// build the Map for the estimatedDistributions
m_estimatedDistributions = new HashMap(m_train.numInstances() / 2);
// cycle through all instances
Iterator it = new EnumerationIterator(m_train.enumerateInstances());
while (it.hasNext() == true) {
Instance instance = (Instance) it.next();
Coordinates c = new Coordinates(instance);
// get DiscreteEstimator from the map
DiscreteEstimator df =
(DiscreteEstimator) m_estimatedDistributions.get(c);
// if no DiscreteEstimator is present in the map, create one
if (df == null) {
df = new DiscreteEstimator(instances.numClasses(), 0);
}
df.addValue(instance.classValue(), instance.weight()); // update
m_estimatedDistributions.put(c, df); // put back in map
}
// Create the attributes for m_baseMin and m_baseMax.
// These are identical to those of m_train, except that the
// class is set to 'numeric'
// The class attribute is moved to the back
FastVector newAtts = new FastVector(m_train.numAttributes());
Attribute classAttribute = null;
for (int i = 0; i < m_train.numAttributes(); i++) {
Attribute att = m_train.attribute(i);
if (i != m_train.classIndex()) {
newAtts.addElement(att.copy());
} else {
classAttribute = new Attribute(att.name()); //numeric attribute
}
}
newAtts.addElement(classAttribute);
// original training instances are replaced by an empty set
// of instances
m_train = new Instances(m_train.relationName(), newAtts,
m_estimatedDistributions.size());
m_train.setClassIndex(m_train.numAttributes() - 1);
// We cycle through the map of estimatedDistributions and
// create one Instance for each entry in the map, with
// a class value that is calculated from the distribution of
// the class values
it = m_estimatedDistributions.keySet().iterator();
while(it.hasNext()) {
// XXX attValues must be here, otherwise things go wrong
double[] attValues = new double[m_train.numAttributes()];
Coordinates cc = (Coordinates) it.next();
DiscreteEstimator df =
(DiscreteEstimator) m_estimatedDistributions.get(cc);
cc.getValues(attValues);
switch(m_atype) {
case AT_MEAN: