Skip to content

Commit

Permalink
Some rearrangements again
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Mar 10, 2012
1 parent f9907d2 commit fa1f8cd
Show file tree
Hide file tree
Showing 53 changed files with 230 additions and 205 deletions.
4 changes: 0 additions & 4 deletions src/interfaces/modular/Classifier.i
Expand Up @@ -64,8 +64,6 @@

%rename(KernelMulticlassMachine) CKernelMulticlassMachine;
%rename(LinearMulticlassMachine) CLinearMulticlassMachine;
%rename(MulticlassLibLinear) CMulticlassLibLinear;
%rename(MulticlassOCAS) CMulticlassOCAS;

/* These functions return new Objects */
%newobject apply();
Expand Down Expand Up @@ -119,8 +117,6 @@
%include <shogun/machine/MulticlassMachine.h>
%include <shogun/machine/KernelMulticlassMachine.h>
%include <shogun/machine/LinearMulticlassMachine.h>
%include <shogun/classifier/svm/MulticlassLibLinear.h>
%include <shogun/classifier/svm/MulticlassOCAS.h>

#ifdef USE_SVMLIGHT

Expand Down
2 changes: 0 additions & 2 deletions src/interfaces/modular/Classifier_includes.i
Expand Up @@ -42,8 +42,6 @@
#include <shogun/machine/MulticlassMachine.h>
#include <shogun/machine/KernelMulticlassMachine.h>
#include <shogun/machine/LinearMulticlassMachine.h>
#include <shogun/classifier/svm/MulticlassLibLinear.h>
#include <shogun/classifier/svm/MulticlassOCAS.h>
#ifdef USE_SVMLIGHT
#include <shogun/classifier/svm/SVMLight.h>
#include <shogun/classifier/svm/SVMLightOneClass.h>
Expand Down
18 changes: 18 additions & 0 deletions src/interfaces/modular/Multiclass.i
@@ -0,0 +1,18 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2012 Sergey Lisitsyn
* Copyright (C) 2012 Sergey Lisitsyn
*/

/* Remove C Prefix */
%rename(MulticlassLibLinear) CMulticlassLibLinear;
%rename(MulticlassOCAS) CMulticlassOCAS;

/* Include Class Headers to make them visible from within the target language */
%include <shogun/multiclass/MulticlassLibLinear.h>
%include <shogun/multiclass/MulticlassOCAS.h>

4 changes: 4 additions & 0 deletions src/interfaces/modular/Multiclass_includes.i
@@ -0,0 +1,4 @@
%{
#include <shogun/multiclass/MulticlassLibLinear.h>
#include <shogun/multiclass/MulticlassOCAS.h>
%}
2 changes: 2 additions & 0 deletions src/interfaces/modular/modshogun.i
Expand Up @@ -54,6 +54,7 @@
%include "Preprocessor_includes.i"
%include "Regression_includes.i"
%include "Structure_includes.i"
%include "Multiclass_includes.i"

%include "SGBase.i"
%include "IO.i"
Expand All @@ -71,3 +72,4 @@
%include "Clustering.i"
%include "ModelSelection.i"
%include "Structure.i"
%include "Multiclass.i"
4 changes: 2 additions & 2 deletions src/shogun/classifier/AveragedPerceptron.cpp
Expand Up @@ -31,7 +31,7 @@ CAveragedPerceptron::~CAveragedPerceptron()

bool CAveragedPerceptron::train(CFeatures* data)
{
ASSERT(labels);
ASSERT(m_labels);
if (data)
{
if (!data->has_property(FP_DOT))
Expand All @@ -41,7 +41,7 @@ bool CAveragedPerceptron::train(CFeatures* data)
ASSERT(features);
bool converged=false;
int32_t iter=0;
SGVector<int32_t> train_labels=labels->get_int_labels();
SGVector<int32_t> train_labels=m_labels->get_int_labels();
int32_t num_feat=features->get_dim_feature_space();
int32_t num_vec=features->get_num_vectors();

Expand Down
6 changes: 3 additions & 3 deletions src/shogun/classifier/ConjugateIndex.cpp
Expand Up @@ -70,7 +70,7 @@ bool CConjugateIndex::train(CFeatures* train_features)
if (train_features)
set_features(train_features);

m_num_classes = labels->get_num_classes();
m_num_classes = m_labels->get_num_classes();
ASSERT(m_num_classes>=2);
clean_classes();

Expand All @@ -91,7 +91,7 @@ bool CConjugateIndex::train(CFeatures* train_features)
int32_t count = 0;
for (int32_t i=0; i<num_vectors; i++)
{
if (labels->get_int_label(i) == label)
if (m_labels->get_int_label(i) == label)
count++;
}

Expand All @@ -102,7 +102,7 @@ bool CConjugateIndex::train(CFeatures* train_features)
count = 0;
for (int32_t i=0; i<num_vectors; i++)
{
if (labels->get_label(i) == label)
if (m_labels->get_label(i) == label)
{
memcpy(class_feature_matrix.matrix+count*num_features,
feature_matrix+i*num_features,
Expand Down
4 changes: 2 additions & 2 deletions src/shogun/classifier/GaussianNaiveBayes.cpp
Expand Up @@ -73,8 +73,8 @@ bool CGaussianNaiveBayes::train(CFeatures* data)
set_features((CDotFeatures*) data);
}
// get int labels to train_labels and check length equality
ASSERT(labels);
SGVector<int32_t> train_labels = labels->get_int_labels();
ASSERT(m_labels);
SGVector<int32_t> train_labels = m_labels->get_int_labels();
ASSERT(m_features->get_num_vectors()==train_labels.vlen);

// init min_label, max_label and loop variables
Expand Down
6 changes: 3 additions & 3 deletions src/shogun/classifier/KNN.cpp
Expand Up @@ -61,17 +61,17 @@ CKNN::~CKNN()

bool CKNN::train_machine(CFeatures* data)
{
ASSERT(labels);
ASSERT(m_labels);
ASSERT(distance);

if (data)
{
if (labels->get_num_labels() != data->get_num_vectors())
if (m_labels->get_num_labels() != data->get_num_vectors())
SG_ERROR("Number of training vectors does not match number of labels\n");
distance->init(data, data);
}

SGVector<int32_t> lab=labels->get_int_labels();
SGVector<int32_t> lab=m_labels->get_int_labels();
train_labels.vlen=lab.vlen;
train_labels.vector=CMath::clone_vector(lab.vector, lab.vlen);
lab.free_vector();
Expand Down
4 changes: 2 additions & 2 deletions src/shogun/classifier/LDA.cpp
Expand Up @@ -39,15 +39,15 @@ CLDA::~CLDA()

bool CLDA::train_machine(CFeatures* data)
{
ASSERT(labels);
ASSERT(m_labels);
if (data)
{
if (!data->has_property(FP_DOT))
SG_ERROR("Specified features are not of type CDotFeatures\n");
set_features((CDotFeatures*) data);
}
ASSERT(features);
SGVector<int32_t> train_labels=labels->get_int_labels();
SGVector<int32_t> train_labels=m_labels->get_int_labels();
ASSERT(train_labels.vector);

int32_t num_feat=features->get_dim_feature_space();
Expand Down
4 changes: 2 additions & 2 deletions src/shogun/classifier/Perceptron.cpp
Expand Up @@ -32,7 +32,7 @@ CPerceptron::~CPerceptron()

bool CPerceptron::train_machine(CFeatures* data)
{
ASSERT(labels);
ASSERT(m_labels);
if (data)
{
if (!data->has_property(FP_DOT))
Expand All @@ -42,7 +42,7 @@ bool CPerceptron::train_machine(CFeatures* data)
ASSERT(features);
bool converged=false;
int32_t iter=0;
SGVector<int32_t> train_labels=labels->get_int_labels();
SGVector<int32_t> train_labels=m_labels->get_int_labels();
int32_t num_feat=features->get_dim_feature_space();
int32_t num_vec=features->get_num_vectors();

Expand Down
8 changes: 4 additions & 4 deletions src/shogun/classifier/PluginEstimate.cpp
Expand Up @@ -45,7 +45,7 @@ CPluginEstimate::~CPluginEstimate()

bool CPluginEstimate::train_machine(CFeatures* data)
{
ASSERT(labels);
ASSERT(m_labels);
if (data)
{
if (data->get_feature_class() != C_STRING ||
Expand All @@ -70,14 +70,14 @@ bool CPluginEstimate::train_machine(CFeatures* data)
int32_t* pos_indizes=SG_MALLOC(int32_t, ((CStringFeatures<uint16_t>*) features)->get_num_vectors());
int32_t* neg_indizes=SG_MALLOC(int32_t, ((CStringFeatures<uint16_t>*) features)->get_num_vectors());

ASSERT(labels->get_num_labels()==features->get_num_vectors());
ASSERT(m_labels->get_num_labels()==features->get_num_vectors());

int32_t pos_idx=0;
int32_t neg_idx=0;

for (int32_t i=0; i<labels->get_num_labels(); i++)
for (int32_t i=0; i<m_labels->get_num_labels(); i++)
{
if (labels->get_label(i) > 0)
if (m_labels->get_label(i) > 0)
pos_indizes[pos_idx++]=i;
else
neg_indizes[neg_idx++]=i;
Expand Down
18 changes: 9 additions & 9 deletions src/shogun/classifier/mkl/MKL.cpp
Expand Up @@ -193,11 +193,11 @@ bool CMKL::check_lpx_status(LPX *lp)
bool CMKL::train_machine(CFeatures* data)
{
ASSERT(kernel);
ASSERT(labels && labels->get_num_labels());
ASSERT(m_labels && m_labels->get_num_labels());

if (data)
{
if (labels->get_num_labels() != data->get_num_vectors())
if (m_labels->get_num_labels() != data->get_num_vectors())
SG_ERROR("Number of training vectors does not match number of labels\n");
kernel->init(data, data);
}
Expand All @@ -207,10 +207,10 @@ bool CMKL::train_machine(CFeatures* data)
SG_ERROR("No constraint generator (SVM) set\n");

int32_t num_label=0;
if (labels)
num_label = labels->get_num_labels();
if (m_labels)
num_label = m_labels->get_num_labels();

SG_INFO("%d trainlabels (%ld)\n", num_label, labels);
SG_INFO("%d trainlabels (%ld)\n", num_label, m_labels);
if (mkl_epsilon<=0)
mkl_epsilon=1e-2 ;

Expand Down Expand Up @@ -265,7 +265,7 @@ bool CMKL::train_machine(CFeatures* data)
svm->set_shrinking_enabled(get_shrinking_enabled());
svm->set_linadd_enabled(get_linadd_enabled());
svm->set_batch_computation_enabled(get_batch_computation_enabled());
svm->set_labels(labels);
svm->set_labels(m_labels);
svm->set_kernel(kernel);

#ifdef USE_CPLEX
Expand Down Expand Up @@ -407,7 +407,7 @@ bool CMKL::perform_mkl_step(
ASSERT(nweights==num_kernels);
float64_t* beta = SG_MALLOC(float64_t, num_kernels);

int32_t inner_iters=0;
//int32_t inner_iters=0;
float64_t mkl_objective=0;

mkl_objective=-suma;
Expand Down Expand Up @@ -584,7 +584,7 @@ float64_t CMKL::compute_elasticnet_dual_objective()
int32_t num_kernels = kernel->get_num_subkernels();
float64_t mkl_obj=0;

if (labels && kernel && kernel->get_kernel_type() == K_COMBINED)
if (m_labels && kernel && kernel->get_kernel_type() == K_COMBINED)
{
// Compute Elastic-net dual
float64_t* nm = SG_MALLOC(float64_t, num_kernels);
Expand Down Expand Up @@ -1521,7 +1521,7 @@ float64_t CMKL::compute_mkl_dual_objective()
int32_t n=get_num_support_vectors();
float64_t mkl_obj=0;

if (labels && kernel && kernel->get_kernel_type() == K_COMBINED)
if (m_labels && kernel && kernel->get_kernel_type() == K_COMBINED)
{
CKernel* kn = ((CCombinedKernel*)kernel)->get_first_kernel();
while (kn)
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/classifier/mkl/MKLClassification.cpp
Expand Up @@ -34,5 +34,5 @@ float64_t CMKLClassification::compute_sum_alpha()

void CMKLClassification::init_training()
{
ASSERT(labels && labels->get_num_labels() && labels->is_two_class_labeling());
ASSERT(m_labels && m_labels->get_num_labels() && m_labels->is_two_class_labeling());
}
22 changes: 11 additions & 11 deletions src/shogun/classifier/mkl/MKLMultiClass.cpp
Expand Up @@ -66,7 +66,7 @@ CMKLMultiClass CMKLMultiClass::operator=( const CMKLMultiClass & cm)

void CMKLMultiClass::initsvm()
{
if (!labels)
if (!m_labels)
{
SG_ERROR("CMKLMultiClass::initsvm(): the set labels is NULL\n");
}
Expand All @@ -78,13 +78,13 @@ void CMKLMultiClass::initsvm()
svm->set_C(get_C1(),get_C2());
svm->set_epsilon(epsilon);

if (labels->get_num_labels()<=0)
if (m_labels->get_num_labels()<=0)
{
SG_ERROR("CMKLMultiClass::initsvm(): the number of labels is "
"nonpositive, do not know how to handle this!\n");
}

svm->set_labels(labels);
svm->set_labels(m_labels);
}

void CMKLMultiClass::initlpsolver()
Expand Down Expand Up @@ -241,15 +241,15 @@ void CMKLMultiClass::addingweightsstep( const std::vector<float64_t> &
float64_t CMKLMultiClass::getsumofsignfreealphas()
{

std::vector<int> trainlabels2(labels->get_num_labels());
SGVector<int32_t> lab=labels->get_int_labels();
std::vector<int> trainlabels2(m_labels->get_num_labels());
SGVector<int32_t> lab=m_labels->get_int_labels();
std::copy(lab.vector,lab.vector+lab.vlen, trainlabels2.begin());
lab.free_vector();

ASSERT (trainlabels2.size()>0);
float64_t sum=0;

for (int32_t nc=0; nc< labels->get_num_classes();++nc)
for (int32_t nc=0; nc< m_labels->get_num_classes();++nc)
{
CSVM * sm=svm->get_svm(nc);

Expand All @@ -265,7 +265,7 @@ float64_t CMKLMultiClass::getsumofsignfreealphas()

for (size_t lb=0; lb< trainlabels2.size();++lb)
{
for (int32_t nc=0; nc< labels->get_num_classes();++nc)
for (int32_t nc=0; nc< m_labels->get_num_classes();++nc)
{
CSVM * sm=svm->get_svm(nc);

Expand Down Expand Up @@ -293,7 +293,7 @@ float64_t CMKLMultiClass::getsquarenormofprimalcoefficients(

float64_t tmp=0;

for (int32_t classindex=0; classindex< labels->get_num_classes();
for (int32_t classindex=0; classindex< m_labels->get_num_classes();
++classindex)
{
CSVM * sm=svm->get_svm(classindex);
Expand Down Expand Up @@ -324,13 +324,13 @@ float64_t CMKLMultiClass::getsquarenormofprimalcoefficients(

bool CMKLMultiClass::train_machine(CFeatures* data)
{
int numcl=labels->get_num_classes();
int numcl=m_labels->get_num_classes();
ASSERT(kernel);
ASSERT(labels && labels->get_num_labels());
ASSERT(m_labels && m_labels->get_num_labels());

if (data)
{
if (labels->get_num_labels() != data->get_num_vectors())
if (m_labels->get_num_labels() != data->get_num_vectors())
SG_ERROR("Number of training vectors does not match number of "
"labels\n");
kernel->init(data, data);
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/classifier/svm/DomainAdaptationSVM.cpp
Expand Up @@ -83,7 +83,7 @@ bool CDomainAdaptationSVM::train_machine(CFeatures* data)

if (data)
{
if (labels->get_num_labels() != data->get_num_vectors())
if (m_labels->get_num_labels() != data->get_num_vectors())
SG_ERROR("Number of training vectors does not match number of labels\n");
kernel->init(data, data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/classifier/svm/DomainAdaptationSVMLinear.cpp
Expand Up @@ -101,7 +101,7 @@ bool CDomainAdaptationSVMLinear::train_machine(CDotFeatures* train_data)

if (train_data)
{
if (labels->get_num_labels() != train_data->get_num_vectors())
if (m_labels->get_num_labels() != train_data->get_num_vectors())
SG_ERROR("Number of training vectors does not match number of labels\n");
tmp_data = train_data;

Expand Down

0 comments on commit fa1f8cd

Please sign in to comment.