Пример #1
0
def svm_to_fiksvm(svm_models, weights, feat_dim, params):
    num_models = len(weights)
    min_vals = params['min_vals']
    max_vals = params['max_vals']
    nr_bins = params['nr_bins']

    c_weights = (c_double * num_models)()
    model_ptr_ptr = (POINTER(svm_model) * num_models)()

    for t in range(num_models):
        #c_weights[t] = c_double(1.0/num_models)
        c_weights[t] = c_double(weights[t])
        model_ptr_ptr[t] = pointer(svm_models[t])
        #print t, svm_models[t].get_nr_class()

    c_min_vals = (c_double * feat_dim)()
    c_max_vals = (c_double * feat_dim)()
    for i in range(feat_dim):
        c_min_vals[i] = c_double(min_vals[i])
        c_max_vals[i] = c_double(max_vals[i])

    new_model = libfiksvm.create_fiksvm_approx_model(model_ptr_ptr, num_models,
                                                     c_weights, feat_dim,
                                                     c_min_vals, c_max_vals,
                                                     nr_bins)
    del model_ptr_ptr
    del c_weights
    del c_min_vals
    del c_max_vals

    if not new_model:
        print("can't do svm_to_fiksvm")
        return None

    return toPyModel(new_model)
Пример #2
0
def svm_to_fiksvm(svm_models, weights, feat_dim, params):
    num_models = len(weights)
    min_vals = params["min_vals"]
    max_vals = params["max_vals"]
    nr_bins = params["nr_bins"]

    c_weights = (c_double * num_models)()
    model_ptr_ptr = (POINTER(svm_model) * num_models)()

    for t in range(num_models):
        # c_weights[t] = c_double(1.0/num_models)
        c_weights[t] = c_double(weights[t])
        model_ptr_ptr[t] = pointer(svm_models[t])
        # print t, svm_models[t].get_nr_class()

    c_min_vals = (c_double * feat_dim)()
    c_max_vals = (c_double * feat_dim)()
    for i in range(feat_dim):
        c_min_vals[i] = c_double(min_vals[i])
        c_max_vals[i] = c_double(max_vals[i])

    new_model = libfiksvm.create_fiksvm_approx_model(
        model_ptr_ptr, num_models, c_weights, feat_dim, c_min_vals, c_max_vals, nr_bins
    )
    del model_ptr_ptr
    del c_weights
    del c_min_vals
    del c_max_vals

    if not new_model:
        print("can't do svm_to_fiksvm")
        return None

    return toPyModel(new_model)
Пример #3
0
def fiksvm_load_model(model_file_name):
    """
    fiksvm_load_model(model_file_name) -> model

    Load a fik_approx_model from model_file_name and return.
    """
    model = libfiksvm.fiksvm_load_model(model_file_name)

    if not model:
        print("can't open model file %s" % model_file_name)
        return None

    model = toPyModel(model)
    return model
Пример #4
0
def fiksvm_load_model(model_file_name):
    """
    fiksvm_load_model(model_file_name) -> model

    Load a fik_approx_model from model_file_name and return.
    """
    model = libfiksvm.fiksvm_load_model(model_file_name)

    if not model:
        print("can't open model file %s" % model_file_name)
        return None

    model = toPyModel(model)
    return model
Пример #5
0
import svm


labels = [0, 1]
samples = [[0, 0], [0, 1]]

labels = [0, 1, 1, 2]
samples = [[0, 0], [0, 1], [1, 0], [1, 1]]

import svm

labels = [0, 0, 1, 1]
samples = [[1, 1], [1, -1], [-1, 1], [-1, -1]]

param = svm.svm_parameter("-c 1")
problem = svm.svm_problem(labels, samples)

model = svm.libsvm.svm_train(problem, param)
pmodel = svm.toPyModel(model)
pmodel.predict_values(samples[0])
for i in range(len(samples)):
    print svm.libsvm.svm_predict(model, svm.gen_svm_nodearray(samples[i])[0])


r = (c_double * 6)()
svm.libsvm.svm_predict_values(model, svm.gen_svm_nodearray(samples[0])[0], r)
Пример #6
0
import svm

labels = [0, 1]
samples = [[0, 0], [0, 1]]

labels = [0, 1, 1, 2]
samples = [[0, 0], [0, 1], [1, 0], [1, 1]]

import svm

labels = [0, 0, 1, 1]
samples = [[1, 1], [1, -1], [-1, 1], [-1, -1]]

param = svm.svm_parameter('-c 1')
problem = svm.svm_problem(labels, samples)

model = svm.libsvm.svm_train(problem, param)
pmodel = svm.toPyModel(model)
pmodel.predict_values(samples[0])
for i in range(len(samples)):
    print svm.libsvm.svm_predict(model, svm.gen_svm_nodearray(samples[i])[0])

r = (c_double * 6)()
svm.libsvm.svm_predict_values(model, svm.gen_svm_nodearray(samples[0])[0], r)