Skip to content

Commit

Permalink
fix mkl example
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Sonnenburg committed Nov 22, 2011
1 parent 1f4a30c commit 2d4c51c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions examples/undocumented/libshogun/mkl_memleak_test.cpp
@@ -1,5 +1,8 @@
#include <shogun/base/init.h>
#include <shogun/classifier/mkl/MKLClassification.h>
#include <shogun/regression/svr/MKLRegression.h>
#include <shogun/regression/svr/LibSVR.h>
#include <shogun/regression/svr/SVRLight.h>
#include <shogun/features/Labels.h>
#include <shogun/lib/DataType.h>
#include <shogun/kernel/CustomKernel.h>
Expand All @@ -12,13 +15,21 @@ using namespace shogun;

int main(int argc, char** argv)
{
init_shogun();
init_shogun_with_defaults();

CMKLRegression* regressor = new CMKLRegression();
//CMKLClassification* regressor = new CMKLClassification();
regressor->set_mkl_norm(2.0);
//regressor->set_solver_type(ST_GLPK);
//CSVRLight* regressor = new CSVRLight();
//CLibSVR* regressor = new CLibSVR();
SG_REF(regressor);
//regressor->parallel->set_num_threads(1);

SGVector<float64_t> vec(N);
for (int i=0; i<N; i++) vec.vector[i] = i>>3;
for (int i=0; i<N; i++) vec.vector[i] = (i%2) ? (1.0) : (-1.0);
CLabels* labels = new CLabels(vec);
SG_REF(labels);

SGMatrix<float64_t> matrix1(N,N);
SGMatrix<float64_t> matrix2(N,N);
Expand All @@ -28,6 +39,12 @@ int main(int argc, char** argv)
{
matrix1.matrix[i*N+j] = (i-j)*(i-j)/(1000.0*1000.0);
matrix2.matrix[i*N+j] = (i-j)*(i-j)/(1000.0*1000.0);

if (i==j)
{
matrix1.matrix[i*N+j]+=100;
matrix2.matrix[i*N+j]+=100;
}
}

CCustomKernel* kernel1 = new CCustomKernel(matrix1);
Expand All @@ -37,6 +54,7 @@ int main(int argc, char** argv)
matrix2.destroy_matrix();

CCombinedKernel* ckernel = new CCombinedKernel();
SG_REF(ckernel);
ckernel->append_kernel(kernel1);
ckernel->append_kernel(kernel2);

Expand Down

0 comments on commit 2d4c51c

Please sign in to comment.