/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="ProductWishartOp"]/message_doc[@name="ProductAverageLogarithm(Wishart, Gamma, Wishart)"]/*'/> public static Wishart ProductAverageLogarithm([SkipIfUniform] Wishart A, [SkipIfUniform] Gamma B, Wishart result) { if (B.IsPointMass) { return(ProductAverageLogarithm(A, B.Point, result)); } // E[x] = E[a]*E[b] // E[log(x)] = E[log(a)]+E[log(b)] PositiveDefiniteMatrix m = new PositiveDefiniteMatrix(A.Dimension, A.Dimension); A.GetMean(m); m.Scale(B.GetMean()); double meanLogDet = A.Dimension * B.GetMeanLog() + A.GetMeanLogDeterminant(); if (m.LogDeterminant() < meanLogDet) { throw new MatrixSingularException(m); } return(Wishart.FromMeanAndMeanLogDeterminant(m, meanLogDet, result)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="ProductWishartOp"]/message_doc[@name="ProductAverageConditional(Wishart, PositiveDefiniteMatrix, Gamma, Gamma, Wishart)"]/*'/> public static Wishart ProductAverageConditional(Wishart Product, PositiveDefiniteMatrix A, [SkipIfUniform] Gamma B, Gamma to_B, Wishart result) { if (B.IsPointMass) { return(ProductAverageConditional(A, B.Point, result)); } Gamma Bpost = B * to_B; // E[x] = a*E[b] // E[logdet(x)] = logdet(a) + d*E[log(b)] PositiveDefiniteMatrix m = new PositiveDefiniteMatrix(A.Rows, A.Cols); m.SetTo(A); m.Scale(Bpost.GetMean()); double meanLogDet = A.Rows * Bpost.GetMeanLog() + A.LogDeterminant(); if (m.LogDeterminant() < meanLogDet) { throw new MatrixSingularException(m); } Wishart.FromMeanAndMeanLogDeterminant(m, meanLogDet, result); result.SetToRatio(result, Product); return(result); }