Skip to content

Commit

Permalink
added example/test for fitting sigmoid on binary labels
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Aug 14, 2012
1 parent 47bbe6a commit d75793a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/undocumented/libshogun/Makefile
Expand Up @@ -54,6 +54,7 @@ TARGETS = basic_minimal \
features_copy_subset_string_features \
features_copy_subset_sparse_features \
features_create_merged_copy \
labels_binary_fit_sigmoid \
mathematics_confidence_intervals \
clustering_kmeans base_parameter_map \
base_load_file_parameters \
Expand Down
43 changes: 43 additions & 0 deletions examples/undocumented/libshogun/labels_binary_fit_sigmoid.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) 2012 Heiko Strathmann
*/
#include <shogun/labels/BinaryLabels.h>

using namespace shogun;

void test_sigmoid_fitting()
{
CBinaryLabels* labels=new CBinaryLabels(10);
labels->set_confidences(SGVector<float64_t>(labels->get_num_labels()));

for (index_t i=0; i<labels->get_num_labels(); ++i)
labels->set_confidence(i%2==0 ? 1 : -1, i);

labels->get_confidences().display_vector("scores");
labels->scores_to_probabilities();

/* only two probabilities will be the result, repeatedly,
* assert against reference implementation */
ASSERT(CMath::abs(labels->get_confidence(0)-0.8571428439385661)<10E-15);
ASSERT(CMath::abs(labels->get_confidence(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;
}

0 comments on commit d75793a

Please sign in to comment.