Skip to content

Commit

Permalink
Fixed MKL libshogun example
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jul 7, 2012
1 parent e510cf0 commit 77ab132
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
30 changes: 14 additions & 16 deletions examples/undocumented/libshogun/classifier_mklmulticlass.cpp
Expand Up @@ -219,9 +219,13 @@ void tester()
CCustomKernel* kernel2=new CCustomKernel();
CCustomKernel* kernel3=new CCustomKernel();

kernel1->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(ker1, numdata,numdata));
kernel2->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(ker2, numdata,numdata));
kernel3->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(ker3, numdata,numdata));
kernel1->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(ker1, numdata,numdata,false));
kernel2->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(ker2, numdata,numdata,false));
kernel3->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(ker3, numdata,numdata,false));

SG_FREE(ker1);
SG_FREE(ker2);
SG_FREE(ker3);

ker->append_kernel(kernel1);
ker->append_kernel(kernel2);
Expand Down Expand Up @@ -257,10 +261,6 @@ void tester()
SG_SPRINT("prediction error on training data (3 classes): %f ",err);
SG_SPRINT("random guess error would be: %f \n",2/3.0);

SG_FREE(ker1);
SG_FREE(ker2);
SG_FREE(ker3);

//generate test data
CMulticlassLabels* tlab=NULL;

Expand All @@ -282,9 +282,13 @@ void tester()
CCustomKernel* tkernel2=new CCustomKernel();
CCustomKernel* tkernel3=new CCustomKernel();

tkernel1->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(tker1,numdata, numdatatest));
tkernel2->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(tker2,numdata, numdatatest));
tkernel3->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(tker2,numdata, numdatatest));
tkernel1->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(tker1,numdata, numdatatest, false));
tkernel2->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(tker2,numdata, numdatatest, false));
tkernel3->set_full_kernel_matrix_from_full(SGMatrix<float64_t>(tker2,numdata, numdatatest, false));

SG_FREE(tker1);
SG_FREE(tker2);
SG_FREE(tker3);

tker->append_kernel(tkernel1);
tker->append_kernel(tkernel2);
Expand Down Expand Up @@ -318,19 +322,13 @@ void tester()
SG_SPRINT("prediction error on test data (3 classes): %f ",terr);
SG_SPRINT("random guess error would be: %f \n",2/3.0);

SG_FREE(tker1);
SG_FREE(tker2);
SG_FREE(tker3);
SG_UNREF(tsvm);
SG_UNREF(res);
SG_UNREF(tres);
SG_UNREF(lab);
SG_UNREF(tlab);
SG_UNREF(tker);

SG_FREE(weights);
weights=NULL;

SG_SPRINT( "finished \n");
}

Expand Down
5 changes: 3 additions & 2 deletions src/shogun/machine/KernelMachine.cpp
Expand Up @@ -260,14 +260,15 @@ SGVector<float64_t> CKernelMachine::apply_get_outputs(CFeatures* data)
data->get_name());
}

if (data)
/*
if (data && kernel->get_kernel_type()!=K_COMBINED)
{
CFeatures* lhs=kernel->get_lhs();
REQUIRE(lhs, "%s: No left hand side specified\n", get_name());
kernel->init(lhs, data);
SG_UNREF(lhs);
}

*/

int32_t num_vectors=kernel->get_num_vec_rhs();

Expand Down
6 changes: 3 additions & 3 deletions src/shogun/multiclass/MulticlassSVM.cpp
Expand Up @@ -79,18 +79,18 @@ bool CMulticlassSVM::init_machines_for_apply(CFeatures* data)
SG_ERROR("No kernel assigned!\n");

CFeatures* lhs=m_kernel->get_lhs();
if (!lhs)
if (!lhs && m_kernel->get_kernel_type()!=K_COMBINED)
SG_ERROR("%s: No left hand side specified\n", get_name());

if (!lhs->get_num_vectors())
if (m_kernel->get_kernel_type()!=K_COMBINED && !lhs->get_num_vectors())
{
SG_ERROR("%s: No vectors on left hand side (%s). This is probably due to"
" an implementation error in %s, where it was forgotten to set "
"the data (m_svs) indices\n", get_name(),
data->get_name());
}

if (data)
if (data && m_kernel->get_kernel_type()!=K_COMBINED)
m_kernel->init(lhs, data);
SG_UNREF(lhs);

Expand Down

0 comments on commit 77ab132

Please sign in to comment.