Package gov.sandia.cognition.math.matrix

Examples of gov.sandia.cognition.math.matrix.Vector


      for (final ICombinatoricsVector<Integer> combination : gen) {
 
        HmmTransitionState<T, StandardHMM<T>> currentState = null;
        double logWeightOfState = 0d;
        for (int i = 0; i < combination.getSize(); i++) {
          final Vector smoothedProbsAtTime =
              Iterables.get(jointProbs, i);
          final int stateAtTime = combination.getVector().get(i);
          // TODO assuming it's normalized, is that true?
          final double logWeightAtTime =
              Math.log(smoothedProbsAtTime.getElement(stateAtTime));
 
          logWeightOfState += logWeightAtTime;
          if (currentState == null) {
            currentState =
                new HmmTransitionState<T, StandardHMM<T>>(hmm, stateAtTime,
View Full Code Here


      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 betaSample =
          predictivePrior.sample(getRandom());
//          predictivePrior.getMean();
      final double predPriorObsMean =
            F.times(betaSample).getElement(0);

      final int particleCount;
      if (particleEntry.getValue() instanceof MutableDoubleCount) {
        particleCount = ((MutableDoubleCount)particleEntry.getValue()).count;
      } else {
        particleCount = 1;
      }
      for (int p = 0; p < particleCount; p++) {
        final double dSampledAugResponse = sampleAugResponse(predPriorObsMean, isOne);

        Vector sampledAugResponse = VectorFactory.getDefault().copyValues(dSampledAugResponse);

        for (int j = 0; j < 10; j++) {
          final LogitMixParticle predictiveParticle = particle.clone();
          predictiveParticle.setPreviousParticle(particle);
          predictiveParticle.setBetaSample(betaSample);
View Full Code Here

    // TODO we should've already set this, so it might be redundant.
    filter.setMeasurementCovariance(
        MatrixFactory.getDefault().copyArray(new double[][] {{
          evComponent.getVariance()}}));

    final Vector sampledAugResponse = priorParticle.getAugResponseSample();
    final Vector diffAugResponse =
        sampledAugResponse.minus(VectorFactory.getDefault().copyArray(
        new double[] {
            evComponent.getMean().doubleValue()
            }));
    final MultivariateGaussian posteriorState = updatedParticle.getLinearState().clone();
View Full Code Here

  @Override
  public List<SimHmmObservedValue<ResponseType, Integer>> sample(
      Random random, int numSamples) {

    List<SimHmmObservedValue<ResponseType, Integer>> results = Lists.newArrayList();
    Vector p = hmm.getInitialProbability();
    int state = -1;
    for (int n = 0; n < numSamples; n++) {
      double value = random.nextDouble();
      state = -1;
      while (value > 0.0) {
        state++;
        value -= p.getElement(state);
      }
 
      ResponseType sample =
          CollectionUtil.getElement(hmm.getEmissionFunctions(),
              state).sample(random);
View Full Code Here

    @Override
    public double computeLogLikelihood(LassoRegressionDistribution particle,
        ObservedValue<Vector, Matrix> observation) {


      final Vector y = observation.getObservedValue();
      /*
       * Now, we compute the predictive dist, so that we can evaluate the likelihood.
       */
      final Matrix X = observation.getObservedData();
      final Vector priorPredObsMean = X.times(particle.getPriorBeta().getMean());
      Matrix priorPredObsCov = X.times(
          particle.getPriorBeta().getCovariance())
          .times(X.transpose()).plus(particle.augLassoSample);
      priorPredObsCov.times(particle.priorObsCovSample);

View Full Code Here

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

    // TODO we should've already set this, so it might be redundant.
    filter.setMeasurementCovariance(
        MatrixFactory.getDefault().copyArray(new double[][] {{
          evComponent.getVariance() + partComponent.getVariance()}}));

    final Vector sampledAugResponse =
        VectorFactory.getDefault().copyValues(
            dsampledAugResponse
            - evComponent.getMean().doubleValue()
            - partComponent.getMean().doubleValue());
View Full Code Here

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

        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

      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);

      final Vector smplOffsetTerm = postPhiSmpl.subVector(0,
              postPhiSmpl.getDimensionality()/2 - 1);
      kf.getModel().setState(smplOffsetTerm);
      kf.setCurrentInput(smplOffsetTerm);
 
      final GaussianArHpTransitionState postState =
View Full Code Here

TOP

Related Classes of gov.sandia.cognition.math.matrix.Vector

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.