/*
* Create a mixture distribution to fit.
*/
final double[] trueComponentWeights = new double[] {0.1d, 0.5d, 0.1d, 0.2d, 0.1d};
final List<MultivariateGaussian> trueComponentModels = Lists.newArrayList();
trueComponentModels.add(new MultivariateGaussian(VectorFactory.getDenseDefault().copyArray(
new double[] {0d, 0d}), MatrixFactory.getDenseDefault().copyArray(
new double[][] { {100d, 0d}, {0d, 100d}})));
trueComponentModels.add(new MultivariateGaussian(VectorFactory.getDenseDefault().copyArray(
new double[] {100d, 1d}), MatrixFactory.getDenseDefault().copyArray(
new double[][] { {100d, 0d}, {0d, 100d}})));
trueComponentModels.add(new MultivariateGaussian(VectorFactory.getDenseDefault().copyArray(
new double[] {10d, -10d}), MatrixFactory.getDenseDefault().copyArray(
new double[][] { {100d, 0d}, {0d, 100d}})));
trueComponentModels.add(new MultivariateGaussian(VectorFactory.getDenseDefault().copyArray(
new double[] {1d, -200d}), MatrixFactory.getDenseDefault().copyArray(
new double[][] { {10d, 0d}, {0d, 10d}})));
trueComponentModels.add(new MultivariateGaussian(VectorFactory.getDenseDefault().copyArray(
new double[] {50d, -50d}), MatrixFactory.getDenseDefault().copyArray(
new double[][] { {20d, 0d}, {0d, 20d}})));
final MultivariateMixtureDensityModel<MultivariateGaussian> trueMixture =
new MultivariateMixtureDensityModel<MultivariateGaussian>(trueComponentModels,
trueComponentWeights);
final Random rng = new Random(829351983l);
/*
* Sample a lot of test data to fit against. TODO For a proper study, we would randomize subsets
* of this data and fit against those.
*/
final List<Vector> observations = trueMixture.sample(rng, 10000);
/*
* Instantiate PL filter by first providing prior parameters/distributions. We start by creating
* a prior conjugate centering distribution (which is a Normal Inverse Wishart), then we provide
* the Dirichlet Process prior parameters (group counts and concentration parameter).
*/
final int centeringCovDof = 2 + 2;
final Matrix centeringCovPriorMean =
MatrixFactory.getDenseDefault().copyArray(new double[][] { {1000d, 0d}, {0d, 1000d}});
final InverseWishartDistribution centeringCovariancePrior =
new InverseWishartDistribution(centeringCovPriorMean.scale(centeringCovDof
- centeringCovPriorMean.getNumColumns() - 1d), centeringCovDof);
final MultivariateGaussian centeringMeanPrior =
new MultivariateGaussian(VectorFactory.getDenseDefault().copyArray(new double[] {0d, 0d}),
centeringCovariancePrior.getMean());
final double centeringCovDivisor = 0.25d;
final NormalInverseWishartDistribution centeringPrior =
new NormalInverseWishartDistribution(centeringMeanPrior, centeringCovariancePrior,
centeringCovDivisor);