weka.core.Utils.logs2probs()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(98)

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

Utils.logs2probs介绍

[英]Converts an array containing the natural logarithms of probabilities stored in a vector back into probabilities. The probabilities are assumed to sum to one.
[中]将包含存储在向量中的概率的自然对数的数组转换回概率。假设概率之和为1。

代码示例

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

/**
 * Returns the cluster probability distribution for an instance.
 *
 * @param instance the instance to be clustered
 * @return the probability distribution
 * @throws Exception if computation fails
 */  
public double[] distributionForInstance(Instance instance) throws Exception {
 
 return Utils.logs2probs(logJointDensitiesForInstance(instance));
}

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

/**
 * Returns the cluster probability distribution for an instance.
 *
 * @param instance the instance to be clustered
 * @return the probability distribution
 * @throws Exception if computation fails
 */  
public double[] distributionForInstance(Instance instance) throws Exception {
 
 return Utils.logs2probs(logJointDensitiesForInstance(instance));
}

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

/**
 * Calculates entrpy for given model and data.
 */
protected double entropy(MM mixtureModel) {
 double entropy = 0;
 for (int j = 0; j < m_NumValues; j++) {
  entropy += m_Weights[j] * 
   ContingencyTables.entropy(Utils.logs2probs(mixtureModel.logJointDensities(m_Values[j])));
 }
 entropy *= Utils.log2; // Need natural logarithm, not base-2 logarithm
 return entropy / (double)m_NumValues;
}

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

/**
 * Calculates entrpy for given model and data.
 */
protected double entropy(MM mixtureModel) {
 double entropy = 0;
 for (int j = 0; j < m_NumValues; j++) {
  entropy += m_Weights[j] * 
   ContingencyTables.entropy(Utils.logs2probs(mixtureModel.logJointDensities(m_Values[j])));
 }
 entropy *= Utils.log2; // Need natural logarithm, not base-2 logarithm
 return entropy / (double)m_NumValues;
}

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

/**
 * 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 instance could not be classified successfully
 */
@Override
public double[] distributionForInstance(Instance instance) throws Exception {
 // default model?
 if (m_NumIterationsPerformed == 0) {
  return m_ZeroR.distributionForInstance(instance);
 }
 if (m_NumIterationsPerformed == 0) {
  throw new Exception("No model built");
 }
 double[] sums = new double[instance.numClasses()];
 if (m_NumIterationsPerformed == 1) {
  return m_Classifiers[0].distributionForInstance(instance);
 } else {
  for (int i = 0; i < m_NumIterationsPerformed; i++) {
   sums[(int) m_Classifiers[i].classifyInstance(instance)] += m_Betas[i];
  }
  return Utils.logs2probs(sums);
 }
}

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

/**
 * 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 instance could not be classified successfully
 */
@Override
public double[] distributionForInstance(Instance instance) throws Exception {
 // default model?
 if (m_NumIterationsPerformed == 0) {
  return m_ZeroR.distributionForInstance(instance);
 }
 if (m_NumIterationsPerformed == 0) {
  throw new Exception("No model built");
 }
 double[] sums = new double[instance.numClasses()];
 if (m_NumIterationsPerformed == 1) {
  return m_Classifiers[0].distributionForInstance(instance);
 } else {
  for (int i = 0; i < m_NumIterationsPerformed; i++) {
   sums[(int) m_Classifiers[i].classifyInstance(instance)] += m_Betas[i];
  }
  return Utils.logs2probs(sums);
 }
}

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

tempDist = Utils.logs2probs(tempDist);
Utils.normalize(tempDist);

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

double[] p = Utils.logs2probs(model.logJointDensities(values[i]));
for (int j = 0; j < p.length; j++) {
 probs[j][i] = p[j];

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

double[] p = Utils.logs2probs(model.logJointDensities(values[i]));
for (int j = 0; j < p.length; j++) {
 probs[j][i] = p[j];

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

normDist[i] += Math.log(nbDist[i]);
normDist = Utils.logs2probs(normDist);

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

/**
 * Output class probabilities using Bayes' rule.
 */
public double[] distributionForInstance(Instance inst) throws Exception {
 
 // Filter instance
 m_RemoveUseless.input(inst);
 inst = m_RemoveUseless.output();
 
 // Convert instance to array
 double[] values = new double[inst.numAttributes() - 1];
 int index = 0;
 for (int i = 0; i < m_Data.numAttributes(); i++) {
  if (i != m_Data.classIndex()) {
   values[index++] = inst.value(i);
  }
 }
 double[] posteriorProbs = new double[m_Data.numClasses()];
 for (int i = 0; i < m_Data.numClasses(); i++) {
  if (m_Estimators[i] != null) {
   posteriorProbs[i] = m_Estimators[i].logDensity(values) + m_LogPriors[i];
  } else {
   posteriorProbs[i] = -Double.MAX_VALUE;
  }
 }
 posteriorProbs = Utils.logs2probs(posteriorProbs);
 return posteriorProbs;
}

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

/**
 * Output class probabilities using Bayes' rule.
 */
public double[] distributionForInstance(Instance inst) throws Exception {
 
 // Filter instance
 m_RemoveUseless.input(inst);
 inst = m_RemoveUseless.output();
 
 // Convert instance to array
 double[] posteriorProbs = new double[m_Data.numClasses()];
 double[] values = new double[inst.numAttributes() - 1];
 for (int i = 0; i < m_Data.numClasses(); i++) {
  if (m_Means[i] != null) {
   int index = 0;
   for (int j = 0; j < m_Data.numAttributes(); j++) {
    if (j != m_Data.classIndex()) {
     values[index] = inst.value(j) - m_Means[i][index] + m_GlobalMean[index];
     index++;
    }
   }
   posteriorProbs[i] = m_Estimator.logDensity(values) + m_LogPriors[i];
  } else {
   posteriorProbs[i] = -Double.MAX_VALUE;
  }
 }
 posteriorProbs = Utils.logs2probs(posteriorProbs);
 return posteriorProbs;
}

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

tempvals = Utils.logs2probs(tempvals);
System.arraycopy(tempvals, 0, instanceVals, 0, tempvals.length);
if (instance.classIndex() >= 0) {

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

tempvals = Utils.logs2probs(tempvals);
System.arraycopy(tempvals, 0, instanceVals, 0, tempvals.length);
if (instance.classIndex() >= 0) {

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

normDist[l] += Math.log(nbDist[l]);
normDist = Utils.logs2probs(normDist);

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

probs = Utils.logs2probs(probs);
} else {

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

probs = Utils.logs2probs(probs);
} else {

相关文章