/** * Calculates the class membership probabilities for the given test * instance. * * @param instance the instance to be classified * @return predicted class probability distribution * @throws Exception if there is a problem generating the prediction */ public double [] distributionForInstance(Instance instance) throws Exception { double[] probOfClassGivenDoc = new double[m_numClasses]; //calculate the array of log(Pr[D|C]) double[] logDocGivenClass = new double[m_numClasses]; for (int h = 0; h < m_numClasses; h++) { logDocGivenClass[h] = probOfDocGivenClass(instance, h); } double max = logDocGivenClass[Utils.maxIndex(logDocGivenClass)]; for (int i = 0; i < m_numClasses; i++) { probOfClassGivenDoc[i] = Math.exp(logDocGivenClass[i] - max) * m_probOfClass[i]; } Utils.normalize(probOfClassGivenDoc); return probOfClassGivenDoc; }
/** * Calculates the class membership probabilities for the given test * instance. * * @param instance the instance to be classified * @return predicted class probability distribution * @throws Exception if there is a problem generating the prediction */ public double [] distributionForInstance(Instance instance) throws Exception { double[] probOfClassGivenDoc = new double[m_numClasses]; //calculate the array of log(Pr[D|C]) double[] logDocGivenClass = new double[m_numClasses]; for (int h = 0; h < m_numClasses; h++) { logDocGivenClass[h] = probOfDocGivenClass(instance, h); } double max = logDocGivenClass[Utils.maxIndex(logDocGivenClass)]; for (int i = 0; i < m_numClasses; i++) { probOfClassGivenDoc[i] = Math.exp(logDocGivenClass[i] - max) * m_probOfClass[i]; } Utils.normalize(probOfClassGivenDoc); return probOfClassGivenDoc; }