Package gov.sandia.cognition.statistics.distribution

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


      final DataDistribution<LogitMixParticle> initialParticles =
          CountedDataDistribution.create(true);
      for (int i = 0; i < numParticles; i++) {
       
        final MultivariateGaussian initialPriorState = initialPrior.clone();
        final KalmanFilter kf = this.initialFilter.clone();
        final int componentId = this.rng.nextInt(10);
        final UnivariateGaussian evDist = this.evDistribution.
            getDistributions().get(componentId);
       
View Full Code Here


    @Override
    public double computeLogLikelihood(
      GaussianArHpTransitionState transState,
      ObservedValue<Vector,Void> observation) {

      final MultivariateGaussian priorPredState = transState.getState();
      final KalmanFilter kf = Iterables.get(transState.getHmm().getStateFilters(),
          transState.getClassId());
      /*
       * 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());

      return logCt;
    }
View Full Code Here

         */
        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 =
            new GaussianArHpTransitionState(particlePriorHmm, sampledClass,
                ObservedValue.<Vector>create(0, null), priorState,
                priorStateSample,
View Full Code Here

                this.kf.getModel().getA(),
                this.kf.getModel().getB(),
                this.kf.getModel().getC()),
            this.kf.getModelCovariance(),
            this.kf.getMeasurementCovariance());
    clone.state = new MultivariateGaussian(
        this.state.getMean(), this.state.getCovariance());
    clone.stateSample = this.stateSample.clone();
    clone.logWeight = this.logWeight;
    clone.obs = this.obs;
    clone.prevParticle = this.prevParticle;
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());


      /*
       * 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 InverseGammaDistribution invScaleSS = predState.getInvScaleSS().clone();
      final List<MultivariateGaussian> systemOffsetsSS =
          ObjectUtil.cloneSmartElementsAsArrayList(predState.getPsiSS());

      final int xDim = posteriorState.getInputDimensionality();
      final Matrix Ij = MatrixFactory.getDefault().createIdentity(xDim, xDim);
      final Matrix H = MatrixFactory.getDefault().createMatrix(xDim, xDim * 2);
      H.setSubMatrix(0, 0, Ij);
      H.setSubMatrix(0, xDim, MatrixFactory.getDefault().createDiagonal(predState.getStateSample()));
      final Vector postStateSample = posteriorState.sample(this.rng);
      final MultivariateGaussian priorPhi = predState.getPsiSS().get(predState.getClassId());
      final Vector phiPriorSmpl = priorPhi.sample(this.rng);
      final Vector xHdiff = postStateSample.minus(H.times(phiPriorSmpl));

      final double newN = invScaleSS.getShape() + 1d;
      final double d = invScaleSS.getScale() + xHdiff.dotProduct(xHdiff);
     
      invScaleSS.setScale(d);
      invScaleSS.setShape(newN);
     
      // FIXME TODO: crappy sampler
      final double newInvScaleSmpl = invScaleSS.sample(this.rng);
     
      /*
       * Update state and measurement covariances, which
       * have a strict dependency in this model (equality).
       */
      kf.setMeasurementCovariance(MatrixFactory.getDefault().createDiagonal(
          VectorFactory.getDefault().createVector(kf.getModel().getOutputDimensionality(),
              newInvScaleSmpl)));

      kf.setModelCovariance(MatrixFactory.getDefault().createDiagonal(
          VectorFactory.getDefault().createVector(kf.getModel().getStateDimensionality(),
              newInvScaleSmpl)));

      /*
       * Update offset and AR(1) prior(s).
       * Note that we divide out the previous inv scale param, since
       * we want to update A alone.
       */
      final Matrix priorAInv = priorPhi.getCovariance().scale(1d/predState.getInvScaleSample()).inverse();
      /*
       * 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();
      final Matrix postAInv = priorAInv.plus(Hv.outerProduct(Hv)).inverse();
      // TODO FIXME: ewww.  inverse.
      final Vector postPhiMean = postAInv.times(priorAInv.times(phiPriorSmpl).plus(
          H.transpose().times(postStateSample)));
      final MultivariateGaussian postPhi = systemOffsetsSS.get(predState.getClassId());
      postPhi.setMean(postPhiMean);
      postPhi.setCovariance(postAInv.scale(newInvScaleSmpl));
     
      final Vector postPhiSmpl = postPhi.sample(this.rng);
      final Matrix smplArTerms = MatrixFactory.getDefault().createDiagonal(
          postPhiSmpl.subVector(
              postPhiSmpl.getDimensionality()/2,
              postPhiSmpl.getDimensionality() - 1));
      kf.getModel().setA(smplArTerms);
View Full Code Here

    @Override
    public GaussianEnsParticle update(
      GaussianEnsParticle predState) {

      final MultivariateGaussian posteriorState = predState.getState().clone();
     
      return null;
    }
View Full Code Here

                this.regressionFilter.getModel().getB(),
                this.regressionFilter.getModel().getC()),
            this.regressionFilter.getModelCovariance(),
            this.regressionFilter.getMeasurementCovariance());
    // same here
    clone.linearState = new MultivariateGaussian(
        this.linearState.getMean(), this.linearState.getCovariance());
    clone.augResponseSample = this.augResponseSample;
    clone.priorPredMean = this.priorPredMean;
    clone.priorPredCov = this.priorPredCov;
    clone.compLikelihoods = this.compLikelihoods;
View Full Code Here

            - evComponent.getMean().doubleValue()
            - partComponent.getMean().doubleValue());

    updatedParticle.setAugResponseSample(sampledAugResponse);

    final MultivariateGaussian posteriorState = updatedParticle.getLinearState().clone();
    filter.update(posteriorState, sampledAugResponse);

    updatedParticle.setLinearState(posteriorState);
   
    return updatedParticle;
View Full Code Here

      final DataDistribution<LogitMixParticle> initialParticles =
          CountedDataDistribution.create(true);
      for (int i = 0; i < numParticles; i++) {
       
        final MultivariateGaussian initialPriorState = initialPrior.clone();
        final KalmanFilter kf = this.initialFilter.clone();
        final int componentId = this.rng.nextInt(10);
        final UnivariateGaussian evDist = this.evDistribution.
            getDistributions().get(componentId);
       
View Full Code Here

    public void run() {
      double sourceTotalLogLikelihood = Double.NEGATIVE_INFINITY;

      final LogitMixParticle particle = particleEntry.getKey();

      final MultivariateGaussian predictivePrior = particle.getLinearState().clone();
      KalmanFilter kf = particle.getRegressionFilter();
      final Matrix G = kf.getModel().getA();
      final Matrix F = data.getObservedData();
      predictivePrior.setMean(G.times(predictivePrior.getMean()));
      predictivePrior.setCovariance(
          G.times(predictivePrior.getCovariance()).times(G.transpose())
            .plus(kf.getModelCovariance()));
      final Vector betaMean = predictivePrior.getMean();

      final int particleCount;
      if (particleEntry.getValue() instanceof MutableDoubleCount) {
        particleCount = ((MutableDoubleCount)particleEntry.getValue()).count;
      } else {
        particleCount = 1;
      }
      for (int p = 0; p < particleCount; p++) {
        for (int j = 0; j < 10; j++) {
          final LogitMixParticle predictiveParticle =
              particle.clone();

          predictiveParticle.setPreviousParticle(particle);
          predictiveParticle.setBetaSample(betaMean);
          predictiveParticle.setLinearState(predictivePrior);

          final UnivariateGaussian componentDist =
              filter.evDistribution.getDistributions().get(j);

          predictiveParticle.setEVcomponent(componentDist);
         
          /*
           * Update the observed data for the regression component.
           */
          predictiveParticle.getRegressionFilter().getModel().setC(F);

          final Matrix compVar = MatrixFactory.getDefault().copyArray(
              new double[][] {{componentDist.getVariance()}});
          predictiveParticle.getRegressionFilter().setMeasurementCovariance(compVar);
         
          final double compPredPriorObsMean =
               F.times(betaMean).getElement(0)
               + componentDist.getMean();
          final double compPredPriorObsCov =
               F.times(predictivePrior.getCovariance()).times(F.transpose()).getElement(0, 0)
               + componentDist.getVariance();
          predictiveParticle.setPriorPredMean(compPredPriorObsMean);
          predictiveParticle.setPriorPredCov(compPredPriorObsCov);

          final double logLikelihood =
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.