Ejemplo n.º 1
0
        /// <summary>
        ///   Computes Forward probabilities for a given potential function and a set of observations.
        /// </summary>
        ///
        public static double[,] Forward <TObservation>(FactorPotential <TObservation> function,
                                                       TObservation[] observations, int output, out double logLikelihood)
        {
            int states = function.States;

            double[,] fwd = new double[observations.Length, states];
            double[] coefficients = new double[observations.Length];

            ForwardBackwardAlgorithm.Forward(function, observations, output, coefficients, fwd);

            logLikelihood = 0;
            for (int i = 0; i < coefficients.Length; i++)
            {
                logLikelihood += Math.Log(coefficients[i]);
            }

            return(fwd);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Computes Forward probabilities for a given potential function and a set of observations.
        /// </summary>
        ///
        public static double[,] LogForward <TObservation>(FactorPotential <TObservation> function,
                                                          TObservation[] observations, int output, out double logLikelihood)
        {
            int states = function.States;

            double[,] lnFwd = new double[observations.Length, states];
            int T = observations.Length;

            ForwardBackwardAlgorithm.LogForward(function, observations, output, lnFwd);

            logLikelihood = Double.NegativeInfinity;
            for (int j = 0; j < states; j++)
            {
                logLikelihood = Special.LogSum(logLikelihood, lnFwd[T - 1, j]);
            }

            System.Diagnostics.Debug.Assert(!Double.IsNaN(logLikelihood));

            return(lnFwd);
        }