public override void DoWork()
        {
            base.DoWork();

            AlphaPass();
            BetaPass();

            _probabilitySuffix = StateSpace.Sum(
                state =>
                InitialProbabilitiesOfStates[state] * EmissionMatrix[state, SequenceOfObservations[0]] *
                beta[state][0]);
            _probabilityPrefix = StateSpace.Sum(state => alpha[state][T - 1]);

            var TOLERANCE = 1e-3;

            if (Math.Abs((_probabilitySuffix - _probabilityPrefix) / _probabilityPrefix) > TOLERANCE)
            {
                throw new Exception("Probabilities are not equal");
            }

            // Probability = (_probabilitySuffix + _probabilityPrefix)/2.0;

            LogProbability = 0.0;


            for (int i = 0; i < T; i++)
            {
                LogProbability -= Math.Log(c[i]);
            }
            Probability = Math.Exp(LogProbability);

            Output = new TState[T];

            for (var i = 0; i < T; i++)
            {
                var mostProbableState = StateSpace.Aggregate(
                    (s1, s2) =>
                    alpha[s1][i] * beta[s1][i] >
                    alpha[s2][i] * beta[s2][i]
                            ? s1
                            : s2);
                Output[i] = mostProbableState;
            }
        }