Skip to content

Commit

Permalink
fix libsvm example and don't call pure virtual method (indirectly in …
Browse files Browse the repository at this point in the history
…constructor)
  • Loading branch information
Soeren Sonnenburg committed May 20, 2012
1 parent 6f79da5 commit fa50f74
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 21 deletions.
6 changes: 4 additions & 2 deletions examples/undocumented/libshogun/classifier_libsvm.cpp
Expand Up @@ -8,6 +8,8 @@
* Copyright (C) 2008-2009 Fraunhofer Institute FIRST and Max Planck Society
*/
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/labels/RealLabels.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/classifier/svm/LibSVM.h>
#include <shogun/mathematics/Math.h>
Expand Down Expand Up @@ -66,7 +68,7 @@ int main()
gen_rand_data();

// create train labels
CLabels* labels=new CLabels(SGVector<float64_t>(lab, NUM));
CLabels* labels=new CBinaryLabels(SGVector<float64_t>(lab, NUM));

// create train features
CDenseFeatures<float64_t>* features = new CDenseFeatures<float64_t>(feature_cache);
Expand All @@ -87,7 +89,7 @@ int main()
printf("num_sv:%d b:%f\n", svm->get_num_support_vectors(), svm->get_bias());

// classify + display output
CLabels* out_labels=svm->apply();
CRealLabels* out_labels=(CRealLabels*) svm->apply();

for (int32_t i=0; i<NUM; i++)
printf("out[%d]=%f\n", i, out_labels->get_label(i));
Expand Down
3 changes: 2 additions & 1 deletion src/shogun/labels/BinaryLabels.cpp
Expand Up @@ -11,8 +11,9 @@ CBinaryLabels::CBinaryLabels(int32_t num_labels) : CDenseLabels(num_labels)
{
}

CBinaryLabels::CBinaryLabels(const SGVector<float64_t> src) : CDenseLabels(src)
CBinaryLabels::CBinaryLabels(const SGVector<float64_t> src) : CDenseLabels()
{
set_labels(src);
}

CBinaryLabels::CBinaryLabels(CFile* loader) : CDenseLabels(loader)
Expand Down
10 changes: 0 additions & 10 deletions src/shogun/labels/DenseLabels.cpp
Expand Up @@ -33,14 +33,6 @@ CDenseLabels::CDenseLabels(int32_t num_lab)
labels=SGVector<float64_t>(num_lab);
}

CDenseLabels::CDenseLabels(SGVector<float64_t> src)
: CLabels()
{
init();

set_labels(src);
}

CDenseLabels::CDenseLabels(CFile* loader)
: CLabels()
{
Expand All @@ -54,9 +46,7 @@ CDenseLabels::~CDenseLabels()

void CDenseLabels::init()
{
CDenseLabels::init();
SG_ADD(&labels, "labels", "The labels.", MS_NOT_AVAILABLE);
labels=SGVector<float64_t>();
}

void CDenseLabels::set_to_one()
Expand Down
6 changes: 0 additions & 6 deletions src/shogun/labels/DenseLabels.h
Expand Up @@ -42,12 +42,6 @@ class CDenseLabels : public CLabels
*/
CDenseLabels(int32_t num_labels);

/** constructor
*
* @param src labels to set
*/
CDenseLabels(const SGVector<float64_t> src);

/** constructor
*
* @param loader File object via which to load data
Expand Down
3 changes: 2 additions & 1 deletion src/shogun/labels/MulticlassLabels.cpp
Expand Up @@ -12,8 +12,9 @@ CMulticlassLabels::CMulticlassLabels(int32_t num_labels) : CDenseLabels(num_labe
{
}

CMulticlassLabels::CMulticlassLabels(const SGVector<float64_t> src) : CDenseLabels(src)
CMulticlassLabels::CMulticlassLabels(const SGVector<float64_t> src) : CDenseLabels()
{
set_labels(src);
}

CMulticlassLabels::CMulticlassLabels(CFile* loader) : CDenseLabels(loader)
Expand Down
3 changes: 2 additions & 1 deletion src/shogun/labels/RealLabels.cpp
Expand Up @@ -11,8 +11,9 @@ CRealLabels::CRealLabels(int32_t num_labels) : CDenseLabels(num_labels)
{
}

CRealLabels::CRealLabels(const SGVector<float64_t> src) : CDenseLabels(src)
CRealLabels::CRealLabels(const SGVector<float64_t> src) : CDenseLabels()
{
set_labels(src);
}

CRealLabels::CRealLabels(CFile* loader) : CDenseLabels(loader)
Expand Down

0 comments on commit fa50f74

Please sign in to comment.