Package gov.sandia.cognition.statistics.distribution

Examples of gov.sandia.cognition.statistics.distribution.MultivariateGaussian


    });
    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);
View Full Code Here


    @Override
    public double computeLogLikelihood(
      GaussianArHpWfParticle transParticle,
      ObservedValue<Vector,?> observation) {

      final MultivariateGaussian priorPsi = transParticle.getPsiSS();
      final KalmanFilter kf = transParticle.getFilter();

      final int xDim = kf.getModel().getInputDimensionality();
      final Matrix H = MatrixFactory.getDefault().createMatrix(xDim, xDim * 2);
      H.setSubMatrix(0, 0, Ix);
      H.setSubMatrix(0, xDim,
          // x_{t-1}
          MatrixFactory.getDefault().createDiagonal(transParticle.getStateSample()));

      /*
       * Construct the measurement prior predictive likelihood
       * t_n (H*m^psi, d*C^psi/n)
       */
      final Vector mPriorPredMean = H.times(priorPsi.getMean());
      final Matrix mPriorPredCov = H.times(priorPsi.getCovariance()).times(H.transpose())
          .plus(Iy.scale(2d));

      // TODO FIXME
      final Matrix stPriorPredPrec = mPriorPredCov.inverse().scale(
          transParticle.getSigma2SS().getShape()/transParticle.getSigma2SS().getScale());
View Full Code Here

        final InverseGammaDistribution thisSigma2Prior = this.initialPriorSigma2.clone();
        final double sigma2Sample = thisSigma2Prior.sample(this.rng);

        final KalmanFilter thisKf = this.initialKf.clone();
        final MultivariateGaussian thisPsiPrior = initialPriorPsi.clone();
        // TODO FIXME use t-distribution
        final MultivariateGaussian thisPsiPriorSmpler = thisPsiPrior.clone();
        thisPsiPriorSmpler.getCovariance().scaleEquals(sigma2Sample);
        final Vector psiSample = thisPsiPriorSmpler.sample(this.rng);

        final Vector alphaTerm = psiSample.subVector(0,
            psiSample.getDimensionality()/2 - 1);
        thisKf.getModel().setState(alphaTerm);
        thisKf.setCurrentInput(alphaTerm);

        final Matrix betaTerm = MatrixFactory.getDefault().createDiagonal(
            psiSample.subVector(
                psiSample.getDimensionality()/2,
                psiSample.getDimensionality() - 1));
        thisKf.getModel().setA(betaTerm);

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

        final Matrix measIdent = Iy.clone();
        thisKf.setMeasurementCovariance(measIdent);

        final Matrix modelIdent = Ix.clone();
        thisKf.setModelCovariance(modelIdent);

        final MultivariateGaussian priorState = thisKf.createInitialLearnedObject();
        final MultivariateGaussian priorStateSmpler = thisKf.createInitialLearnedObject();
        priorStateSmpler.getCovariance().scaleEquals(sigma2Sample);
        final Vector priorStateSample = priorStateSmpler.sample(this.rng);


        final GaussianArHpWfParticle particle =
            new GaussianArHpWfParticle(thisKf,
                ObservedValue.<Vector>create(0, null), priorState,
View Full Code Here

    @Override
    public GaussianArHpWfParticle update(
      GaussianArHpWfParticle predState) {

      final MultivariateGaussian posteriorState = predState.getState().clone();
      final KalmanFilter kf = predState.getFilter().clone();

      /*
       * The following are the parameter learning updates;
       * they can be done off-line, but we'll do them now.
       * TODO FIXME check that the input/offset thing is working!
       */

      final int xDim = posteriorState.getInputDimensionality();
      final Matrix H = MatrixFactory.getDefault().createMatrix(xDim, xDim * 2);
      H.setSubMatrix(0, 0, Ix);
      H.setSubMatrix(0, xDim,
          // x_{t-1}
          MatrixFactory.getDefault().createDiagonal(predState.getStateSample()));

      final InverseGammaDistribution sigma2SS = predState.getSigma2SS().clone();
      // TODO FIXME matrix inverse!!
      final Matrix postStatePrec = posteriorState.getCovarianceInverse().scale(
          sigma2SS.getShape()/sigma2SS.getScale());
      MultivariateStudentTDistribution postStateMarginal = new MultivariateStudentTDistribution(
          sigma2SS.getShape(),
          posteriorState.getMean(), postStatePrec);
      final Vector postStateSample = postStateMarginal.sample(this.rng);
     
      final Vector psiPriorSmpl = predState.getPsiSample();
      // x_t
      final Vector xHdiff = postStateSample.minus(H.times(psiPriorSmpl));

      /*
       * 1. Update the sigma2 sufficient stats.
       */
      final double newN = sigma2SS.getShape() + 1d;
      final double d = sigma2SS.getScale() + xHdiff.dotProduct(xHdiff);
      sigma2SS.setScale(d);
      sigma2SS.setShape(newN);
     
      /*
       * 2. Update psi sufficient stats. (i.e. offset and AR(1)).
       *
       * Note that we divide out the previous scale param, since
       * we want to update A alone.
       * TODO FIXME inverse!  ewww.
       */
      final Matrix priorAInv = predState.getPsiSS().getCovarianceInverse();
      /*
       * TODO FIXME: we don't have a generalized outer product, so we're only
       * supporting the 1d case for now.
       */
      final Vector Hv = H.convertToVector();
      /*
       * TODO FIXME inverse!  ewww.
       */
      final Matrix postAInv = priorAInv.plus(Hv.outerProduct(Hv)).inverse();
      final Vector postPsiMean = postAInv.times(priorAInv.times(psiPriorSmpl).plus(
          H.transpose().times(postStateSample)));
      final MultivariateGaussian postPsi = predState.getPsiSS().clone();
      postPsi.setMean(postPsiMean);
      postPsi.setCovariance(postAInv);
     
      final double sigma2Smpl = sigma2SS.sample(this.rng);
      final GaussianArHpWfParticle postState =
          new GaussianArHpWfParticle(kf, predState.getObservation(),
              posteriorState, postStateSample,
View Full Code Here

  protected GaussianArHpWfParticle propagate(
      GaussianArHpWfParticle prevState, ObservedValue<Vector,?> data) {
    /*
     * Perform the filtering step
     */
    MultivariateGaussian priorPredictedState = prevState.getState().clone();
    final KalmanFilter kf = prevState.getFilter().clone();
    kf.predict(priorPredictedState);
   
    final InverseGammaDistribution scaleSS = prevState.getSigma2SS().clone();
    final MultivariateGaussian systemSS = prevState.getPsiSS().clone();

    final GaussianArHpWfParticle newTransState =
        new GaussianArHpWfParticle(prevState, kf,
            data, priorPredictedState, prevState.getStateSample(),
            scaleSS, systemSS, prevState.getSigma2Sample(), null);
View Full Code Here

    });
    final Matrix phiCov = MatrixFactory.getDefault().copyArray(new double[][] {
        {2d + 4d * sigmaPriorMean, 0d},
        { 0d, 4d * sigmaPriorMean}
    });
    final MultivariateGaussian phiPrior = new MultivariateGaussian(phiMean, phiCov);

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

View Full Code Here

          MatrixFactory.getDefault().copyArray(new double[][] {
              {0d}}),
          MatrixFactory.getDefault().copyArray(new double[][] {{0d}})   
        );
   
    final MultivariateGaussian trueInitialPrior = new MultivariateGaussian(
        VectorFactory.getDefault().copyValues(3.7d),
        MatrixFactory.getDefault().copyArray(new double[][] {
            {0d}}));
    final int T = 3000;
    final List<ObservedValue<Vector, Matrix>> observations = Lists.newArrayList();

    List<SimObservedValue<Vector, Matrix, Vector>> dlmSamples = DlmUtils.sampleDlm(
        rng, T, trueInitialPrior, initialFilter);
    int t = 0;
    for (SimObservedValue<Vector, Matrix, Vector> samplePair : dlmSamples) {
      final double ev1Upper = -Math.log(-Math.log(rng.nextDouble()));
      final double upperUtility = samplePair.getObservedValue().getElement(0) +
          ev1Upper;
      final double lowerUtility = -Math.log(-Math.log(rng.nextDouble()));
      final double obs = (upperUtility > lowerUtility) ? 1d : 0d;
      observations.add(
          SimObservedValue.<Vector, Matrix, LogitTrueState>create(
              t++,
              VectorFactory.getDefault().copyValues(obs),
              samplePair.getObservedData(),
              new LogitTrueState(samplePair.getTrueState(), upperUtility, ev1Upper, lowerUtility)));
    }

    /*
     * Create and initialize the PL filter
     */
    final MultivariateGaussian initialPrior = new MultivariateGaussian(
        VectorFactory.getDefault().copyValues(0d),
        MatrixFactory.getDefault().copyArray(new double[][] {
            {1000d}}));
    final Matrix F = MatrixFactory.getDefault().copyArray(new double[][] {
        {1d}});
View Full Code Here

    });
    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);
View Full Code Here

    });
    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);
View Full Code Here

          MatrixFactory.getDefault().copyArray(new double[][] {
              {0d}}),
          MatrixFactory.getDefault().copyArray(new double[][] {{0d}})   
        );
   
    final MultivariateGaussian trueInitialPrior = new MultivariateGaussian(
        VectorFactory.getDefault().copyValues(3.7d),
        MatrixFactory.getDefault().copyArray(new double[][] {
            {0d}}));
    final int N = 3000;
    final List<ObservedValue<Vector, Matrix>> observations = Lists.newArrayList();

    List<SimObservedValue<Vector, Matrix, Vector>> dlmSamples = DlmUtils.sampleDlm(
        rng, N, trueInitialPrior, initialFilter);
    for (SimObservedValue<Vector, Matrix, Vector> samplePair : dlmSamples) {
      final double ev1Upper = -Math.log(-Math.log(rng.nextDouble()));
      final double upperUtility = samplePair.getObservedValue().getElement(0) +
          ev1Upper;
      final double lowerUtility = -Math.log(-Math.log(rng.nextDouble()));
      final double obs = (upperUtility > lowerUtility) ? 1d : 0d;
      observations.add(
          SimObservedValue.<Vector, Matrix, LogitTrueState>create(
              VectorFactory.getDefault().copyValues(obs),
              samplePair.getObservedData(),
              new LogitTrueState(samplePair.getTrueState(), upperUtility, ev1Upper, lowerUtility)));
    }

    /*
     * Create and initialize the PL filter
     */
    final MultivariateGaussian initialPrior = new MultivariateGaussian(
        VectorFactory.getDefault().copyValues(0d),
        MatrixFactory.getDefault().copyArray(new double[][] {
            {1000d}}));
    final Matrix F = MatrixFactory.getDefault().copyArray(new double[][] {
        {1d}});
View Full Code Here

TOP

Related Classes of gov.sandia.cognition.statistics.distribution.MultivariateGaussian

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.