From 8813ca63114b43b35e87866f9d9936857c34ceeb Mon Sep 17 00:00:00 2001 From: Fernando Iglesias Date: Fri, 26 Jul 2013 15:05:33 +0200 Subject: [PATCH] Fix discrete HM-SVM example --- .../libshogun/structure_discrete_hmsvm_bmrm.cpp | 13 +++++++------ src/shogun/structure/HMSVMModel.cpp | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/undocumented/libshogun/structure_discrete_hmsvm_bmrm.cpp b/examples/undocumented/libshogun/structure_discrete_hmsvm_bmrm.cpp index abc48514e87..20a80d00baf 100644 --- a/examples/undocumented/libshogun/structure_discrete_hmsvm_bmrm.cpp +++ b/examples/undocumented/libshogun/structure_discrete_hmsvm_bmrm.cpp @@ -10,13 +10,14 @@ int main() { init_shogun_with_defaults(); - float64_t features_dat[] = {0,1, 2,1, 0,1, 0,2}; - SGMatrix features_mat(features_dat,1,8,false); - CMatrixFeatures* features = new CMatrixFeatures(features_mat,2,4); + float64_t features_dat[] = {0,1,1, 2,1,2, 0,1,0, 0,2,2}; + SGMatrix features_mat(features_dat,1,12,false); + CMatrixFeatures* features = new CMatrixFeatures(features_mat,3,4); - int32_t labels_dat[] = {0,0, 1,1, 0,0, 1,1}; - SGVector 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 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); diff --git a/src/shogun/structure/HMSVMModel.cpp b/src/shogun/structure/HMSVMModel.cpp index 56049cafec8..bead59c2d9d 100644 --- a/src/shogun/structure/HMSVMModel.cpp +++ b/src/shogun/structure/HMSVMModel.cpp @@ -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];