Skip to content

Commit

Permalink
Added libshogun test for the GNB classifier
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jan 9, 2012
1 parent 681147a commit 1309149
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/undocumented/libshogun/Makefile
Expand Up @@ -54,7 +54,8 @@ TARGETS = basic_minimal classifier_libsvm classifier_minimal_svm \
converter_linearlocaltangentspacealignment \
converter_localitypreservingprojections \
serialization_basic_tests \
classifier_conjugateindex
classifier_conjugateindex \
classifier_gaussiannaivebayes \

all: $(TARGETS)

Expand Down
42 changes: 42 additions & 0 deletions examples/undocumented/libshogun/classifier_gaussiannaivebayes.cpp
@@ -0,0 +1,42 @@
#include <shogun/features/Labels.h>
#include <shogun/features/SimpleFeatures.h>
#include <shogun/classifier/GaussianNaiveBayes.h>
#include <shogun/base/init.h>
#include <shogun/lib/common.h>
#include <shogun/io/SGIO.h>

using namespace shogun;

int main(int argc, char** argv)
{
init_shogun_with_defaults();

// create some data
float64_t* matrix = SG_MALLOC(float64_t, 6);
for (int32_t i=0; i<6; i++)
matrix[i]=i;

// create three 2-dimensional vectors
// shogun will now own the matrix created
CSimpleFeatures<float64_t>* features= new CSimpleFeatures<float64_t>();
features->set_feature_matrix(matrix, 2, 3);

// create three labels
CLabels* labels=new CLabels(3);
labels->set_label(0, 0);
labels->set_label(1, +1);
labels->set_label(2, +2);

CGaussianNaiveBayes* ci = new CGaussianNaiveBayes(features,labels);
ci->train();

// classify on training examples
for (int32_t i=0; i<3; i++)
SG_SPRINT("output[%d]=%f\n", i, ci->apply(i));

// free up memory
SG_UNREF(ci);

exit_shogun();
return 0;
}

0 comments on commit 1309149

Please sign in to comment.