From 4da2a23b474958427855af7a978f332d3649cc78 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Thu, 14 Mar 2013 17:04:39 +0000 Subject: [PATCH] added an example for multiclass serialization that doesnt work (but runs fine) Once muticlass label serialization work this should be turned into a test --- examples/undocumented/libshogun/Makefile | 1 + .../labels_multiclass_serialization.cpp | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 examples/undocumented/libshogun/labels_multiclass_serialization.cpp diff --git a/examples/undocumented/libshogun/Makefile b/examples/undocumented/libshogun/Makefile index 88473e56b9c..8fc20af4e51 100644 --- a/examples/undocumented/libshogun/Makefile +++ b/examples/undocumented/libshogun/Makefile @@ -84,6 +84,7 @@ TARGETS = basic_minimal \ converter_stochasticproximityembedding \ converter_factoranalysis \ serialization_basic_tests \ + serialization_multiclass_labels \ kernel_machine_train_locked \ statistics \ transfer_multitaskleastsquaresregression \ diff --git a/examples/undocumented/libshogun/labels_multiclass_serialization.cpp b/examples/undocumented/libshogun/labels_multiclass_serialization.cpp new file mode 100644 index 00000000000..9017c2b9e73 --- /dev/null +++ b/examples/undocumented/libshogun/labels_multiclass_serialization.cpp @@ -0,0 +1,43 @@ +/* + * 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) 2013 Heiko Strathmann + */ +#include + +using namespace shogun; + +void test_sigmoid_fitting() +{ + CBinaryLabels* labels=new CBinaryLabels(10); + labels->set_values(SGVector(labels->get_num_labels())); + + for (index_t i=0; iget_num_labels(); ++i) + labels->set_value(i%2==0 ? 1 : -1, i); + + labels->get_values().display_vector("scores"); + labels->scores_to_probabilities(); + + /* only two probabilities will be the result, repeatedly, + * assert against reference implementation */ + ASSERT(CMath::abs(labels->get_value(0)-0.8571428439385661)<10E-15); + ASSERT(CMath::abs(labels->get_value(1)-0.14285715606143384)<10E-15); + + SG_UNREF(labels); +} + +int main() +{ + init_shogun_with_defaults(); + +// sg_io->set_loglevel(MSG_DEBUG); + + test_sigmoid_fitting(); + + exit_shogun(); + return 0; +} +