See also: classification_task reference.

The classification task serves to classify a pattern into a number of pattern models.

#include <ame/patterns/task/classification.hpp>
#include <ame/patterns/model/chain_hmm.hpp>
#include <ame/observations/training/normal.hpp>

#include <boost/assign/std/vector.hpp>


#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>


BOOST_AUTO_TEST_CASE( test ) 
{
    namespace patterns = ame::patterns;
    namespace observations = ame::observations;
    
    patterns::classification_task
    <
        // use a chain_hmm model, with a normal observation distribution
        patterns::model::chain_hmm<observations::normal>,
        // use the EM algorithm for training
        patterns::expectation_maximization_training,
        // use the forward algorithm for inference
        patterns::forward_inference
    >
        task;
    
    // this will hold our training example
    std::vector<std::vector<double> > examples(2);
    
    using namespace boost::assign;
    
    // two examples for pattern 0
    examples.front() += 0, 0.1, -0.1, 0.2, 0.2, 0.2, 1.1;
    examples.back() += 0.1, 1.2;
    
    // add a new pattern model with 2 states, trained from the examples
    task.add_pattern_with_examples(2, examples);
    
    examples.clear();
    examples.resize(2);

    // examples for pattern 1
    examples.front() += -0.4, 1.1;
    examples.back() += -0.3, 1.2;
    
    // add a new pattern model with 2 states, trained from the examples
    task.add_pattern_with_examples(2, examples);
    
    // this is our pattern to classify
    std::vector<double> pattern;
    pattern += -0.2, 1.1;
    
    // task.classify(pattern) should return 1
    BOOST_CHECK_EQUAL(task.classify(pattern), 1u);
}