Esempio n. 1
0
#############################################

dasvm_libsvm = DomainAdaptationSVM(1.0, wdk, lab, presvm_libsvm, B)
dasvm_libsvm.set_bias_enabled(False)
dasvm_libsvm.train()

dasvm_liblinear = DomainAdaptationSVMLinear(1.0, feat, lab, presvm_liblinear,
                                            B)
dasvm_liblinear.io.set_loglevel(MSG_DEBUG)
dasvm_liblinear.set_bias_enabled(False)
dasvm_liblinear.train()

print "##############"
alphas = []

sv_ids = dasvm_libsvm.get_support_vectors()
for (j, sv_id) in enumerate(sv_ids):
    alpha = dasvm_libsvm.get_alphas()[j]
    #get rid of label
    alpha = alpha * labels[sv_id]
    alphas.append(alpha)

print "alphas libsvm", alphas

#w = presvm_liblinear.get_w()
#print "prew", w[0:10]
#print "labels", labels

#############################################
#    checking linear term
#############################################
dasvm_libsvm = DomainAdaptationSVM(1.0, wdk, lab, presvm_libsvm, B)
dasvm_libsvm.set_bias_enabled(False)
dasvm_libsvm.train()
 

dasvm_liblinear = DomainAdaptationSVMLinear(1.0, feat, lab, presvm_liblinear, B)
dasvm_liblinear.io.set_loglevel(MSG_DEBUG)
dasvm_liblinear.set_bias_enabled(False)
dasvm_liblinear.train()


print "##############"
alphas = []

sv_ids = dasvm_libsvm.get_support_vectors()
for (j, sv_id) in enumerate(sv_ids):
    alpha = dasvm_libsvm.get_alphas()[j]
    #get rid of label
    alpha = alpha*labels[sv_id]
    alphas.append(alpha) 

print "alphas libsvm", alphas

#w = presvm_liblinear.get_w()
#print "prew", w[0:10]
#print "labels", labels

#############################################
#    checking linear term
#############################################
Esempio n. 3
0
#dasvm = SVMLight(1.0, wdk, lab)
Math_init_random(1)

dasvm.train()


#dasvm = SVMLight(1.0, wdk, lab)
#dasvm.set_linear_term(numpy.double(p))
#dasvm.train()

 

lin_da = dasvm.get_linear_term()
daobj = dasvm.get_objective()

sv_idx_da = dasvm.get_support_vectors()
alphas_da = dasvm.get_alphas()

alphas_full_da = numpy.zeros(N)
alphas_full_da[sv_idx_da] = alphas_da



################
#checking linear term
presvm.set_bias(0.0)
tmp_out = -B*presvm.classify(feat).get_labels()*tmp_lab - 1

for i in xrange(len(examples)):
    
    print lin_da[i], tmp_out[i]
Esempio n. 4
0
#############################################

dasvm = DomainAdaptationSVM(1.0, wdk, lab, presvm, B)
#dasvm = SVMLight(1.0, wdk, lab)
Math_init_random(1)

dasvm.train()

#dasvm = SVMLight(1.0, wdk, lab)
#dasvm.set_linear_term(numpy.double(p))
#dasvm.train()

lin_da = dasvm.get_linear_term()
daobj = dasvm.get_objective()

sv_idx_da = dasvm.get_support_vectors()
alphas_da = dasvm.get_alphas()

alphas_full_da = numpy.zeros(N)
alphas_full_da[sv_idx_da] = alphas_da

################
#checking linear term
presvm.set_bias(0.0)
tmp_out = -B * presvm.classify(feat).get_labels() * tmp_lab - 1

for i in xrange(len(examples)):

    print lin_da[i], tmp_out[i]
    assert (abs(lin_da[i] - tmp_out[i]) <= 0.001)