예제 #1
0
        public override double[][][] EstimateXi(IMLDataSet sequence,
                                                ForwardBackwardCalculator fbc, HiddenMarkovModel hmm)
        {
            if (sequence.Count <= 1)
            {
                throw new EncogError(
                          "Must have more than one observation");
            }

            double[][][] xi          = EngineArray.AllocDouble3D((int)sequence.Count - 1, hmm.StateCount, hmm.StateCount);
            double       probability = fbc.Probability();

            for (int t = 0; t < (sequence.Count - 1); t++)
            {
                IMLDataPair o = sequence[t + 1];

                for (int i = 0; i < hmm.StateCount; i++)
                {
                    for (int j = 0; j < hmm.StateCount; j++)
                    {
                        xi[t][i][j] = (fbc.AlphaElement(t, i)
                                       * hmm.TransitionProbability[i][j]
                                       * hmm.StateDistributions[j].Probability(o) * fbc
                                       .BetaElement(t + 1, j)) / probability;
                    }
                }
            }

            return(xi);
        }