Skip to content

Commit

Permalink
shareboost cookbook with integration test data
Browse files Browse the repository at this point in the history
  • Loading branch information
OXPHOS committed Jun 28, 2016
1 parent d6353fe commit 22edc6b
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 40 deletions.
33 changes: 33 additions & 0 deletions doc/cookbook/source/examples/multiclass_classifier/shareboost.rst
@@ -0,0 +1,33 @@
==========
ShareBoost
==========

ShareBoost algorithm learns a multiclass predictor from a subset of shared features of the samples with forward greedy selection approach.

See :cite:`shalev2011shareboost` for a detailed introduction.

-------
Example
-------
Imagine we have files with training and test data. We create CDenseFeatures (here 64 bit floats aka RealFeatures) and :sgclass:`CMulticlassLabels` as

.. sgexample:: shareboost.sg:create_features

We create an instance of the :sgclass:`CShareBoost` classifier by setting the number of features expected to be used for learning.

.. sgexample:: shareboost.sg:create_instance

Then we train and apply it to test data, which gives :sgclass:`CMulticlassLabels`.

.. sgexample:: shareboost.sg:train_and_apply

We can evaluate test performance via e.g. :sgclass:`CMulticlassAccuracy`.

.. sgexample:: shareboost.sg:evaluate_accuracy

----------
References
----------

.. bibliography:: ../../references.bib
:filter: docname in docnames
7 changes: 7 additions & 0 deletions doc/cookbook/source/references.bib
Expand Up @@ -79,3 +79,10 @@ @inproceedings{gao2011discriminative
year={2011},
organization={IEEE}
}
@inproceedings{shalev2011shareboost,
title={Shareboost: Efficient multiclass learning with feature sharing},
author={Shalev-Shwartz, Shai and Wexler, Yonatan and Shashua, Amnon},
booktitle={Advances in Neural Information Processing Systems},
pages={1179--1187},
year={2011}
}
1 change: 1 addition & 0 deletions examples/meta/generator/targets/cpp.json
Expand Up @@ -15,6 +15,7 @@
"Assign": "$lhs = $expr",
"Type": {
"RealFeatures": "DenseFeatures<float64_t>",
"RealSubsetFeatures": "DenseSubsetFeatures<float64_t>",
"StringCharFeatures": "CStringFeatures<char>",
"Default": "$type",
"bool": "bool",
Expand Down
29 changes: 29 additions & 0 deletions examples/meta/src/multiclass_classifier/shareboost.sg
@@ -0,0 +1,29 @@
CSVFile f_feats_train("../../data/classifier_4class_2d_linear_features_train.dat")
CSVFile f_feats_test("../../data/classifier_4class_2d_linear_features_test.dat")
CSVFile f_labels_train("../../data/classifier_4class_2d_linear_labels_train.dat")
CSVFile f_labels_test("../../data/classifier_4class_2d_linear_labels_test.dat")

#![create_features]
RealFeatures features_train(f_feats_train)
RealFeatures features_test(f_feats_test)
MulticlassLabels labels_train(f_labels_train)
MulticlassLabels labels_test(f_labels_test)
#![create_features]

#![create_instance]
ShareBoost shareboost(features_train, labels_train, 2)
#![create_instance]

#![train_and_apply]
shareboost.train()
RealSubsetFeatures features_test_sub(features_test, shareboost.get_activeset())
MulticlassLabels labels_predict = shareboost.apply_multiclass(features_test_sub)
#![train_and_apply]

#![evaluate_accuracy]
MulticlassAccuracy eval()
real accuracy = eval.evaluate(labels_predict, labels_test)
#![evaluate_accuracy]

# additional integration testing variables
RealVector output = labels_predict.get_labels()

This file was deleted.

0 comments on commit 22edc6b

Please sign in to comment.