diff --git a/examples/undocumented/libshogun/structure_discrete_hmsvm_bmrm.cpp b/examples/undocumented/libshogun/structure_discrete_hmsvm_bmrm.cpp new file mode 100644 index 00000000000..abc48514e87 --- /dev/null +++ b/examples/undocumented/libshogun/structure_discrete_hmsvm_bmrm.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include + + +using namespace shogun; + +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); + + 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); + + CHMSVMModel* model = new CHMSVMModel(features, labels, SMT_TWO_STATE, 3); + CDualLibQPBMSOSVM* sosvm = new CDualLibQPBMSOSVM(model, labels, 5000,0); + sosvm->train(); + + SG_UNREF(sosvm); + exit_shogun(); + return 0; +} diff --git a/examples/undocumented/libshogun/structure_plif_hmsvm_bmrm.cpp b/examples/undocumented/libshogun/structure_plif_hmsvm_bmrm.cpp new file mode 100644 index 00000000000..58111a4a6ab --- /dev/null +++ b/examples/undocumented/libshogun/structure_plif_hmsvm_bmrm.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +using namespace shogun; + +int main() +{ + init_shogun_with_defaults(); + CTwoStateModel* tsm = new CTwoStateModel(); + CHMSVMModel* model = tsm->simulate_data(100,250,3,1); + CStructuredLabels* labels = model->get_labels(); + CDualLibQPBMSOSVM* sosvm = new CDualLibQPBMSOSVM(model, labels, 5000.0); + sosvm->train(); + + SG_UNREF(sosvm); + SG_UNREF(labels); + SG_UNREF(tsm); + exit_shogun(); + return 0; +} diff --git a/src/shogun/lib/SGMatrixList.cpp b/src/shogun/lib/SGMatrixList.cpp index bf5318dc794..670a7454dfb 100644 --- a/src/shogun/lib/SGMatrixList.cpp +++ b/src/shogun/lib/SGMatrixList.cpp @@ -92,22 +92,19 @@ SGMatrixList SGMatrixList::split(SGMatrix matrix, int32_t num_component matrix.num_cols, num_components); int32_t new_num_cols = matrix.num_cols / num_components; - int32_t start; SGMatrixList out(num_components); for ( int32_t i = 0 ; i < num_components ; ++i ) { - out[i] = SGMatrix(matrix.num_rows, new_num_cols); - start = i*matrix.num_rows*new_num_cols; + SGMatrix new_matrix = SGMatrix(matrix.num_rows, new_num_cols); for ( int32_t row = 0 ; row < matrix.num_rows ; ++row ) { for ( int32_t col = 0 ; col < new_num_cols ; ++col ) - { - out[i][col*matrix.num_rows + row] = - matrix[start + col*matrix.num_rows + row]; - } + new_matrix(row, col) = matrix(row, i*new_num_cols + col); } + + out.set_matrix(i, new_matrix); } return out; diff --git a/src/shogun/machine/StructuredOutputMachine.cpp b/src/shogun/machine/StructuredOutputMachine.cpp index c7ffa4a1b33..8fdd37d362a 100644 --- a/src/shogun/machine/StructuredOutputMachine.cpp +++ b/src/shogun/machine/StructuredOutputMachine.cpp @@ -87,16 +87,18 @@ float64_t CStructuredOutputMachine::risk_nslack_margin_rescale(float64_t* subgra int32_t dim = m_model->get_dim(); int32_t from=0, to=0; + CFeatures* features = get_features(); if (info) { from = info->m_from; - to = (info->m_N == 0) ? get_features()->get_num_vectors() : from+info->m_N; + to = (info->m_N == 0) ? features->get_num_vectors() : from+info->m_N; } else { from = 0; - to = get_features()->get_num_vectors(); + to = features->get_num_vectors(); } + SG_UNREF(features); float64_t R = 0.0; for (int32_t i=0; i W=0); /** destructor */ - ~CDualLibQPBMSOSVM(); + virtual ~CDualLibQPBMSOSVM(); /** @return name of SGSerializable */ virtual const char* get_name() const { return "DualLibQPBMSOSVM"; } diff --git a/src/shogun/structure/libbmrm.cpp b/src/shogun/structure/libbmrm.cpp index 22140325a32..f5fea4760cd 100644 --- a/src/shogun/structure/libbmrm.cpp +++ b/src/shogun/structure/libbmrm.cpp @@ -196,7 +196,9 @@ BmrmStatistics svm_bmrm_solver( floatmax_t rsum, sq_norm_W, sq_norm_Wdiff=0.0; uint32_t *I; uint8_t S=1; - uint32_t nDim=machine->get_model()->get_dim(); + CStructuredModel* model=machine->get_model(); + uint32_t nDim=model->get_dim(); + SG_UNREF(model); CTime ttime; float64_t tstart, tstop;