weka.core.Instances.sumOfWeights()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中weka.core.Instances.sumOfWeights()方法的一些代码示例,展示了Instances.sumOfWeights()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instances.sumOfWeights()方法的具体详情如下:
包路径:weka.core.Instances
类名称:Instances
方法名:sumOfWeights

Instances.sumOfWeights介绍

[英]Computes the sum of all the instances' weights.
[中]计算所有实例的权重之和。

代码示例

代码示例来源:origin: com.googlecode.obvious/obviousx-weka

@Override
public double sumOfWeights() {
 return super.sumOfWeights();
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * 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)));
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * 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)));
}

代码示例来源:origin: nz.ac.waikato.cms.weka/conjunctiveRule

/**
 * 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);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * 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);
 }
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * 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);
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

Instances data = pruneData;
double total = data.sumOfWeights();
if (!Utils.gr(total, 0.0)) {
 return;

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

if (Utils.eq(data.sumOfWeights(), 0)) {
 m_isEmpty = true;

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * 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;
  }
 }
}

代码示例来源:origin: Waikato/weka-trunk

if (Utils.eq(data.sumOfWeights(), 0)) {
 m_isEmpty = true;

代码示例来源:origin: Waikato/weka-trunk

/**
 * 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;
  }
 }
}

代码示例来源:origin: Waikato/weka-trunk

double sumProbs = m_TrainingData.sumOfWeights();
for (int i = 0; i < m_TrainingData.numInstances(); i++) {
 m_TrainingData.instance(i).setWeight(

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

rt += dataDL(expFPRate, 0.0, m_Data.sumOfWeights(), 0.0, fn);

代码示例来源:origin: Waikato/weka-trunk

rt += dataDL(expFPRate, 0.0, m_Data.sumOfWeights(), 0.0, fn);

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

if (Utils.eq(train.sumOfWeights(), 0)) {
 m_isEmpty = true;

代码示例来源:origin: Waikato/weka-trunk

if (Utils.eq(train.sumOfWeights(), 0)) {
 m_isEmpty = true;

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * 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);
  }
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

m_sons = null;
indeX = 0;
sumOfWeights = data.sumOfWeights();
noSplit = new NoSplit(new Distribution(data));
if (leaf) {

代码示例来源:origin: Waikato/weka-trunk

m_sons = null;
indeX = 0;
sumOfWeights = data.sumOfWeights();
noSplit = new NoSplit(new Distribution(data));
if (leaf) {

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

m_sons = null;
indeX = 0;
sumOfWeights = data.sumOfWeights();
noSplit = new NoSplit(new Distribution(data));
if (leaf) {

相关文章

Instances类方法