public void ConstructorTest4()
{
// Create a Inverse Wishart with the parameters
var invWishart = new InverseWishartDistribution(
// Degrees of freedom
degreesOfFreedom: 4,
// Scale parameter
inverseScale: new double[,]
{
{ 1.7, -0.2 },
{ -0.2, 5.3 },
}
);
// Common measures
double[] var = invWishart.Variance; // { -3.4, -10.6 }
double[,] cov = invWishart.Covariance; // see below
double[,] mmean = invWishart.MeanMatrix; // see below
// cov mean
// -5.78 -4.56 1.7 -0.2
// -4.56 -56.18 -0.2 5.3
// (the above matrix representations have been transcribed to text using)
// string scov = cov.ToString(DefaultMatrixFormatProvider.InvariantCulture);
// string smean = mmean.ToString(DefaultMatrixFormatProvider.InvariantCulture);
// For compatibility reasons, .Mean stores a flattened mean matrix
double[] mean = invWishart.Mean; // { 1.7, -0.2, -0.2, 5.3 }
// Probability density functions
double pdf = invWishart.ProbabilityDensityFunction(new double[,]
{
{ 5.2, 0.2 }, // 0.000029806281690351203
{ 0.2, 4.2 },
});
double lpdf = invWishart.LogProbabilityDensityFunction(new double[,]
{
{ 5.2, 0.2 }, // -10.420791391688828
{ 0.2, 4.2 },
});
Assert.AreEqual(pdf, System.Math.Exp(lpdf), 1e-6);
Assert.AreEqual(1.7, mean[0]);
Assert.AreEqual(-0.2, mean[1]);
Assert.AreEqual(-0.2, mean[2]);
Assert.AreEqual(5.3, mean[3]);
Assert.AreEqual(-3.4, var[0]);
Assert.AreEqual(-10.6, var[1]);
Assert.AreEqual(-5.7799999999999994, cov[0, 0]);
Assert.AreEqual(-4.5649999999999995, cov[0, 1]);
Assert.AreEqual(-4.5649999999999995, cov[1, 0]);
Assert.AreEqual(-56.18, cov[1, 1]);
Assert.AreEqual(0.000029806281690351203, pdf);
Assert.AreEqual(-10.420791391688828, lpdf);
}