Skip to content

Commit

Permalink
fix remaining libshogun examples for new label system
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Sonnenburg committed May 21, 2012
1 parent 4830bda commit c54276b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/undocumented/libshogun/classifier_libsvm.cpp
Expand Up @@ -88,7 +88,7 @@ int main()
printf("num_sv:%d b:%f\n", svm->get_num_support_vectors(), svm->get_bias());

// classify + display output
CBinaryLabels* out_labels=(CBinaryLabels*) svm->apply();
CBinaryLabels* out_labels=CBinaryLabels::obtain_from_generic(svm->apply());

for (int32_t i=0; i<NUM; i++)
printf("out[%d]=%f (%f)\n", i, out_labels->get_label(i), out_labels->get_confidence(i));
Expand Down
Expand Up @@ -10,7 +10,7 @@

#include <shogun/base/init.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/features/Labels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/classifier/svm/LibSVM.h>
#include <shogun/evaluation/CrossValidation.h>
Expand Down Expand Up @@ -61,7 +61,7 @@ void test_cross_validation()
for (index_t i=0; i<num_vectors; ++i)
lab.vector[i]=i<num_vectors/2 ? -1.0 : 1.0;

CLabels* labels=new CLabels(lab);
CBinaryLabels* labels=new CBinaryLabels(lab);

/* gaussian kernel */
int32_t kernel_cache=100;
Expand All @@ -77,7 +77,7 @@ void test_cross_validation()

/* train and output */
svm->train(features);
CLabels* output=svm->apply(features);
CBinaryLabels* output=CBinaryLabels::obtain_from_generic(svm->apply(features));
for (index_t i=0; i<num_vectors; ++i)
SG_SPRINT("i=%d, class=%f,\n", i, output->get_label(i));

Expand Down
Expand Up @@ -9,7 +9,7 @@

#include <shogun/base/init.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/features/Labels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/classifier/svm/LibSVM.h>
#include <shogun/classifier/svm/SVMLight.h>
Expand Down Expand Up @@ -59,7 +59,7 @@ void test_cross_validation()
for (index_t i=0; i<num_vectors; ++i)
lab.vector[i]=i<num_vectors/2 ? -1.0 : 1.0;

CLabels* labels=new CLabels(lab);
CBinaryLabels* labels=new CBinaryLabels(lab);

/* gaussian kernel */
CGaussianKernel* kernel=new CGaussianKernel();
Expand All @@ -75,7 +75,7 @@ void test_cross_validation()
/* train and output the normal way */
SG_SPRINT("starting normal training\n");
svm->train(features);
CLabels* output=svm->apply(features);
CBinaryLabels* output=CBinaryLabels::obtain_from_generic(svm->apply(features));

/* evaluation criterion */
CContingencyTableEvaluation* eval_crit=
Expand Down
Expand Up @@ -10,7 +10,7 @@

#include <shogun/base/init.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/features/Labels.h>
#include <shogun/labels/MulticlassLabels.h>
#include <shogun/multiclass/MulticlassLibLinear.h>
#include <shogun/io/StreamingAsciiFile.h>
#include <shogun/io/SGIO.h>
Expand Down Expand Up @@ -70,7 +70,7 @@ void test_cross_validation()
// Create features with the useful values from mat
CDenseFeatures< float64_t >* features = new CDenseFeatures<float64_t>(mat);

CLabels* labels = new CLabels(num_vectors);
CMulticlassLabels* labels = new CMulticlassLabels(num_vectors);
SG_REF(features);
SG_REF(labels);

Expand All @@ -92,7 +92,7 @@ void test_cross_validation()

/* train and output */
svm->train(features);
CLabels* output=svm->apply(features);
CMulticlassLabels* output=CMulticlassLabels::obtain_from_generic(svm->apply(features));
for (index_t i=0; i<num_vectors; ++i)
SG_SPRINT("i=%d, class=%f,\n", i, output->get_label(i));

Expand Down
Expand Up @@ -10,7 +10,7 @@

#include <shogun/base/init.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/features/Labels.h>
#include <shogun/labels/RegressionLabels.h>
#include <shogun/kernel/LinearKernel.h>
#include <shogun/regression/KernelRidgeRegression.h>
#include <shogun/evaluation/CrossValidation.h>
Expand Down Expand Up @@ -49,7 +49,7 @@ void test_cross_validation()
SG_REF(features);

/* training labels */
CLabels* labels=new CLabels(lab);
CRegressionLabels* labels=new CRegressionLabels(lab);

/* kernel */
CLinearKernel* kernel=new CLinearKernel();
Expand All @@ -65,7 +65,7 @@ void test_cross_validation()

/* train and output */
krr->train(features);
CLabels* output=krr->apply();
CRegressionLabels* output= CRegressionLabels::obtain_from_generic(krr->apply());
for (index_t i=0; i<num_vectors; ++i)
{
SG_SPRINT("x=%f, train=%f, predict=%f\n", train_dat.matrix[i],
Expand Down
4 changes: 2 additions & 2 deletions examples/undocumented/libshogun/features_subset_labels.cpp
Expand Up @@ -9,7 +9,7 @@
*/

#include <shogun/base/init.h>
#include <shogun/features/Labels.h>
#include <shogun/labels/MulticlassLabels.h>
#include <shogun/mathematics/Math.h>

using namespace shogun;
Expand All @@ -28,7 +28,7 @@ int main(int argc, char **argv)
const int32_t num_subset_idx=CMath::random(1, num_labels);

/* create labels */
CLabels* labels=new CLabels(num_labels);
CMulticlassLabels* labels=new CMulticlassLabels(num_labels);
for (index_t i=0; i<num_labels; ++i)
labels->set_label(i, i%num_classes);

Expand Down
Expand Up @@ -15,7 +15,7 @@
#include <shogun/modelselection/GridSearchModelSelection.h>
#include <shogun/modelselection/ModelSelectionParameters.h>
#include <shogun/modelselection/ParameterCombination.h>
#include <shogun/features/Labels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/classifier/svm/LibSVM.h>
#include <shogun/kernel/GaussianKernel.h>
Expand Down Expand Up @@ -101,7 +101,7 @@ int main(int argc, char **argv)

/* create some data and labels */
SGMatrix<float64_t> matrix(dim_vectors, num_vectors);
CLabels* labels=new CLabels(num_vectors);
CBinaryLabels* labels=new CBinaryLabels(num_vectors);

for (int32_t i=0; i<num_vectors*dim_vectors; i++)
matrix.matrix[i]=CMath::randn_double();
Expand Down
Expand Up @@ -16,7 +16,7 @@
#include <shogun/modelselection/GridSearchModelSelection.h>
#include <shogun/modelselection/ModelSelectionParameters.h>
#include <shogun/modelselection/ParameterCombination.h>
#include <shogun/features/Labels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/classifier/svm/LibLinear.h>

Expand Down Expand Up @@ -59,7 +59,7 @@ int main(int argc, char **argv)
CDenseFeatures<float64_t>* features=new CDenseFeatures<float64_t>(matrix);

/* create three labels */
CLabels* labels=new CLabels(num_vectors);
CBinaryLabels* labels=new CBinaryLabels(num_vectors);
for (index_t i=0; i<num_vectors; ++i)
labels->set_label(i, i%2==0 ? 1 : -1);

Expand Down
Expand Up @@ -15,7 +15,7 @@
#include <shogun/modelselection/GridSearchModelSelection.h>
#include <shogun/modelselection/ModelSelectionParameters.h>
#include <shogun/modelselection/ParameterCombination.h>
#include <shogun/features/Labels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/features/StringFeatures.h>
#include <shogun/classifier/svm/LibSVM.h>
#include <shogun/kernel/DistantSegmentsKernel.h>
Expand Down Expand Up @@ -102,7 +102,7 @@ int main(int argc, char **argv)
CStringFeatures<char>* features=new CStringFeatures<char>(strings, ALPHANUM);

/* create labels, two classes */
CLabels* labels=new CLabels(num_strings);
CBinaryLabels* labels=new CBinaryLabels(num_strings);
for (index_t i=0; i<num_strings; ++i)
labels->set_label(i, i%2==0 ? 1 : -1);

Expand Down

0 comments on commit c54276b

Please sign in to comment.