当前位置: 首页>>代码示例>>Java>>正文


Java Utils.normalize方法代码示例

本文整理汇总了Java中weka.core.Utils.normalize方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.normalize方法的具体用法?Java Utils.normalize怎么用?Java Utils.normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weka.core.Utils的用法示例。


在下文中一共展示了Utils.normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: distributionForInstance

import weka.core.Utils; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public double[] distributionForInstance(Instance instance) throws Exception {
	double[] result;

	result = classifier.getVotesForInstance(instance);
	// ensure that the array has as many elements as there are
	// class values!
	if (result.length < instance.numClasses()) {
		double[] newResult = new double[instance.numClasses()];
		System.arraycopy(result, 0, newResult, 0, result.length);
		result = newResult;
	}

	try {
		Utils.normalize(result);
	} catch (Exception e) {
		result = new double[instance.numClasses()];
	}

	return result;
}
 
开发者ID:ogreyesp,项目名称:JCLAL,代码行数:24,代码来源:MOAWrapper.java

示例2: distributionForInstance

import weka.core.Utils; //导入方法依赖的package包/类
@Override
public double[] distributionForInstance(Instance instance) throws Exception {
  if (m_canopies == null || m_canopies.size() == 0) {
    throw new Exception("No canopies available to cluster with!");
  }

  double[] d = new double[numberOfClusters()];

  if (m_missingValuesReplacer != null) {
    m_missingValuesReplacer.input(instance);
    instance = m_missingValuesReplacer.output();
  }

  for (int i = 0; i < m_canopies.numInstances(); i++) {
    double distance = m_distanceFunction.distance(instance,
      m_canopies.instance(i));

    d[i] = 1.0 / (1.0 + distance);
  }

  Utils.normalize(d);
  return d;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:24,代码来源:Canopy.java

示例3: distributionForInstance

import weka.core.Utils; //导入方法依赖的package包/类
/**                                                                                                             
 * Classifies the given test instance. The instance has to belong to a                                          
 * dataset when it's being classified.                                                          
 *                                                                                                              
 * @param inst the instance to be classified                                                                
 * @return the predicted most likely class for the instance or                                                  
 * Utils.missingValue() if no prediction is made                                                             
 * @exception Exception if an error occurred during the prediction                                              
 */
public double[] distributionForInstance(Instance inst) throws Exception {
  if (!m_initialized) {
    mapToMiningSchema(inst.dataset());
  }
  double[] preds = null;
  
  if (m_miningSchema.getFieldsAsInstances().classAttribute().isNumeric()) {
    preds = new double[1];
  } else {
    preds = new double[m_miningSchema.getFieldsAsInstances().classAttribute().numValues()];
  }
  
  double[] incoming = m_fieldsMap.instanceToSchema(inst, m_miningSchema);
  
  preds = m_ruleSet.score(incoming, 
      m_miningSchema.getFieldsAsInstances().classAttribute());
  
  if (m_miningSchema.getFieldsAsInstances().classAttribute().isNominal()) {
    Utils.normalize(preds);
  }
  
  return preds;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:33,代码来源:RuleSetModel.java

示例4: distributionForInstance

import weka.core.Utils; //导入方法依赖的package包/类
/**
 * Returns the class distribution for an instance.
 */
@Override
public double[] distributionForInstance(Instance inst) throws Exception {

  // Does the metric produce thresholds that need to be applied?
  if (m_thresholds != null) {
    double[] dist = m_IterativeClassifier.distributionForInstance(inst);
    double[] newDist = new double[dist.length];
    for (int i = 0; i < dist.length; i++) {
      if (dist[i] >= m_thresholds[i]) {
        newDist[i] = 1.0;
      }
    }
    Utils.normalize(newDist); // Could have multiple 1.0 entries
    return newDist;
  } else {
    return m_IterativeClassifier.distributionForInstance(inst);
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:22,代码来源:IterativeClassifierOptimizer.java

示例5: getDistribution

import weka.core.Utils; //导入方法依赖的package包/类
/**
 * Return a class probability distribution computed from the frequency counts
 * at this node
 * 
 * @param inst the instance to get a prediction for
 * @param classAtt the class attribute
 * @return a class probability distribution
 * @throws Exception if a problem occurs
 */
public double[] getDistribution(Instance inst, Attribute classAtt)
    throws Exception {
  double[] dist = new double[classAtt.numValues()];

  for (int i = 0; i < classAtt.numValues(); i++) {
    WeightMass w = m_classDistribution.get(classAtt.value(i));
    if (w != null) {
      dist[i] = w.m_weight;
    } else {
      dist[i] = 1.0;
    }
  }

  Utils.normalize(dist);
  return dist;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:26,代码来源:HNode.java

示例6: distributionForInstance

import weka.core.Utils; //导入方法依赖的package包/类
/**
  * Calculates the class membership probabilities for the given test
  * instance.
  *
  * @param instance the instance to be classified
  * @return preedicted class probability distribution
  * @throws Exception if distribution can't be computed successfully 
  */
 @Override
 public double[] distributionForInstance(Instance instance) throws Exception {

   double [] sums = new double [instance.numClasses()], newProbs; 
   
   double numPreds = 0;
   for (int i = 0; i < m_NumIterations; i++) {
     if (instance.classAttribute().isNumeric() == true) {
       double pred = m_Classifiers[i].classifyInstance(instance);
       if (!Utils.isMissingValue(pred)) {
         sums[0] += pred;
         numPreds++;
       }
     } else {
newProbs = m_Classifiers[i].distributionForInstance(instance);
for (int j = 0; j < newProbs.length; j++)
  sums[j] += newProbs[j];
     }
   }
   if (instance.classAttribute().isNumeric() == true) {
     if (numPreds == 0) {
       sums[0] = Utils.missingValue();
     } else {
       sums[0] /= numPreds;
     }
     return sums;
   } else if (Utils.eq(Utils.sum(sums), 0)) {
     return sums;
   } else {
     Utils.normalize(sums);
     return sums;
   }
 }
 
开发者ID:seqcode,项目名称:seqcode-core,代码行数:42,代码来源:AttributeBagging.java

示例7: distributionForInstance

import weka.core.Utils; //导入方法依赖的package包/类
/**
 * Classifies a given instance using the selected combination rule.
 * 
 * @param instance the instance to be classified
 * @return the distribution
 * @throws Exception if instance could not be classified successfully
 */
@Override
public double[] distributionForInstance(Instance instance) throws Exception {
  double[] result = new double[instance.numClasses()];

  switch (m_CombinationRule) {
  case AVERAGE_RULE:
    result = distributionForInstanceAverage(instance);
    break;
  case PRODUCT_RULE:
    result = distributionForInstanceProduct(instance);
    break;
  case MAJORITY_VOTING_RULE:
    result = distributionForInstanceMajorityVoting(instance);
    break;
  case MIN_RULE:
    result = distributionForInstanceMin(instance);
    break;
  case MAX_RULE:
    result = distributionForInstanceMax(instance);
    break;
  case MEDIAN_RULE:
    result[0] = classifyInstance(instance);
    break;
  default:
    throw new IllegalStateException("Unknown combination rule '"
      + m_CombinationRule + "'!");
  }

  if (!instance.classAttribute().isNumeric() && (Utils.sum(result) > 0)) {
    Utils.normalize(result);
  }

  return result;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:42,代码来源:Vote.java

示例8: distributionForInstance

import weka.core.Utils; //导入方法依赖的package包/类
/**
  * Calculates the class membership probabilities for the given test
  * instance.
  *
  * @param instance 	the instance to be classified
  * @return 		preedicted class probability distribution
  * @throws Exception 	if distribution can't be computed successfully 
  */
 public double[] distributionForInstance(Instance instance) throws Exception {

   // default model?
   if (m_ZeroR != null) {
     return m_ZeroR.distributionForInstance(instance);
   }
   
   double[] sums = new double [instance.numClasses()], newProbs; 
   
   double numPreds = 0;
   for (int i = 0; i < m_NumIterations; i++) {
     if (instance.classAttribute().isNumeric() == true) {
       double pred = m_Classifiers[i].classifyInstance(instance);
       if (!Utils.isMissingValue(pred)) {
         sums[0] += pred;
         numPreds++;
       }
     } else {
newProbs = m_Classifiers[i].distributionForInstance(instance);
for (int j = 0; j < newProbs.length; j++)
  sums[j] += newProbs[j];
     }
   }
   if (instance.classAttribute().isNumeric() == true) {
     if (numPreds == 0) {
       sums[0] = Utils.missingValue();
     } else {
       sums[0] /= numPreds;
     }
     return sums;
   } else if (Utils.eq(Utils.sum(sums), 0)) {
     return sums;
   } else {
     Utils.normalize(sums);
     return sums;
   }
 }
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:46,代码来源:RandomSubSpace.java

示例9: distributionForInstance

import weka.core.Utils; //导入方法依赖的package包/类
/**
  * Returns the distribution for an instance.
  *
  * @param inst the instance to get the distribution for
  * @return the computed distribution
  * @throws Exception if the distribution can't be computed successfully
  */
 public double[] distributionForInstance(Instance inst) throws Exception {
   
   double[] probs = new double[inst.numClasses()];
   Instance newInst;
   double sum = 0;

   for (int i = 0; i < inst.numClasses(); i++) {
     m_ClassFilters[i].input(inst);
     m_ClassFilters[i].batchFinished();
     newInst = m_ClassFilters[i].output();
     probs[i] = m_Classifiers[i].classifyInstance(newInst);
     if (Utils.isMissingValue(probs[i])) {
       throw new UnassignedClassException("ClassificationViaRegression: base learner predicted missing value.");
     }
     if (probs[i] > 1) {
       probs[i] = 1;
     }
     if (probs[i] < 0){
probs[i] = 0;
     }
     sum += probs[i];
   }
   if (sum != 0) {
     Utils.normalize(probs, sum);
   } 
   return probs;
 }
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:35,代码来源:ClassificationViaRegression.java

示例10: getOuput

import weka.core.Utils; //导入方法依赖的package包/类
/**
 * Compute the output. Either a probability distribution or a single
 * value (regression).
 * 
 * @param incoming the values from the last hidden layer
 * @param preds the array to fill with predicted values
 * @throws Exception if there is a problem computing the output
 */
protected void getOuput(HashMap<String, Double> incoming, double[] preds) throws Exception {
  
  if (preds.length != m_outputNeurons.length) {
    throw new Exception("[NeuralOutputs] Incorrect number of predictions requested: "
        + preds.length + "requested, " + m_outputNeurons.length + " expected");
  }
  for (int i = 0; i < m_outputNeurons.length; i++) {
    Double neuronOut = incoming.get(m_outputNeurons[i]);
    if (neuronOut == null) {
      throw new Exception("[NeuralOutputs] Unable to find output neuron "
          + m_outputNeurons[i] + " in the incoming HashMap!!");
    }
    if (m_classAttribute.isNumeric()) {
      // will be only one output neuron anyway
      preds[0] = neuronOut.doubleValue();
      
      preds[0] = m_regressionMapping.getResultInverse(preds);
    } else {

      // clip at zero
      // preds[m_categoricalIndexes[i]] = (neuronOut < 0) ? 0.0 : neuronOut;
      preds[m_categoricalIndexes[i]] = neuronOut;
    }
  }
  
  if (m_classAttribute.isNominal()) {
    // check for negative values and adjust
    double min = preds[Utils.minIndex(preds)];
    if (min < 0) {
      for (int i = 0; i < preds.length; i++) {
        preds[i] -= min;
      }
    }
    // do a simplemax normalization
    Utils.normalize(preds);
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:46,代码来源:NeuralNetwork.java

示例11: distributionForInstance

import weka.core.Utils; //导入方法依赖的package包/类
/**
 * Computes class distribution of an instance using the decision tree.
 * 
 * @param instance the instance to compute the distribution for
 * @return the computed class distribution
 * @throws Exception if computation fails
 */
public double[] distributionForInstance(Instance instance) throws Exception {

  double[] returnedDist = null;

  if (m_Attribute > -1) {

    // Node is not a leaf
    if (instance.isMissing(m_Attribute)) {

      // Value is missing
      returnedDist = new double[m_Info.numClasses()];

      // Split instance up
      for (int i = 0; i < m_Successors.length; i++) {
        double[] help = m_Successors[i].distributionForInstance(instance);
        if (help != null) {
          for (int j = 0; j < help.length; j++) {
            returnedDist[j] += m_Prop[i] * help[j];
          }
        }
      }
    } else if (m_Info.attribute(m_Attribute).isNominal()) {

      // For nominal attributes
      returnedDist = m_Successors[(int) instance.value(m_Attribute)]
        .distributionForInstance(instance);
    } else {

      // For numeric attributes
      if (instance.value(m_Attribute) < m_SplitPoint) {
        returnedDist = m_Successors[0].distributionForInstance(instance);
      } else {
        returnedDist = m_Successors[1].distributionForInstance(instance);
      }
    }
  }

  // Node is a leaf or successor is empty?
  if ((m_Attribute == -1) || (returnedDist == null)) {

    // Is node empty?
    if (m_ClassDistribution == null) {
      if (getAllowUnclassifiedInstances()) {
        double[] result = new double[m_Info.numClasses()];
        if (m_Info.classAttribute().isNumeric()) {
          result[0] = Utils.missingValue();
        }
        return result;
      } else {
        return null;
      }
    }

    // Else return normalized distribution
    double[] normalizedDistribution = m_ClassDistribution.clone();
    if (m_Info.classAttribute().isNominal()) {
      Utils.normalize(normalizedDistribution);
    }
    return normalizedDistribution;
  } else {
    return returnedDist;
  }
}
 
开发者ID:seqcode,项目名称:seqcode-core,代码行数:71,代码来源:AttributeRandomTree.java

示例12: distributionForInstance

import weka.core.Utils; //导入方法依赖的package包/类
/**
 * 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 distribution can't be computed
 */
@Override
public double[] distributionForInstance(Instance instance) throws Exception {

  DecisionTableHashKey thekey;
  double[] tempDist;
  double[] normDist;

  m_disTransform.input(instance);
  m_disTransform.batchFinished();
  instance = m_disTransform.output();

  m_delTransform.input(instance);
  m_delTransform.batchFinished();
  instance = m_delTransform.output();

  thekey = new DecisionTableHashKey(instance, instance.numAttributes(), false);

  // if this one is not in the table
  if ((tempDist = m_entries.get(thekey)) == null) {
    if (m_useIBk) {
      tempDist = m_ibk.distributionForInstance(instance);
    } else {
      if (!m_classIsNominal) {
        tempDist = new double[1];
        tempDist[0] = m_majority;
      } else {
        tempDist = m_classPriors.clone();
        /*
         * tempDist = new double
         * [m_theInstances.classAttribute().numValues()];
         * tempDist[(int)m_majority] = 1.0;
         */
      }
    }
  } else {
    if (!m_classIsNominal) {
      normDist = new double[1];
      normDist[0] = (tempDist[0] / tempDist[1]);
      tempDist = normDist;
    } else {

      // normalise distribution
      normDist = new double[tempDist.length];
      System.arraycopy(tempDist, 0, normDist, 0, tempDist.length);
      Utils.normalize(normDist);
      tempDist = normDist;
    }
  }
  return tempDist;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:58,代码来源:DecisionTable.java

示例13: buildClassifier

import weka.core.Utils; //导入方法依赖的package包/类
/**
 * Generates the classifier.
 * 
 * @param instances set of instances serving as training data
 * @throws Exception if the classifier has not been generated successfully
 */
@Override
public void buildClassifier(Instances instances) throws Exception {
  // can classifier handle the data?
  getCapabilities().testWithFail(instances);

  // remove instances with missing class
  instances = new Instances(instances);
  instances.deleteWithMissingClass();

  double sumOfWeights = 0;

  m_Class = instances.classAttribute();
  m_ClassValue = 0;
  switch (instances.classAttribute().type()) {
  case Attribute.NUMERIC:
    m_Counts = null;
    break;
  case Attribute.NOMINAL:
    m_Counts = new double[instances.numClasses()];
    for (int i = 0; i < m_Counts.length; i++) {
      m_Counts[i] = 1;
    }
    sumOfWeights = instances.numClasses();
    break;
  }
  Enumeration<Instance> enu = instances.enumerateInstances();
  while (enu.hasMoreElements()) {
    Instance instance = enu.nextElement();
    if (!instance.classIsMissing()) {
      if (instances.classAttribute().isNominal()) {
        m_Counts[(int) instance.classValue()] += instance.weight();
      } else {
        m_ClassValue += instance.weight() * instance.classValue();
      }
      sumOfWeights += instance.weight();
    }
  }
  if (instances.classAttribute().isNumeric()) {
    if (Utils.gr(sumOfWeights, 0)) {
      m_ClassValue /= sumOfWeights;
    }
  } else {
    m_ClassValue = Utils.maxIndex(m_Counts);
    Utils.normalize(m_Counts, sumOfWeights);
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:53,代码来源:ZeroR.java

示例14: calculateRegionProbs

import weka.core.Utils; //导入方法依赖的package包/类
private double[] calculateRegionProbs(int j, int i) throws Exception {
  double[] sumOfProbsForRegion = new double[m_trainingData.classAttribute()
    .numValues()];

  for (int u = 0; u < m_numOfSamplesPerRegion; u++) {

    double[] sumOfProbsForLocation = new double[m_trainingData
      .classAttribute().numValues()];

    m_weightingAttsValues[m_xAttribute] = getRandomX(j);
    m_weightingAttsValues[m_yAttribute] = getRandomY(m_panelHeight - i - 1);

    m_dataGenerator.setWeightingValues(m_weightingAttsValues);

    double[] weights = m_dataGenerator.getWeights();
    double sumOfWeights = Utils.sum(weights);
    int[] indices = Utils.sort(weights);

    // Prune 1% of weight mass
    int[] newIndices = new int[indices.length];
    double sumSoFar = 0;
    double criticalMass = 0.99 * sumOfWeights;
    int index = weights.length - 1;
    int counter = 0;
    for (int z = weights.length - 1; z >= 0; z--) {
      newIndices[index--] = indices[z];
      sumSoFar += weights[indices[z]];
      counter++;
      if (sumSoFar > criticalMass) {
        break;
      }
    }
    indices = new int[counter];
    System.arraycopy(newIndices, index + 1, indices, 0, counter);

    for (int z = 0; z < m_numOfSamplesPerGenerator; z++) {

      m_dataGenerator.setWeightingValues(m_weightingAttsValues);
      double[][] values = m_dataGenerator.generateInstances(indices);

      for (int q = 0; q < values.length; q++) {
        if (values[q] != null) {
          System.arraycopy(values[q], 0, m_vals, 0, m_vals.length);
          m_vals[m_xAttribute] = m_weightingAttsValues[m_xAttribute];
          m_vals[m_yAttribute] = m_weightingAttsValues[m_yAttribute];

          // classify the instance
          m_dist = m_classifier.distributionForInstance(m_predInst);

          for (int k = 0; k < sumOfProbsForLocation.length; k++) {
            sumOfProbsForLocation[k] += (m_dist[k] * weights[q]);
          }
        }
      }
    }

    for (int k = 0; k < sumOfProbsForRegion.length; k++) {
      sumOfProbsForRegion[k] += (sumOfProbsForLocation[k] * sumOfWeights);
    }
  }

  // average
  Utils.normalize(sumOfProbsForRegion);

  // cache
  double[] tempDist = new double[sumOfProbsForRegion.length];
  System.arraycopy(sumOfProbsForRegion, 0, tempDist, 0,
    sumOfProbsForRegion.length);

  return tempDist;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:72,代码来源:RemoteBoundaryVisualizerSubTask.java

示例15: distributionForInstance

import weka.core.Utils; //导入方法依赖的package包/类
/**
 * Calculates the class membership probabilities for the given test instance.
 * 
 * @param bayesNet the bayes net to use
 * @param instance the instance to be classified
 * @return predicted class probability distribution
 * @throws Exception if there is a problem generating the prediction
 */
@Override
public double[] distributionForInstance(BayesNet bayesNet, Instance instance)
  throws Exception {
  Instances instances = bayesNet.m_Instances;
  int nNumClasses = instances.numClasses();
  double[] fProbs = new double[nNumClasses];

  for (int iClass = 0; iClass < nNumClasses; iClass++) {
    double logfP = 0;

    for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
      double iCPT = 0;

      for (int iParent = 0; iParent < bayesNet.getParentSet(iAttribute)
        .getNrOfParents(); iParent++) {
        int nParent = bayesNet.getParentSet(iAttribute).getParent(iParent);

        if (nParent == instances.classIndex()) {
          iCPT = iCPT * nNumClasses + iClass;
        } else {
          iCPT = iCPT * instances.attribute(nParent).numValues()
            + instance.value(nParent);
        }
      }

      if (iAttribute == instances.classIndex()) {
        // fP *=
        // m_Distributions[iAttribute][(int) iCPT].getProbability(iClass);
        logfP += Math.log(bayesNet.m_Distributions[iAttribute][(int) iCPT]
          .getProbability(iClass));
      } else {
        // fP *=
        // m_Distributions[iAttribute][(int) iCPT]
        // .getProbability(instance.value(iAttribute));
        logfP += Math.log(bayesNet.m_Distributions[iAttribute][(int) iCPT]
          .getProbability(instance.value(iAttribute)));
      }
    }

    // fProbs[iClass] *= fP;
    fProbs[iClass] += logfP;
  }

  // Find maximum
  double fMax = fProbs[0];
  for (int iClass = 0; iClass < nNumClasses; iClass++) {
    if (fProbs[iClass] > fMax) {
      fMax = fProbs[iClass];
    }
  }
  // transform from log-space to normal-space
  for (int iClass = 0; iClass < nNumClasses; iClass++) {
    fProbs[iClass] = Math.exp(fProbs[iClass] - fMax);
  }

  // Display probabilities
  try {
    Utils.normalize(fProbs);
  } catch (IllegalArgumentException ex) {
    return new double[nNumClasses]; // predict missing value
  }

  return fProbs;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:73,代码来源:SimpleEstimator.java


注:本文中的weka.core.Utils.normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。