Skip to content

Commit

Permalink
log determinant directly and small const typo
Browse files Browse the repository at this point in the history
  • Loading branch information
athos00 committed Nov 19, 2024
1 parent 91a37b0 commit faf1ae2
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ApproximateTreeDataLikelihood(MaximizerWrtParameter maximizer) {
this.likelihood = maximizer.getLikelihood();
final GradientWrtParameterProvider gradient = maximizer.getGradient();
this.parameter = gradient.getParameter();
this.marginalLikelihoodConst = Math.log(2) - parameter.getDimension() / 2 *Math.log(Math.PI);
this.marginalLikelihoodConst = (parameter.getDimension() - 1) * Math.log(2 * Math.PI);
// todo: get Numerical Hessian.
if (gradient instanceof HessianWrtParameterProvider) {
this.hessianWrtParameterProvider = (HessianWrtParameterProvider) gradient;
Expand Down Expand Up @@ -139,14 +139,12 @@ public double[][] getHessianLogDensity() {

private void updateMarginalLikelihood() {
double[] diagonalHessian = hessianWrtParameterProvider.getDiagonalHessianLogDensity();
double diagonalDeterminant = 1;
double logDiagonalDeterminant = 0;
for (int i = 0; i < parameter.getDimension(); i++) {
diagonalDeterminant *= Math.abs(diagonalHessian[i]);
logDiagonalDeterminant += Math.log(Math.abs(diagonalHessian[i]));
}
// 2pi^{-k/2} * det(Sigma)^{-1/2} * likelihood(map) * prior(map)
// todo: eval posterior(map)
// todo: log likelihood
this.marginalLikelihood = marginalLikelihoodConst + 0.5 * Math.log(diagonalDeterminant) + likelihood.getLogLikelihood();
this.marginalLikelihood = marginalLikelihoodConst + 0.5 * logDiagonalDeterminant + likelihood.getLogLikelihood();
likelihoodKnown = true;
}

Expand Down

0 comments on commit faf1ae2

Please sign in to comment.