* Propagate
*/
final DataDistribution<PolyaGammaLogitDistribution> updatedDist =
new DefaultDataDistribution<PolyaGammaLogitDistribution>();
for (final PolyaGammaLogitDistribution particle : resampledParticles) {
final MultivariateGaussian augResponseDist = particle.getAugmentedResponseDistribution();
final MultivariateGaussian updatedBetaMean = particle.getPriorBeta().clone();
final List<Double> lambdaSamples =
new ExponentialDistribution(2).sample(random, updatedBetaMean.getInputDimensionality());
final Matrix lambdaSamplesMatrix =
MatrixFactory.getDenseDefault().createDiagonal(
VectorFactory.getDenseDefault().copyValues(lambdaSamples));
/*
* To perform the following updates, we need smoothed joint samples of the previous and
* current states (beta and the global mean), i.e. a draw from (x_t, x_{t-1} | y_t). FIXME XXX
* The above isn't currently being done
*/
final MultivariateGaussian priorBetaSmoothedDist = getSmoothedPriorDist(particle.getPriorBeta(),
augResponseDist, observation, particle.getPriorPredictiveMean());
final Vector priorBetaSmoothedSample = priorBetaSmoothedDist.sample(random);
final MultivariateGaussian postBetaSmoothedDist = getSmoothedPostDist(particle.getPriorBeta(),
augResponseDist, observation, particle.getPriorPredictiveMean());
final Vector postBetaSmoothedSample = postBetaSmoothedDist.sample(random);
final Vector priorGlobalMeanSample = particle.getPriorBeta().getMean();
final Vector postGlobalMeanSample = particle.getPriorBeta().sample(random);
/*
* Perform the actual Gaussian Bayes update. FIXME This is a very poor implementation.
*/
mvGaussianBayesUpdate(augResponseDist, priorGlobalMeanSample,
updatedBetaMean, observation.getObservedData());
final Vector betaMeanError = postBetaSmoothedSample.minus(priorBetaSmoothedSample);
final ScaledInverseGammaCovDistribution updatedBetaCov = particle.getPriorBetaCov().clone();
updateCovariancePrior(updatedBetaCov, betaMeanError);
final Matrix betaCovSmpl = updatedBetaCov.sample(random);
Preconditions.checkState(betaCovSmpl.getElement(0, 0) >= 0d);
updatedBetaMean.setCovariance(lambdaSamplesMatrix.times(betaCovSmpl
.times(updatedBetaMean.getCovariance())));
/*
* Now, do the above for the the global mean term.
*/
final MultivariateGaussian updatedGlobalMean =
particle.getPriorBeta().times(particle.getAugmentedResponseDistribution());
mvGaussianBayesUpdate(augResponseDist,
observation.getObservedData().times(priorBetaSmoothedSample), updatedGlobalMean,
MatrixFactory.getDenseDefault().createIdentity(
augResponseDist.getInputDimensionality(), augResponseDist.getInputDimensionality()));
final Vector globalMeanError = postGlobalMeanSample.minus(priorGlobalMeanSample);
final ScaledInverseGammaCovDistribution updatedGlobalMeanCov =
particle.getPriorBetaCov().clone();
updateCovariancePrior(updatedGlobalMeanCov, globalMeanError);
final Matrix globalMeanCovSmpl = updatedGlobalMeanCov.sample(random)
.times(updatedGlobalMean.getCovariance());
Preconditions.checkState(globalMeanCovSmpl.getElement(0, 0) > 0d);
updatedGlobalMean.setCovariance(globalMeanCovSmpl);
final PolyaGammaLogitDistribution updatedParticle =
new PolyaGammaLogitDistribution(updatedGlobalMean, updatedGlobalMeanCov);
updatedDist.increment(updatedParticle);