public void Sigma_RightLeftAndParametersAnnNotNormalized_SigmaCalculated() { var delta = 3; 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 <Mixture <IMultivariateDistribution> >() { NumberOfStates = NumberOfStatesRightLeft, Delta = delta, Emissions = CreateEmissions(observations, NumberOfStatesRightLeft, NumberOfComponents) }); //new HiddenMarkovModelState<Mixture<IMultivariateDistribution>>(NumberOfStatesRightLeft, delta, CreateEmissions(observations, NumberOfStatesRightLeft, NumberOfComponents)) { LogNormalized = false }; model.Normalized = false; var baseParameters = new BasicEstimationParameters <Mixture <IMultivariateDistribution> > { Model = model, Observations = Helper.Convert(observations), Normalized = model.Normalized }; var alphaEstimator = new AlphaEstimator <Mixture <IMultivariateDistribution> >(); var alpha = alphaEstimator.Estimate(baseParameters); var betaEstimator = new BetaEstimator <Mixture <IMultivariateDistribution> >(); var beta = betaEstimator.Estimate(baseParameters); var parameters = new ParameterEstimations <Mixture <IMultivariateDistribution> >(model, Helper.Convert(observations), alpha, beta); var sigma = new MixtureSigmaEstimator <Mixture <IMultivariateDistribution> >(); var mixtureGammaEstimator = new MixtureGammaEstimator <Mixture <IMultivariateDistribution> >(); var mixtureMuEstimator = new MixtureMuEstimator <Mixture <IMultivariateDistribution> >(); var @params = new MixtureSigmaEstimationParameters <Mixture <IMultivariateDistribution> > { Model = model, Normalized = model.Normalized, Alpha = alpha, Beta = beta, Observations = Helper.Convert(observations), L = model.Emission[0].Components.Length }; var gamma = mixtureGammaEstimator.Estimate(@params as AdvancedEstimationParameters <Mixture <IMultivariateDistribution> >); var gammaComponens = mixtureGammaEstimator.Estimate(@params); @params.Gamma = gamma; @params.GammaComponents = gammaComponens; @params.Mu = mixtureMuEstimator.Estimate(@params); for (int i = 0; i < NumberOfStatesRightLeft; i++) { for (int l = 0; l < NumberOfComponents; l++) { for (int rows = 0; rows < parameters.Observation[0].Dimention; rows++) { for (int cols = 0; cols < parameters.Observation[0].Dimention; cols++) { Assert.IsTrue(sigma.Estimate(@params)[i, l][rows, cols] > 0, string.Format("Failed Sigma {0}", sigma.Estimate(@params)[i, l][rows, cols])); } } } } }
public void Denormalized_NormalizedEstimator_SigmaDenormalized() { 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 <Mixture <IMultivariateDistribution> >() { NumberOfStates = NumberOfStates, Emissions = CreateEmissions(observations, NumberOfStates, NumberOfComponents) }); //new HiddenMarkovModelState<Mixture<IMultivariateDistribution>>(NumberOfStates, CreateEmissions(observations, NumberOfStates, NumberOfComponents)) { LogNormalized = true }; model.Normalized = true; var baseParameters = new BasicEstimationParameters <Mixture <IMultivariateDistribution> > { Model = model, Observations = Helper.Convert(observations), Normalized = model.Normalized }; var alphaEstimator = new AlphaEstimator <Mixture <IMultivariateDistribution> >(); var alpha = alphaEstimator.Estimate(baseParameters); var betaEstimator = new BetaEstimator <Mixture <IMultivariateDistribution> >(); var beta = betaEstimator.Estimate(baseParameters); var parameters = new ParameterEstimations <Mixture <IMultivariateDistribution> >(model, Helper.Convert(observations), alpha, beta); var coefficients = new MixtureCoefficientsEstimator <Mixture <IMultivariateDistribution> >(); var mixtureGammaEstimator = new MixtureGammaEstimator <Mixture <IMultivariateDistribution> >(); var @params = new MixtureCoefficientEstimationParameters <Mixture <IMultivariateDistribution> > { Model = model, Normalized = model.Normalized, Alpha = alpha, Beta = beta, Observations = Helper.Convert(observations), L = model.Emission[0].Components.Length }; var gamma = mixtureGammaEstimator.Estimate(@params as AdvancedEstimationParameters <Mixture <IMultivariateDistribution> >); var gammaComponens = mixtureGammaEstimator.Estimate(@params); @params.Gamma = gamma; @params.GammaComponents = gammaComponens; for (int i = 0; i < NumberOfStates; i++) { for (int l = 0; l < NumberOfComponents; l++) { Assert.IsTrue(coefficients.Estimate(@params)[i][l] < 0, string.Format("Failed Coefficients {0}", coefficients.Estimate(@params)[i][l])); } } coefficients.Denormalize(); for (int i = 0; i < NumberOfStates; i++) { for (int l = 0; l < NumberOfComponents; l++) { Assert.IsTrue(coefficients.Estimate(@params)[i][l] > 0 && coefficients.Estimate(@params)[i][l] < 1, string.Format("Failed Coefficients {0}", coefficients.Estimate(@params)[i][l])); } } }
public void Coefficients_RightLeftAndNotNormilized_EachEntryMatrixIsSummedToOne() { var delta = 3; 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 <Mixture <IMultivariateDistribution> >() { NumberOfStates = NumberOfStatesRightLeft, Delta = delta, Emissions = CreateEmissions(observations, NumberOfStatesRightLeft, NumberOfComponents) }); //new HiddenMarkovModelState<Mixture<IMultivariateDistribution>>(NumberOfStatesRightLeft, delta, CreateEmissions(observations, NumberOfStatesRightLeft, NumberOfComponents)) { LogNormalized = false }; model.Normalized = false; var baseParameters = new BasicEstimationParameters <Mixture <IMultivariateDistribution> > { Model = model, Observations = Helper.Convert(observations), Normalized = model.Normalized }; var alphaEstimator = new AlphaEstimator <Mixture <IMultivariateDistribution> >(); var alpha = alphaEstimator.Estimate(baseParameters); var betaEstimator = new BetaEstimator <Mixture <IMultivariateDistribution> >(); var beta = betaEstimator.Estimate(baseParameters); var parameters = new ParameterEstimations <Mixture <IMultivariateDistribution> >(model, Helper.Convert(observations), alpha, beta); var coefficients = new MixtureCoefficientsEstimator <Mixture <IMultivariateDistribution> >(); var mixtureGammaEstimator = new MixtureGammaEstimator <Mixture <IMultivariateDistribution> >(); var @params = new MixtureCoefficientEstimationParameters <Mixture <IMultivariateDistribution> > { Model = model, Normalized = model.Normalized, Alpha = alpha, Beta = beta, Observations = Helper.Convert(observations), L = model.Emission[0].Components.Length }; var gamma = mixtureGammaEstimator.Estimate(@params as AdvancedEstimationParameters <Mixture <IMultivariateDistribution> >); var gammaComponens = mixtureGammaEstimator.Estimate(@params); @params.Gamma = gamma; @params.GammaComponents = gammaComponens; for (int i = 0; i < NumberOfStates; i++) { Assert.AreEqual(1.0d, Math.Round(coefficients.Estimate(@params)[i].Sum(), 5), string.Format("Failed Coefficients {0} at component {1}", new Vector(coefficients.Estimate(@params)[i]), i)); } }