ObservationDistribution types are used for states of generative models. Such a type can be trained from a set of examples, and can evaluate a similarity measure over observation types.

Refinement of
Notation

The following expressions are used in this document:

ODT

A ObservationDistributionTrainer type.

odt

An object of type OD

OD

The ObservationDistribution type associated with ODT

observation_range

A ForwardRange of objects of type O

Requirements

Name

Expression

Result Type

Semantics

Train With Examples

odt(observation_range)

OD

Trains the ObservationDistribution object from the provided example observations. This is usually done during the training phase of various generative models, where observations in the training sequences are assigned to states of the model, and each state is trained on the assigned states. For probabilistic models, this typically means constructing a probability distribution most likely to produce the provided example observations.

Example

The below example uses a normal distribution to model a state. The training consists of calculating the mean and standard deviation of the provided example observations. The trained distribution is then used to provide a similarity measure with observations.

#include <ame/range/standard_deviation.hpp>
#include <ame/utility/serialize/normal_distribution.hpp>
#include <boost/math/distributions/normal.hpp>

namespace ame { namespace patterns {

class normal_model_state
{
public:
    typedef double observation_type;
    
    normal_model_state(double min_st_dev=std::numeric_limits<double>::min())
        : m_min_st_dev(min_st_dev)
    {}
    double operator()(double a) const
    {
        return pdf(m_distribution,a);
    }
    template<typename Range>
    void train_with_examples(const Range &examples)
    {
        if (examples.size()==0)
            return;
        double mean=ame::range::mean(examples);
        double st_dev=ame::range::standard_deviation(examples, mean);

        m_distribution = boost::math::normal_distribution<>(mean, (std::max)(st_dev, m_min_st_dev));
    }
    const boost::math::normal_distribution<> distribution() const
    {   return m_distribution; }
    bool operator == (const normal_model_state &rhs) const
    {
        return
                m_min_st_dev == rhs.m_min_st_dev
            &&  mean(m_distribution) == mean(rhs.m_distribution)
            && standard_deviation(m_distribution) == standard_deviation(rhs.m_distribution);
    }
private:
    double m_min_st_dev;
    boost::math::normal_distribution<> m_distribution;
    
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
        ar & m_min_st_dev;
        ar & m_distribution;
    }
};

}}