public void PredictTest2()
{
// We will try to create a Hidden Markov Model which
// can recognize (and predict) the following sequences:
int[][] sequences =
{
new[] { 1, 2, 3, 4, 5 },
new[] { 1, 2, 3, 3, 5 },
new[] { 1, 2, 3 },
};
// Creates a new left-to-right (forward) Hidden Markov Model
// with 4 states for an output alphabet of six characters.
HiddenMarkovModel hmm = new HiddenMarkovModel(new Forward(4), 6);
// Try to fit the model to the data until the difference in
// the average log-likelihood changes only by as little as 0.0001
BaumWelchLearning teacher = new BaumWelchLearning(hmm)
{
Tolerance = 0.0001,
Iterations = 0
};
// Run the learning algorithm on the model
double logLikelihood = teacher.Run(sequences);
// Now, we will try to predict the next
// observations after a base sequence
int length = 1; // number of observations to predict
int[] input = { 1, 2 }; // base sequence for prediction
// Predict the next 1 observation in sequence
int[] prediction = hmm.Predict(input, length);
// At this point, prediction should be int[] { 3 }
Assert.AreEqual(prediction.Length, 1);
Assert.AreEqual(prediction[0], 3);
}