Click or drag to resize
Accord.NET (logo)

HiddenMarkovModelTDistribution, TObservationPredict Method (TObservation, Int32, Double)

Predicts the next observations occurring after a given observation sequence.

Namespace:  Accord.Statistics.Models.Markov
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.8.0
Syntax
public TObservation[] Predict(
	TObservation[] observations,
	int next,
	out double logLikelihood
)
Request Example View Source

Parameters

observations
Type: TObservation
A sequence of observations. Predictions will be made regarding the next observations that should be coming after the last observation in this sequence.
next
Type: SystemInt32
The number of observations to be predicted. Default is 1.
logLikelihood
Type: SystemDouble
The log-likelihood of the given sequence, plus the predicted next observation. Exponentiate this value (use the System.Math.Exp function) to obtain a likelihood value.

Return Value

Type: TObservation
Remarks
This method works by inspecting the forward matrix of probabilities for the sequence and checking which would be the most likely state after the current one. Then, it returns the most likely value (the mode) for the distribution associated with that state. This limits the applicability of this model to only very short-term predictions (i.e. most likely, only the most immediate next observation).
Examples
// We will try to create a Hidden Markov Model which
// can recognize (and predict) the following sequences:
double[][] sequences =
{
    new double[] { 1, 3, 5, 7, 9, 11, 13 },
    new double[] { 1, 3, 5, 7, 9, 11 },
    new double[] { 1, 3, 5, 7, 9, 11, 13 },
    new double[] { 1, 3, 3, 7, 7, 9, 11, 11, 13, 13 },
    new double[] { 1, 3, 7, 9, 11, 13 },
};

// Create a Baum-Welch HMM algorithm:
var teacher = new BaumWelchLearning<NormalDistribution, double, NormalOptions>()
{
    // Let's creates a left-to-right (forward)
    // Hidden Markov Model with 7 hidden states
    Topology = new Forward(7),

    FittingOptions = new NormalOptions()
    {
        Regularization = 1e-8
    },

    // We'll try to fit the model to the data until the difference in
    // the average log-likelihood changes only by as little as 0.0001
    Tolerance = 0.0001,
    Iterations = 0 // do not impose a limit on the number of iterations
};

// Use the algorithm to learn a new Markov model:
HiddenMarkovModel<NormalDistribution, double> hmm = teacher.Learn(sequences);

// Now, we will try to predict the next 1 observation in a base symbol sequence
double[] prediction = hmm.Predict(observations: new double[] { 1, 3, 5, 7, 9 }, next: 1);

// At this point, prediction should be around double[] { 11.909090909090905 }
double nextObservation = prediction[0]; // should be comparatively near 11.
See Also