Skip to content

Commit

Permalink
Merge pull request #1316 from iglesias/feature/fix_matrixlist
Browse files Browse the repository at this point in the history
Feature/fix matrixlist
  • Loading branch information
iglesias committed Jul 26, 2013
2 parents 47040a7 + 857008d commit 8d8a3ea
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 15 deletions.
28 changes: 28 additions & 0 deletions examples/undocumented/libshogun/structure_discrete_hmsvm_bmrm.cpp
@@ -0,0 +1,28 @@
#include <shogun/structure/HMSVMModel.h>
#include <shogun/structure/DualLibQPBMSOSVM.h>
#include <shogun/structure/StateModelTypes.h>
#include <shogun/features/MatrixFeatures.h>


using namespace shogun;

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);

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);

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;
}
21 changes: 21 additions & 0 deletions examples/undocumented/libshogun/structure_plif_hmsvm_bmrm.cpp
@@ -0,0 +1,21 @@
#include <shogun/structure/TwoStateModel.h>
#include <shogun/structure/HMSVMModel.h>
#include <shogun/structure/DualLibQPBMSOSVM.h>

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;
}
11 changes: 4 additions & 7 deletions src/shogun/lib/SGMatrixList.cpp
Expand Up @@ -92,22 +92,19 @@ SGMatrixList<T> SGMatrixList<T>::split(SGMatrix<T> matrix, int32_t num_component
matrix.num_cols, num_components);

int32_t new_num_cols = matrix.num_cols / num_components;
int32_t start;
SGMatrixList<T> out(num_components);

for ( int32_t i = 0 ; i < num_components ; ++i )
{
out[i] = SGMatrix<T>(matrix.num_rows, new_num_cols);
start = i*matrix.num_rows*new_num_cols;
SGMatrix<T> new_matrix = SGMatrix<T>(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;
Expand Down
6 changes: 4 additions & 2 deletions src/shogun/machine/StructuredOutputMachine.cpp
Expand Up @@ -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<dim; i++)
Expand Down
4 changes: 0 additions & 4 deletions src/shogun/structure/DualLibQPBMSOSVM.cpp
Expand Up @@ -115,13 +115,9 @@ bool CDualLibQPBMSOSVM::train_machine(CFeatures* data)
}

if (m_result.exitflag==1)
{
return true;
}
else
{
return false;
}
}

EMachineType CDualLibQPBMSOSVM::get_classifier_type()
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/structure/DualLibQPBMSOSVM.h
Expand Up @@ -63,7 +63,7 @@ class CDualLibQPBMSOSVM : public CLinearStructuredOutputMachine
SGVector< float64_t > W=0);

/** destructor */
~CDualLibQPBMSOSVM();
virtual ~CDualLibQPBMSOSVM();

/** @return name of SGSerializable */
virtual const char* get_name() const { return "DualLibQPBMSOSVM"; }
Expand Down
4 changes: 3 additions & 1 deletion src/shogun/structure/libbmrm.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 8d8a3ea

Please sign in to comment.