public void Estimate_KsiGammaParameters_TransitionProbabilityMatrixCalculatedAndReturned()
        {
            const int numberOfStates = 2;

            var util         = new TestDataUtils();
            var observations = util.GetSvcData(util.FTSEFilePath, new DateTime(2010, 12, 18), new DateTime(2011, 12, 18));
            var model        = HiddenMarkovModelStateFactory.GetState(new ModelCreationParameters <NormalDistribution>()
            {
                NumberOfStates = numberOfStates, Emissions = CreateEmissions(observations, numberOfStates)
            });

            model.Normalized = true;
            var observationsList = new List <IObservation>();

            for (var i = 0; i < observations.Length; i++)
            {
                observationsList.Add(new Observation(observations[i], i.ToString()));
            }
            var baseEstimator = new BasicEstimationParameters <NormalDistribution> {
                Model = model, Observations = Helper.Convert(observations), Normalized = model.Normalized
            };
            var alphaEstimator = new AlphaEstimator <NormalDistribution>();
            var alpha          = alphaEstimator.Estimate(baseEstimator);
            var betaEstimator  = new BetaEstimator <NormalDistribution>();
            var beta           = betaEstimator.Estimate(baseEstimator);
            var @params        = new AdvancedEstimationParameters <NormalDistribution>
            {
                Alpha        = alpha,
                Beta         = beta,
                Observations = observationsList,
                Model        = model,
                Normalized   = model.Normalized
            };
            var gammaEstimator = new GammaEstimator <NormalDistribution>();
            var ksiEstimator   = new KsiEstimator <NormalDistribution>();
            var gamma          = gammaEstimator.Estimate(@params);
            var ksi            = ksiEstimator.Estimate(@params);
            var estimator      = new TransitionProbabilityEstimator <NormalDistribution>();
            var parameters     = new KsiGammaTransitionProbabilityMatrixParameters <NormalDistribution>
            {
                Model      = model,
                Ksi        = ksi,
                Gamma      = gamma,
                T          = observations.Length,
                Normalized = model.Normalized
            };

            var estimatedTransitionProbabilityMatrix = estimator.Estimate(parameters);

            Assert.AreEqual(1d, Math.Round(estimatedTransitionProbabilityMatrix[0][0] + estimatedTransitionProbabilityMatrix[0][1], 5));
            Assert.AreEqual(1d, Math.Round(estimatedTransitionProbabilityMatrix[1][0] + estimatedTransitionProbabilityMatrix[1][1], 5));
        }
        public void Estimate_AlphaBetaParameters_TransitionProbabilityMatrixCalculatedAndReturned()
        {
            const int numberOfStates = 2;

            var util         = new TestDataUtils();
            var observations = util.GetSvcData(util.FTSEFilePath, new DateTime(2010, 12, 18), new DateTime(2011, 12, 18));
            var model        = HiddenMarkovModelStateFactory.GetState(new ModelCreationParameters <NormalDistribution>()
            {
                NumberOfStates = numberOfStates, Emissions = CreateEmissions(observations, numberOfStates)
            });

            model.Normalized = true;
            var baseParameters = new BasicEstimationParameters <NormalDistribution> {
                Model = model, Observations = Helper.Convert(observations), Normalized = model.Normalized
            };
            var alphaEstimator = new AlphaEstimator <NormalDistribution>();
            var alpha          = alphaEstimator.Estimate(baseParameters);

            var betaEstimator = new BetaEstimator <NormalDistribution>();
            var beta          = betaEstimator.Estimate(baseParameters);
            var weights       = new double[observations.Length];

            var estimator  = new TransitionProbabilityEstimator <NormalDistribution>();
            var parameters = new AlphaBetaTransitionProbabiltyMatrixParameters <NormalDistribution>
            {
                Alpha        = alpha,
                Beta         = beta,
                Model        = model,
                Observations = observations,
                Normalized   = model.Normalized,
                Weights      = weights
            };

            var estimatedTransitionProbabilityMatrix = estimator.Estimate(parameters);

            Assert.AreEqual(1d, Math.Round(estimatedTransitionProbabilityMatrix[0][0] + estimatedTransitionProbabilityMatrix[0][1], 5));
            Assert.AreEqual(1d, Math.Round(estimatedTransitionProbabilityMatrix[1][0] + estimatedTransitionProbabilityMatrix[1][1], 5));
        }