def structure_discrete_hmsvm_mosek (m_data_dict=data_dict):
	from modshogun   import RealMatrixFeatures
	from modshogun  import SequenceLabels, HMSVMModel, Sequence, TwoStateModel, SMT_TWO_STATE
	from modshogun import StructuredAccuracy

	try:
		from modshogun import PrimalMosekSOSVM
	except ImportError:
		print("Mosek not available")
		return

	labels_array = m_data_dict['label'][0]

	idxs = numpy.nonzero(labels_array == -1)
	labels_array[idxs] = 0

	labels = SequenceLabels(labels_array, 250, 500, 2)
	features = RealMatrixFeatures(m_data_dict['signal'].astype(float), 250, 500)

	num_obs = 4	# given by the data file used
	model = HMSVMModel(features, labels, SMT_TWO_STATE, num_obs)

	sosvm = PrimalMosekSOSVM(model, labels)
	sosvm.train()
	#print(sosvm.get_w())

	predicted = sosvm.apply()
	evaluator = StructuredAccuracy()
	acc = evaluator.evaluate(predicted, labels)
def structure_discrete_hmsvm_mosek (m_data_dict=data_dict):
	from modshogun import RealMatrixFeatures, SequenceLabels, HMSVMModel, Sequence, TwoStateModel
	from modshogun import StructuredAccuracy, SMT_TWO_STATE

	try:
		from modshogun import PrimalMosekSOSVM
	except ImportError:
		print("Mosek not available")
		return

	labels_array = m_data_dict['label'][0]

	idxs = numpy.nonzero(labels_array == -1)
	labels_array[idxs] = 0

	labels = SequenceLabels(labels_array, 250, 500, 2)
	features = RealMatrixFeatures(m_data_dict['signal'].astype(float), 250, 500)

	num_obs = 4	# given by the data file used
	model = HMSVMModel(features, labels, SMT_TWO_STATE, num_obs)

	sosvm = PrimalMosekSOSVM(model, labels)
	sosvm.train()
	#print(sosvm.get_w())

	predicted = sosvm.apply()
	evaluator = StructuredAccuracy()
	acc = evaluator.evaluate(predicted, labels)
Пример #3
0
def so_multiclass(fm_train_real=traindat,
                  label_train_multiclass=label_traindat):
    try:
        from modshogun import RealFeatures
        from modshogun import MulticlassModel, MulticlassSOLabels, PrimalMosekSOSVM, RealNumber
    except ImportError:
        print("Mosek not available")
        return

    labels = MulticlassSOLabels(label_train_multiclass)
    features = RealFeatures(fm_train_real.T)

    model = MulticlassModel(features, labels)
    sosvm = PrimalMosekSOSVM(model, labels)
    sosvm.train()

    out = sosvm.apply()
    count = 0
    for i in xrange(out.get_num_labels()):
        yi_pred = RealNumber.obtain_from_generic(out.get_label(i))
        if yi_pred.value == label_train_multiclass[i]:
            count = count + 1

    print("Correct classification rate: %0.2f" %
          (100.0 * count / out.get_num_labels()))
def structure_plif_hmsvm_mosek (num_examples, example_length, num_features, num_noise_features):
	from modshogun import RealMatrixFeatures, TwoStateModel, StructuredAccuracy

	try:
		from modshogun import PrimalMosekSOSVM
	except ImportError:
		print("Mosek not available")
		return

	model = TwoStateModel.simulate_data(num_examples, example_length, num_features, num_noise_features)
	sosvm = PrimalMosekSOSVM(model, model.get_labels())

	sosvm.train()
	#print(sosvm.get_w())

	predicted = sosvm.apply(model.get_features())
	evaluator = StructuredAccuracy()
	acc = evaluator.evaluate(predicted, model.get_labels())
Пример #5
0
def structure_plif_hmsvm_mosek(num_examples, example_length, num_features,
                               num_noise_features):
    from modshogun import RealMatrixFeatures, TwoStateModel, StructuredAccuracy

    try:
        from modshogun import PrimalMosekSOSVM
    except ImportError:
        print("Mosek not available")
        return

    model = TwoStateModel.simulate_data(num_examples, example_length,
                                        num_features, num_noise_features)
    sosvm = PrimalMosekSOSVM(model, model.get_labels())

    sosvm.train()
    #print(sosvm.get_w())

    predicted = sosvm.apply(model.get_features())
    evaluator = StructuredAccuracy()
    acc = evaluator.evaluate(predicted, model.get_labels())
Пример #6
0
def so_multiclass (fm_train_real=traindat,label_train_multiclass=label_traindat):
	try:
		from modshogun	import RealFeatures
		from modshogun	import MulticlassModel, MulticlassSOLabels, PrimalMosekSOSVM, RealNumber
	except ImportError:
		print("Mosek not available")
		return

	labels = MulticlassSOLabels(label_train_multiclass)
	features = RealFeatures(fm_train_real.T)

	model = MulticlassModel(features, labels)
	sosvm = PrimalMosekSOSVM(model, labels)
	sosvm.train()

	out = sosvm.apply()
	count = 0
	for i in xrange(out.get_num_labels()):
		yi_pred = RealNumber.obtain_from_generic(out.get_label(i))
		if yi_pred.value == label_train_multiclass[i]:
			count = count + 1

	print("Correct classification rate: %0.2f" % ( 100.0*count/out.get_num_labels() ))