Skip to content

Commit

Permalink
Merge pull request #1317 from iglesias/feature/fix_matrixlist
Browse files Browse the repository at this point in the history
Fix discrete libshogun HM-SVM example
  • Loading branch information
iglesias committed Jul 26, 2013
2 parents 8d8a3ea + 8813ca6 commit 9361fdd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Expand Up @@ -10,13 +10,14 @@ int main()
{
init_shogun_with_defaults();

float64_t features_dat[] = {0,1, 2,1, 0,1, 0,2};
SGMatrix<float64_t> features_mat(features_dat,1,8,false);
CMatrixFeatures<float64_t>* features = new CMatrixFeatures<float64_t>(features_mat,2,4);
float64_t features_dat[] = {0,1,1, 2,1,2, 0,1,0, 0,2,2};
SGMatrix<float64_t> features_mat(features_dat,1,12,false);
CMatrixFeatures<float64_t>* features = new CMatrixFeatures<float64_t>(features_mat,3,4);

int32_t labels_dat[] = {0,0, 1,1, 0,0, 1,1};
SGVector<int32_t> labels_vec(labels_dat,8,false);
CSequenceLabels* labels = new CSequenceLabels(labels_vec,2,4,2);
int32_t labels_dat[] = {0,0,0, 1,1,1, 0,0,0, 1,1,1};
SGVector<int32_t> labels_vec(labels_dat,12,false);
CSequenceLabels* labels = new CSequenceLabels(labels_vec,3,4,2);
labels->io->set_loglevel(MSG_DEBUG);

CHMSVMModel* model = new CHMSVMModel(features, labels, SMT_TWO_STATE, 3);
CDualLibQPBMSOSVM* sosvm = new CDualLibQPBMSOSVM(model, labels, 5000,0);
Expand Down
4 changes: 4 additions & 0 deletions src/shogun/structure/HMSVMModel.cpp
Expand Up @@ -320,6 +320,10 @@ CResultSet* CHMSVMModel::argmax(
}
}

REQUIRE(opt_path[T-1]!=-1, "Viterbi decoding found no possible sequence states.\n"
"Maybe the state model used cannot produce such sequence.\n"
"If using the TwoStateModel, please use sequences of length greater than two.\n");

for ( int32_t i = T-1 ; i > 0 ; --i )
opt_path[i-1] = trb[opt_path[i]*T + i];

Expand Down

0 comments on commit 9361fdd

Please sign in to comment.