public double logDensityForInstance(Instance instance) throws Exception {
  double[] a=logJointDensitiesForInstance(instance);
  double max=a[Utils.maxIndex(a)];
  double sum=0.0;
  for (int i=0; i < a.length; i++) {
    sum+=Math.exp(a[i] - max);
  }
  return max + Math.log(sum);
}

public double logDensityForInstance ( Instance instance ) throws Exception { double [ ] a = logJointDensitiesForInstance ( instance ) ; double max = a [ Utils . maxIndex ( a ) ] ; double sum = 0.0 ; for ( int i = 0 ; i < a . length ; i ++ ) { sum += Math . exp ( a [ i ] - max ) ; } return max + Math . log ( sum ) ; }
computes the density for a given instance .
