Package plm.hmm

Examples of plm.hmm.DlmHiddenMarkovModel


            .copyArray(new double[] { 0.7d, 0.3d });
    Matrix classTransProbs = MatrixFactory.getDefault().copyArray(
                new double[][] { { 0.7d, 0.7d },
                    { 0.3d, 0.3d } });
   
    DlmHiddenMarkovModel dlmHmm = new DlmHiddenMarkovModel(
        Lists.newArrayList(trueKf1, trueKf2),
        initialClassProbs, classTransProbs);

    final StandardHMM<Double> trueHmm1 =
        StandardHMM.create(
        new HiddenMarkovModel<Double>(initialClassProbs,
            classTransProbs, Lists.newArrayList(
                s1Likelihood, s2Likelihood)));

    final HmmPlFilter<StandardHMM<Double>, GaussianArTransitionState, Double> wfFilter =
        new GaussianArHmmPlFilter(trueHmm1, prior, a, sigma2, sigma_y2, random, true);
    final GaussianArHmmMkfFilter rsFilter =
        new GaussianArHmmMkfFilter(trueHmm1, prior, a, sigma2, sigma_y2, random);


    String outputFilename = args[0] + "/hmm-nar-wf-rs-10000-class-errors-m1.csv";
    final int K = 10;
    final int T = 300;

    List<SimHmmObservedValue<Vector, Vector>> simulation = dlmHmm.sample(random, T);

    wfFilter.setNumParticles(N);
    wfFilter.setResampleOnly(false);
    rsFilter.setNumParticles(N);
View Full Code Here


            .copyArray(new double[] { 0.7d, 0.3d });
    Matrix classTransProbs = MatrixFactory.getDefault().copyArray(
                new double[][] { { 0.7d, 0.7d },
                    { 0.3d, 0.3d } });
   
    DlmHiddenMarkovModel trueHmm1 = new DlmHiddenMarkovModel(
        Lists.newArrayList(trueKf1, trueKf2),
        initialClassProbs, classTransProbs);

    final double sigmaPriorMean = Math.pow(0.4, 2);
    final double sigmaPriorShape = 2d;
    final double sigmaPriorScale = sigmaPriorMean*(sigmaPriorShape + 1d);
    final InverseGammaDistribution sigmaPrior = new InverseGammaDistribution(sigmaPriorShape,
        sigmaPriorScale);
   
    final Vector phiMean1 = VectorFactory.getDefault().copyArray(new double[] {
        0d, 0.8d
    });
    final Matrix phiCov1 = MatrixFactory.getDefault().copyArray(new double[][] {
        {2d + 4d * sigmaPriorMean, 0d},
        { 0d, 4d * sigmaPriorMean}
    });
    final MultivariateGaussian phiPrior1 = new MultivariateGaussian(phiMean1, phiCov1);

    final Vector phiMean2 = VectorFactory.getDefault().copyArray(new double[] {
        0d, 0.1d
    });
    final Matrix phiCov2 = MatrixFactory.getDefault().copyArray(new double[][] {
        { 1d + 4d * sigmaPriorMean, 0d},
        { 0d, 4d * sigmaPriorMean}
    });
    final MultivariateGaussian phiPrior2 = new MultivariateGaussian(phiMean2, phiCov2);
   
    List<MultivariateGaussian> priorPhis = Lists.newArrayList(phiPrior1, phiPrior2);

    final HmmPlFilter<DlmHiddenMarkovModel, GaussianArHpTransitionState, Vector> wfFilter =
        new GaussianArHpHmmPLFilter(trueHmm1, sigmaPrior, priorPhis, random, true);


    final String path;
    if (args.length == 0)
      path = ".";
    else
      path = args[0];
    String outputFilename = path + "/hmm-nar-wf-rs-10000-class-errors-m1.csv";

    final int K = 5;
    final int T = 700;
    final int N = 1000;

    /*
     * Note: replications are over the same set of simulated observations.
     */
    List<SimHmmObservedValue<Vector, Vector>> simulation = trueHmm1.sample(random, T);

    wfFilter.setNumParticles(N);
    wfFilter.setResampleOnly(false);

    CSVWriter writer = new CSVWriter(new FileWriter(outputFilename), ',');
View Full Code Here

            .copyArray(new double[] { 0.7d, 0.3d });
    Matrix classTransProbs = MatrixFactory.getDefault().copyArray(
                new double[][] { { 0.7d, 0.7d },
                    { 0.3d, 0.3d } });
   
    DlmHiddenMarkovModel dlmHmm = new DlmHiddenMarkovModel(
        Lists.newArrayList(trueKf1, trueKf2),
        initialClassProbs, classTransProbs);

    final StandardHMM<Double> trueHmm1 =
        StandardHMM.create(
        new HiddenMarkovModel<Double>(initialClassProbs,
            classTransProbs, Lists.newArrayList(
                s1Likelihood, s2Likelihood)));

    final GaussianArHmmMkfFilter rsFilter =
        new GaussianArHmmMkfFilter(trueHmm1, prior, a, sigma2, sigma_y2, random);

    final int K = 3;
    final int T = 100;

    List<SimHmmObservedValue<Vector, Vector>> simulation = dlmHmm.sample(random, T);

    rsFilter.setNumParticles(N);

    GaussianArHmmRmseEvaluator mkfRmseEvaluator = new GaussianArHmmRmseEvaluator("mkf",
        null);
View Full Code Here

            .copyArray(new double[] { 0.5d, 0.5d });
    Matrix classTransProbs = MatrixFactory.getDefault().copyArray(
                new double[][] { { 0.5d, 0.5d },
                    { 0.5d, 0.5d } });
   
    DlmHiddenMarkovModel trueHmm1 = new DlmHiddenMarkovModel(
        Lists.newArrayList(trueKf1, trueKf2),
        initialClassProbs, classTransProbs);

    final double sigmaPriorMean = Math.pow(0.4, 2);
    final double sigmaPriorShape = 2d;
    final double sigmaPriorScale = sigmaPriorMean*(sigmaPriorShape + 1d);
    final InverseGammaDistribution sigmaPrior = new InverseGammaDistribution(sigmaPriorShape,
        sigmaPriorScale);
   
    final Vector phiMean1 = VectorFactory.getDefault().copyArray(new double[] {
        0d, 0.8d
    });
    final Matrix phiCov1 = MatrixFactory.getDefault().copyArray(new double[][] {
        {2d + 4d * sigmaPriorMean, 0d},
        { 0d, 4d * sigmaPriorMean}
    });
    final MultivariateGaussian phiPrior1 = new MultivariateGaussian(phiMean1, phiCov1);

    final Vector phiMean2 = VectorFactory.getDefault().copyArray(new double[] {
        0d, 0.1d
    });
    final Matrix phiCov2 = MatrixFactory.getDefault().copyArray(new double[][] {
        { 1d + 4d * sigmaPriorMean, 0d},
        { 0d, 4d * sigmaPriorMean}
    });
    final MultivariateGaussian phiPrior2 = new MultivariateGaussian(phiMean2, phiCov2);
   
    List<MultivariateGaussian> priorPhis = Lists.newArrayList(phiPrior1, phiPrior2);

    final HmmPlFilter<DlmHiddenMarkovModel, GaussianArHpTransitionState, Vector> wfFilter =
        new GaussianArHpHmmPLFilter(trueHmm1, sigmaPrior, priorPhis, random, true);

    final int K = 3;
    final int T = 200;
    final int N = 1000;

    /*
     * Note: replications are over the same set of simulated observations.
     */
    List<SimHmmObservedValue<Vector, Vector>> simulation = trueHmm1.sample(random, T);

    wfFilter.setNumParticles(N);
    wfFilter.setResampleOnly(false);

    log.info("rep\tt\tfilter.type\tmeasurement.type\tresample.type\tmeasurement");
View Full Code Here

            .copyArray(new double[] { 0.4d, 0.6d });
    Matrix classTransProbs = MatrixFactory.getDefault().copyArray(
                new double[][] { { 0.9d, 0.1d },
                    { 0.1d, 0.9d } });
   
    DlmHiddenMarkovModel trueHmm1 = new DlmHiddenMarkovModel(
        Lists.newArrayList(trueKf1, trueKf2),
        initialClassProbs, classTransProbs);

    final double sigmaPriorMean = Math.pow(0.4, 2);
    final double sigmaPriorShape = 2d;
    final double sigmaPriorScale = sigmaPriorMean*(sigmaPriorShape + 1d);
    final InverseGammaDistribution sigmaPrior = new InverseGammaDistribution(sigmaPriorShape,
        sigmaPriorScale);
   
    final Vector phiMean1 = VectorFactory.getDefault().copyArray(new double[] {
        0d, 0.8d
    });
    final Matrix phiCov1 = MatrixFactory.getDefault().copyArray(new double[][] {
        {2d + 4d * sigmaPriorMean, 0d},
        { 0d, 4d * sigmaPriorMean}
    });
    final MultivariateGaussian phiPrior1 = new MultivariateGaussian(phiMean1, phiCov1);

    final Vector phiMean2 = VectorFactory.getDefault().copyArray(new double[] {
        0d, 0.1d
    });
    final Matrix phiCov2 = MatrixFactory.getDefault().copyArray(new double[][] {
        { 1d + 4d * sigmaPriorMean, 0d},
        { 0d, 4d * sigmaPriorMean}
    });
    final MultivariateGaussian phiPrior2 = new MultivariateGaussian(phiMean2, phiCov2);
   
    List<MultivariateGaussian> priorPhis = Lists.newArrayList(phiPrior1, phiPrior2);

    final HmmPlFilter<DlmHiddenMarkovModel, GaussianArHpTransitionState, Vector> wfFilter =
        new GaussianArHpHmmPLFilter(trueHmm1, sigmaPrior, priorPhis, random, true);

    final int K = 3;
    final int T = 200;
    final int N = 1000;

    /*
     * Note: replications are over the same set of simulated observations.
     */
    List<SimHmmObservedValue<Vector, Vector>> simulation = trueHmm1.sample(random, T);

    wfFilter.setNumParticles(N);
    wfFilter.setResampleOnly(false);

    log.info("rep\tt\tfilter.type\tmeasurement.type\tresample.type\tmeasurement");
View Full Code Here

            DiscreteSamplingUtil.sampleIndexFromProbabilities(
                this.rng, this.priorHmm.getClassMarginalProbabilities());

        final InverseGammaDistribution thisPriorInvScale = this.priorInvScale.clone();

        final DlmHiddenMarkovModel particlePriorHmm = this.priorHmm.clone();
        /*
         * In this model, covariance is the same across components;
         * the constant offset varies.
         * As well, we need to set/reset the kalman filters to adhere
         * to the intended model.
         */
        final List<MultivariateGaussian> thesePriorOffsets = Lists.newArrayList();
        final double invScaleSample = thisPriorInvScale.sample(this.rng);
        int k = 0;
        for (KalmanFilter kf : particlePriorHmm.getStateFilters()) {
          final MultivariateGaussian thisPriorOffset = priorOffsets.get(k).clone();
          thesePriorOffsets.add(thisPriorOffset);
          k++;

          final Vector systemSample = thisPriorOffset.sample(this.rng);
          final Vector offsetTerm = systemSample.subVector(0,
              systemSample.getDimensionality()/2 - 1);
          kf.getModel().setState(offsetTerm);
          kf.setCurrentInput(offsetTerm);

          final Matrix A = MatrixFactory.getDefault().createDiagonal(
              systemSample.subVector(
                  systemSample.getDimensionality()/2,
                  systemSample.getDimensionality() - 1));
          kf.getModel().setA(A);

          final Matrix offsetIdent = MatrixFactory.getDefault().createIdentity(
              systemSample.getDimensionality()/2, systemSample.getDimensionality()/2);
          kf.getModel().setB(offsetIdent);

          final Matrix measIdent = MatrixFactory.getDefault().createIdentity(
              kf.getModel().getOutputDimensionality(),
              kf.getModel().getOutputDimensionality());
          kf.setMeasurementCovariance(measIdent.scale(invScaleSample));

          final Matrix modelIdent = MatrixFactory.getDefault().createIdentity(
              kf.getModel().getStateDimensionality(),
              kf.getModel().getStateDimensionality());
          kf.setModelCovariance(modelIdent.scale(invScaleSample));
        }

        final KalmanFilter kf = Iterables.get(particlePriorHmm.getStateFilters(),
            sampledClass);
        final MultivariateGaussian priorState = kf.createInitialLearnedObject();
        final Vector priorStateSample = priorState.sample(this.rng);

        final GaussianArHpTransitionState particle =
View Full Code Here

    @Override
    public GaussianArHpTransitionState update(
      GaussianArHpTransitionState predState) {

      final MultivariateGaussian posteriorState = predState.getState().clone();
      final DlmHiddenMarkovModel newHmm = predState.getHmm().clone();
      KalmanFilter kf = Iterables.get(newHmm.getStateFilters(),
          predState.getClassId());
      kf.update(posteriorState, predState.getObservation().getObservedValue());


      /*
 
View Full Code Here

     */
    MultivariateGaussian priorPredictedState = prevState.getState().clone();
    KalmanFilter kf = Iterables.get(prevState.getHmm().getStateFilters(), predClass);
    kf.predict(priorPredictedState);
   
    final DlmHiddenMarkovModel newHmm = prevState.getHmm().clone();
    final InverseGammaDistribution invScaleSS = prevState.getInvScaleSS().clone();
    final List<MultivariateGaussian> psiSS =
        ObjectUtil.cloneSmartElementsAsArrayList(prevState.getPsiSS());

    final GaussianArHpTransitionState newTransState =
View Full Code Here

TOP

Related Classes of plm.hmm.DlmHiddenMarkovModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.