Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored SO machine to not use its own features reference, fixed ge…
…neric risk and bmrm result type
- Loading branch information
Showing
12 changed files
with
79 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
examples/undocumented/python_modular/structure_hmsvm_bmrm.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
|
||
import numpy | ||
import scipy | ||
|
||
from scipy import io | ||
from shogun.Features import RealMatrixFeatures | ||
from shogun.Loss import HingeLoss | ||
from shogun.Structure import HMSVMLabels, HMSVMModel, Sequence, TwoStateModel, SMT_TWO_STATE | ||
from shogun.Evaluation import StructuredAccuracy | ||
from shogun.Structure import DualLibQPBMSOSVM | ||
|
||
data_dict = scipy.io.loadmat('../data/hmsvm_data_large_integer.mat') | ||
labels_array = data_dict['label'][0] | ||
idxs = numpy.nonzero(labels_array == -1) | ||
labels_array[idxs] = 0 | ||
labels = HMSVMLabels(labels_array, 250, 500, 2) | ||
features = RealMatrixFeatures(data_dict['signal'].astype(float), 250, 500) | ||
loss = HingeLoss() | ||
model = HMSVMModel(features, labels, SMT_TWO_STATE, 4) | ||
sosvm = DualLibQPBMSOSVM(model, loss, labels, 5000.0) | ||
sosvm.train() | ||
print sosvm.get_w() | ||
predicted = sosvm.apply() | ||
evaluator = StructuredAccuracy() | ||
acc = evaluator.evaluate(predicted, labels) | ||
print('Accuracy = %.4f' % acc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters