* @exception Exception if the estimator can't be computed
*/
protected UnivariateDensityEstimator getDensityEstimator(Instance instance, boolean print) throws Exception {
// Initialize estimator
UnivariateDensityEstimator e;
if (m_estimatorType == ESTIMATOR_KERNEL) {
e = new UnivariateKernelEstimator();
} else if (m_estimatorType == ESTIMATOR_NORMAL) {
e = new UnivariateNormalEstimator();
} else {
e = new UnivariateEqualFrequencyHistogramEstimator();
// Set the number of bins appropriately
((UnivariateEqualFrequencyHistogramEstimator)e).setNumBins(getNumBins());
// Initialize boundaries of equal frequency estimator
for (int i = 0; i < m_OriginalTargetValues.length; i++) {
e.addValue(m_OriginalTargetValues[i], 1.0);
}
// Construct estimator, then initialize statistics, so that only boundaries will be kept
((UnivariateEqualFrequencyHistogramEstimator)e).initializeStatistics();
// Now that boundaries have been determined, we only need to update the bin weights
((UnivariateEqualFrequencyHistogramEstimator)e).setUpdateWeightsOnly(true);
}
// Make sure structure of class attribute correct
Instance newInstance = (Instance)instance.copy();
newInstance.setDataset(m_DiscretizedHeader);
double [] probs = m_Classifier.distributionForInstance(newInstance);
// Add values to estimator
for (int i = 0; i < m_OriginalTargetValues.length; i++) {
e.addValue(m_OriginalTargetValues[i], probs[m_NewTargetValues[i]] *
m_OriginalTargetValues.length / m_ClassCounts[m_NewTargetValues[i]]);
}
// Return estimator
return e;