/** * Returns the cluster probability distribution for an instance. * * @param instance the instance to be clustered * @return the probability distribution * @throws Exception if computation fails */ public double[] distributionForInstance(Instance instance) throws Exception { return Utils.logs2probs(logJointDensitiesForInstance(instance)); }
/** * Returns the cluster probability distribution for an instance. * * @param instance the instance to be clustered * @return the probability distribution * @throws Exception if computation fails */ public double[] distributionForInstance(Instance instance) throws Exception { return Utils.logs2probs(logJointDensitiesForInstance(instance)); }
/** * Computes the density for a given instance. * * @param instance the instance to compute the density for * @return the density. * @exception Exception if the density could not be computed successfully */ 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. * * @param instance the instance to compute the density for * @return the density. * @exception Exception if the density could not be computed successfully */ 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); }