@Override public double sumOfWeights() { return super.sumOfWeights(); }
/** * Tells the panel to use a new set of instances. * * @param inst a set of Instances */ public void setInstances(Instances inst) { m_Instances = inst; m_RelationNameLab.setText(m_Instances.relationName()); m_RelationNameLab.setToolTipText(m_Instances.relationName()); m_NumInstancesLab .setText("" + ((m_showZeroInstancesAsUnknown && m_Instances.numInstances() == 0) ? "?" : "" + m_Instances.numInstances())); m_NumAttributesLab.setText("" + m_Instances.numAttributes()); m_sumOfWeightsLab .setText("" + ((m_showZeroInstancesAsUnknown && m_Instances.numInstances() == 0) ? "?" : "" + Utils.doubleToString(m_Instances.sumOfWeights(), 3))); }
/** * Tells the panel to use a new set of instances. * * @param inst a set of Instances */ public void setInstances(Instances inst) { m_Instances = inst; m_RelationNameLab.setText(m_Instances.relationName()); m_RelationNameLab.setToolTipText(m_Instances.relationName()); m_NumInstancesLab .setText("" + ((m_showZeroInstancesAsUnknown && m_Instances.numInstances() == 0) ? "?" : "" + m_Instances.numInstances())); m_NumAttributesLab.setText("" + m_Instances.numAttributes()); m_sumOfWeightsLab .setText("" + ((m_showZeroInstancesAsUnknown && m_Instances.numInstances() == 0) ? "?" : "" + Utils.doubleToString(m_Instances.sumOfWeights(), 3))); }
/** * Private function to compute the squared error of the specified data and the * specified mean * * @param data the data in question * @param mean the specified mean * @return the default mean-squared error */ private double meanSquaredError(Instances data, double mean) { if (Utils.eq(data.sumOfWeights(), 0.0)) { return 0; } double mSqErr = 0, sum = data.sumOfWeights(); for (int i = 0; i < data.numInstances(); i++) { Instance datum = data.instance(i); mSqErr += datum.weight() * (datum.classValue() - mean) * (datum.classValue() - mean); } return (mSqErr / sum); }
/** * Sets the weights for the next iteration. * * @param training the training instances * @param reweight the reweighting factor * @throws Exception if something goes wrong */ protected void setWeights(Instances training, double reweight) throws Exception { double oldSumOfWeights, newSumOfWeights; oldSumOfWeights = training.sumOfWeights(); Enumeration<Instance> enu = training.enumerateInstances(); while (enu.hasMoreElements()) { Instance instance = enu.nextElement(); if (!Utils.eq( m_Classifiers[m_NumIterationsPerformed].classifyInstance(instance), instance.classValue())) { instance.setWeight(instance.weight() * reweight); } } // Renormalize weights newSumOfWeights = training.sumOfWeights(); enu = training.enumerateInstances(); while (enu.hasMoreElements()) { Instance instance = enu.nextElement(); instance.setWeight(instance.weight() * oldSumOfWeights / newSumOfWeights); } }
/** * Sets the weights for the next iteration. * * @param training the training instances * @param reweight the reweighting factor * @throws Exception if something goes wrong */ protected void setWeights(Instances training, double reweight) throws Exception { double oldSumOfWeights, newSumOfWeights; oldSumOfWeights = training.sumOfWeights(); Enumeration<Instance> enu = training.enumerateInstances(); while (enu.hasMoreElements()) { Instance instance = enu.nextElement(); if (!Utils.eq( m_Classifiers[m_NumIterationsPerformed].classifyInstance(instance), instance.classValue())) { instance.setWeight(instance.weight() * reweight); } } // Renormalize weights newSumOfWeights = training.sumOfWeights(); enu = training.enumerateInstances(); while (enu.hasMoreElements()) { Instance instance = enu.nextElement(); instance.setWeight(instance.weight() * oldSumOfWeights / newSumOfWeights); } }
Instances data = pruneData; double total = data.sumOfWeights(); if (!Utils.gr(total, 0.0)) { return;
if (Utils.eq(data.sumOfWeights(), 0)) { m_isEmpty = true;
/** * Computes new distributions of instances for nodes * in tree. * * @param data the data to compute the distributions for * @throws Exception if something goes wrong */ private void newDistribution(Instances data) throws Exception { Instances [] localInstances; localModel().resetDistribution(data); m_train = data; if (!m_isLeaf){ localInstances = (Instances [])localModel().split(data); for (int i = 0; i < m_sons.length; i++) son(i).newDistribution(localInstances[i]); } else { // Check whether there are some instances at the leaf now! if (!Utils.eq(data.sumOfWeights(), 0)) { m_isEmpty = false; } } }
if (Utils.eq(data.sumOfWeights(), 0)) { m_isEmpty = true;
/** * Computes new distributions of instances for nodes * in tree. * * @param data the data to compute the distributions for * @throws Exception if something goes wrong */ private void newDistribution(Instances data) throws Exception { Instances [] localInstances; localModel().resetDistribution(data); m_train = data; if (!m_isLeaf){ localInstances = (Instances [])localModel().split(data); for (int i = 0; i < m_sons.length; i++) son(i).newDistribution(localInstances[i]); } else { // Check whether there are some instances at the leaf now! if (!Utils.eq(data.sumOfWeights(), 0)) { m_isEmpty = false; } } }
double sumProbs = m_TrainingData.sumOfWeights(); for (int i = 0; i < m_TrainingData.numInstances(); i++) { m_TrainingData.instance(i).setWeight(
rt += dataDL(expFPRate, 0.0, m_Data.sumOfWeights(), 0.0, fn);
rt += dataDL(expFPRate, 0.0, m_Data.sumOfWeights(), 0.0, fn);
if (Utils.eq(train.sumOfWeights(), 0)) { m_isEmpty = true;
if (Utils.eq(train.sumOfWeights(), 0)) { m_isEmpty = true;
/** * Initialize the classifier. * * @param data the training data to be used for generating the boosted * classifier. * @throws Exception if the classifier could not be built successfully */ public void initializeClassifier(Instances data) throws Exception { super.buildClassifier(data); // can classifier handle the data? getCapabilities().testWithFail(data); // remove instances with missing class data = new Instances(data); data.deleteWithMissingClass(); m_ZeroR = new weka.classifiers.rules.ZeroR(); m_ZeroR.buildClassifier(data); m_NumClasses = data.numClasses(); m_Betas = new double[m_Classifiers.length]; m_NumIterationsPerformed = 0; m_TrainingData = new Instances(data); m_RandomInstance = new Random(m_Seed); if ((m_UseResampling) || (!(m_Classifier instanceof WeightedInstancesHandler))) { // Normalize weights so that they sum to one and can be used as sampling probabilities double sumProbs = m_TrainingData.sumOfWeights(); for (int i = 0; i < m_TrainingData.numInstances(); i++) { m_TrainingData.instance(i).setWeight(m_TrainingData.instance(i).weight() / sumProbs); } } }
m_sons = null; indeX = 0; sumOfWeights = data.sumOfWeights(); noSplit = new NoSplit(new Distribution(data)); if (leaf) {
m_sons = null; indeX = 0; sumOfWeights = data.sumOfWeights(); noSplit = new NoSplit(new Distribution(data)); if (leaf) {
m_sons = null; indeX = 0; sumOfWeights = data.sumOfWeights(); noSplit = new NoSplit(new Distribution(data)); if (leaf) {