Package gov.sandia.cognition.statistics.bayesian

Examples of gov.sandia.cognition.statistics.bayesian.KalmanFilter


    LinearDynamicalSystem model2 = new LinearDynamicalSystem(
        MatrixFactory.getDefault().copyArray(new double[][] {{0.9d}}),
        MatrixFactory.getDefault().copyArray(new double[][] {{1}}),
        MatrixFactory.getDefault().copyArray(new double[][] {{1}})
      );
    KalmanFilter trueKf1 = new KalmanFilter(model1, modelCovariance1, measurementCovariance);
    KalmanFilter trueKf2 = new KalmanFilter(model2, modelCovariance2, measurementCovariance);

    final UnivariateGaussian prior = new UnivariateGaussian(0d, sigma_y2);
    final UnivariateGaussian s1Likelihood = prior;
    final UnivariateGaussian s2Likelihood = s1Likelihood;
   
View Full Code Here


    LinearDynamicalSystem model2 = new LinearDynamicalSystem(
        MatrixFactory.getDefault().copyArray(new double[][] {{truePsis.get(1).getElement(1)}}),
        MatrixFactory.getDefault().copyArray(new double[][] {{1d}}),
        MatrixFactory.getDefault().copyArray(new double[][] {{1d}})
      );
    KalmanFilter trueKf1 = new KalmanFilter(model1, modelCovariance1, measurementCovariance);
    trueKf1.setCurrentInput(VectorFactory.getDefault().copyValues(truePsis.get(0).getElement(0)));
    KalmanFilter trueKf2 = new KalmanFilter(model2, modelCovariance2, measurementCovariance);
    trueKf2.setCurrentInput(VectorFactory.getDefault().copyValues(truePsis.get(1).getElement(0)));
   
    Vector initialClassProbs = VectorFactory.getDefault()
            .copyArray(new double[] { 0.7d, 0.3d });
    Matrix classTransProbs = MatrixFactory.getDefault().copyArray(
                new double[][] { { 0.7d, 0.7d },
View Full Code Here

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

      for (int i = 0; i < numParticles; i++) {

        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 =
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!
View Full Code Here

      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 =
View Full Code Here

    public double computeLogLikelihood(
      GaussianArHpWfParticle transState,
      ObservedValue<Vector,?> observation) {

      final MultivariateGaussian priorPredState = transState.getState();
      final KalmanFilter kf = transState.getFilter();
      /*
       * Construct the measurement prior predictive likelihood
       */
      final Vector mPriorPredMean = kf.getModel().getC().times(priorPredState.getMean());
      final Matrix mPriorPredCov = kf.getModel().getC().times(priorPredState.getCovariance())
          .times(kf.getModel().getC().transpose())
          .plus(kf.getMeasurementCovariance());
      final MultivariateGaussian mPriorPredDist = new MultivariateGaussian(
          mPriorPredMean, mPriorPredCov);

      final double logCt = mPriorPredDist.getProbabilityFunction().logEvaluate(
          observation.getObservedValue());
View Full Code Here

          CountedDataDistribution.create(numParticles, true);
      for (int i = 0; i < numParticles; i++) {

        final InverseGammaDistribution thisPriorScale = this.initialPriorSigma2.clone();

        final KalmanFilter thisKf = this.initialKf.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 double scaleSample = thisPriorScale.sample(this.rng);

        final MultivariateGaussian thisPriorOffset = initialPriorPsi.clone();

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

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

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

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

        final Matrix modelIdent = MatrixFactory.getDefault().createIdentity(
            thisKf.getModel().getStateDimensionality(),
            thisKf.getModel().getStateDimensionality());
        thisKf.setModelCovariance(modelIdent.scale(scaleSample));

        final MultivariateGaussian priorState = thisKf.createInitialLearnedObject();
        final Vector priorStateSample = priorState.sample(this.rng);

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

    LinearDynamicalSystem dlm = new LinearDynamicalSystem(
        MatrixFactory.getDefault().copyArray(new double[][] {{truePsi.getElement(1)}}),
        MatrixFactory.getDefault().copyArray(new double[][] {{1d}}),
        MatrixFactory.getDefault().copyArray(new double[][] {{1d}})
      );
    KalmanFilter trueKf = new KalmanFilter(dlm, modelCovariance, measurementCovariance);
    trueKf.setCurrentInput(VectorFactory.getDefault().copyValues(truePsi.getElement(0)));
   
    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 phiMean = VectorFactory.getDefault().copyArray(new double[] {
        0d, 0.8d
    });
    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;

    final GaussianArHpWfPlFilter wfFilter =
        new GaussianArHpWfPlFilter(trueKf, sigmaPrior, phiPrior, random, K, true);

    /*
     * Note: replications are over the same set of simulated observations.
     */
    List<SimObservedValue<Vector, Matrix, Vector>> simulations = DlmUtils.sampleDlm(
        random, T, trueKf.createInitialLearnedObject(), trueKf);

    wfFilter.setNumParticles(N);

//    log.info("rep\tt\tfilter.type\tmeasurement.type\tresample.type\tmeasurement");

View Full Code Here

    LinearDynamicalSystem model2 = new LinearDynamicalSystem(
        MatrixFactory.getDefault().copyArray(new double[][] {{0.9d}}),
        MatrixFactory.getDefault().copyArray(new double[][] {{1}}),
        MatrixFactory.getDefault().copyArray(new double[][] {{1}})
      );
    KalmanFilter trueKf1 = new KalmanFilter(model1, modelCovariance1, measurementCovariance);
    KalmanFilter trueKf2 = new KalmanFilter(model2, modelCovariance2, measurementCovariance);

    final UnivariateGaussian prior = new UnivariateGaussian(0d, sigma_y2);
    final UnivariateGaussian s1Likelihood = prior;
    final UnivariateGaussian s2Likelihood = s1Likelihood;
   
View Full Code Here

TOP

Related Classes of gov.sandia.cognition.statistics.bayesian.KalmanFilter

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.