Exemplo n.º 1
0
        public void Sigma_ErgodicAndObservationAndLogNormalized_SigmaCalculated()
        {
            var util         = new TestDataUtils();
            var observations = util.GetSvcData(util.FTSEFilePath, new DateTime(2011, 11, 18), new DateTime(2011, 12, 18));
            var sequence     = Helper.Convert(observations);
            var model        = HiddenMarkovModelStateFactory.GetState(new ModelCreationParameters <NormalDistribution>()
            {
                NumberOfStates = NumberOfStates, Emissions = CreateEmissions(observations, NumberOfStates)
            });                                                                                                                                                                                                  //new HiddenMarkovModelState<NormalDistribution>(NumberOfStates, CreateEmissions(observations, NumberOfStates)) { LogNormalized = true };

            model.Normalized = true;
            var baseParameters = new BasicEstimationParameters <NormalDistribution> {
                Model = model, Observations = sequence, Normalized = model.Normalized
            };
            var alphaEstimator = new AlphaEstimator <NormalDistribution>();
            var alpha          = alphaEstimator.Estimate(baseParameters);
            var betaEstimator  = new BetaEstimator <NormalDistribution>();
            var beta           = betaEstimator.Estimate(baseParameters);

            var @params = new AdvancedEstimationParameters <NormalDistribution>
            {
                Alpha        = alpha,
                Beta         = beta,
                Observations = sequence,
                Model        = model
            };
            var gammaEstimator = new GammaEstimator <NormalDistribution>();
            var muEstimator    = new MuMultivariateEstimator <NormalDistribution>();
            var estimator      = new SigmaMultivariateEstimator <NormalDistribution>();
            var muParams       = new MuEstimationParameters <NormalDistribution>
            {
                Gamma        = gammaEstimator.Estimate(@params),
                Model        = model,
                Normalized   = model.Normalized,
                Observations = Helper.Convert(observations)
            };

            Assert.IsNotNull(estimator);
            var sigma = estimator.Estimate(new SigmaEstimationParameters <NormalDistribution, double[][]>(muParams)
            {
                Mean = muEstimator.Estimate(muParams)
            });

            for (int n = 0; n < NumberOfStates; n++)
            {
                for (int i = 0; i < sequence[0].Dimention; i++)
                {
                    for (int j = 0; j < sequence[0].Dimention; j++)
                    {
                        Assert.IsTrue(sigma[n][i, j] > 0, string.Format("Failed Sigma {0}", sigma[n][i, j]));
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void MuEstimator_ModelAndObservations_MuEstimatorCreated()
        {
            var util         = new TestDataUtils();
            var observations = util.GetSvcData(util.FTSEFilePath, new DateTime(2011, 11, 18), new DateTime(2011, 12, 18));
            var model        = HiddenMarkovModelStateFactory.GetState(new ModelCreationParameters <NormalDistribution>()
            {
                NumberOfStates = NumberOfStates, Emissions = CreateEmissions(observations, NumberOfStates)
            });                                                                                                                                                                                                   //new HiddenMarkovModelState<NormalDistribution>(NumberOfStates, CreateEmissions(observations, NumberOfStates)) { LogNormalized = true };

            model.Normalized = true;

            var estimator = new MuMultivariateEstimator <NormalDistribution>();

            Assert.IsNotNull(estimator);
        }
Exemplo n.º 3
0
        public void Mu_MultivariateAndRightLeftAndNotNormalized_MuCalculated()
        {
            var delta        = 3;
            var util         = new TestDataUtils();
            var observations = util.GetSvcData(util.FTSEFilePath, new DateTime(2011, 11, 18), new DateTime(2011, 12, 18));
            var sequence     = Helper.Convert(observations);
            var model        = HiddenMarkovModelStateFactory.GetState(new ModelCreationParameters <NormalDistribution>()
            {
                NumberOfStates = NumberOfStatesRightLeft, Delta = delta, Emissions = CreateEmissions(observations, NumberOfStatesRightLeft)
            });                                                                                                                                                                                                                                   //new HiddenMarkovModelState<NormalDistribution>(NumberOfStatesRightLeft, delta, CreateEmissions(observations, NumberOfStatesRightLeft)) { LogNormalized = false };

            model.Normalized = false;
            var baseParameters = new BasicEstimationParameters <NormalDistribution> {
                Model = model, Observations = sequence, Normalized = model.Normalized
            };
            var alphaEstimator = new AlphaEstimator <NormalDistribution>();
            var alpha          = alphaEstimator.Estimate(baseParameters);
            var betaEstimator  = new BetaEstimator <NormalDistribution>();
            var beta           = betaEstimator.Estimate(baseParameters);
            var @params        = new AdvancedEstimationParameters <NormalDistribution>
            {
                Alpha        = alpha,
                Beta         = beta,
                Observations = sequence,
                Model        = model
            };

            var gammaEstimator = new GammaEstimator <NormalDistribution>();
            var estimator      = new MuMultivariateEstimator <NormalDistribution>();
            var muParams       = new MuEstimationParameters <NormalDistribution>
            {
                Gamma        = gammaEstimator.Estimate(@params),
                Model        = model,
                Normalized   = model.Normalized,
                Observations = sequence
            };

            Assert.IsNotNull(estimator);
            var mu = estimator.Estimate(muParams);

            for (int i = 0; i < NumberOfStatesRightLeft; i++)
            {
                for (int j = 0; j < sequence[0].Dimention; j++)
                {
                    Assert.IsTrue(mu[i][j] > 0, string.Format("Failed Mu {0}", mu[i][j]));
                }
            }
        }