本文整理汇总了Java中weka.core.Utils.gr方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.gr方法的具体用法?Java Utils.gr怎么用?Java Utils.gr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.Utils
的用法示例。
在下文中一共展示了Utils.gr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: classifyInstance
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Classifies an instance.
*
* @param instance the instance to classify
* @return the classification
* @throws Exception if something goes wrong
*/
public double classifyInstance(Instance instance) throws Exception {
double maxProb = -1;
double currentProb;
int maxIndex = 0;
int j;
for (j = 0; j < instance.numClasses(); j++) {
currentProb = getProbs(j, instance, 1);
if (Utils.gr(currentProb, maxProb)) {
maxIndex = j;
maxProb = currentProb;
}
}
return maxIndex;
}
示例2: splitEnt
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Help method for computing the split entropy.
*/
private final double splitEnt(Distribution bags, double totalnoInst) {
double returnValue = 0;
double noUnknown;
int i;
noUnknown = totalnoInst - bags.total();
if (Utils.gr(bags.total(), 0)) {
for (i = 0; i < bags.numBags(); i++) {
returnValue = returnValue - lnFunc(bags.perBag(i));
}
returnValue = returnValue - lnFunc(noUnknown);
returnValue = returnValue + lnFunc(totalnoInst);
}
return returnValue / ContingencyTables.log2;
}
示例3: setSplitPoint
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Sets split point to greatest value in given data smaller or equal to old
* split point. (C4.5 does this for some strange reason).
*/
public final void setSplitPoint(Instances allInstances) {
double newSplitPoint = -Double.MAX_VALUE;
double tempValue;
Instance instance;
if ((!allInstances.attribute(m_attIndex).isNominal()) && (m_numSubsets > 1)) {
Enumeration<Instance> enu = allInstances.enumerateInstances();
while (enu.hasMoreElements()) {
instance = enu.nextElement();
if (!instance.isMissing(m_attIndex)) {
tempValue = instance.value(m_attIndex);
if (Utils.gr(tempValue, newSplitPoint)
&& Utils.smOrEq(tempValue, m_splitPoint)) {
newSplitPoint = tempValue;
}
}
}
m_splitPoint = newSplitPoint;
}
}
示例4: dataDL
import weka.core.Utils; //导入方法依赖的package包/类
/**
* The description length of data given the parameters of the data based on
* the ruleset.
* <p>
* Details see Quinlan: "MDL and categorical theories (Continued)",ML95
* <p>
*
* @param expFPOverErr expected FP/(FP+FN)
* @param cover coverage
* @param uncover uncoverage
* @param fp False Positive
* @param fn False Negative
* @return the description length
*/
public static double dataDL(double expFPOverErr, double cover,
double uncover, double fp, double fn) {
double totalBits = Utils.log2(cover + uncover + 1.0); // how many data?
double coverBits, uncoverBits; // What's the error?
double expErr; // Expected FP or FN
if (Utils.gr(cover, uncover)) {
expErr = expFPOverErr * (fp + fn);
coverBits = subsetDL(cover, fp, expErr / cover);
uncoverBits = Utils.gr(uncover, 0.0) ? subsetDL(uncover, fn, fn / uncover)
: 0.0;
} else {
expErr = (1.0 - expFPOverErr) * (fp + fn);
coverBits = Utils.gr(cover, 0.0) ? subsetDL(cover, fp, fp / cover) : 0.0;
uncoverBits = subsetDL(uncover, fn, expErr / uncover);
}
/*
* System.err.println("!!!cover: " + cover + "|uncover" + uncover +
* "|coverBits: "+coverBits+"|uncBits: "+ uncoverBits+
* "|FPRate: "+expFPOverErr + "|expErr: "+expErr+
* "|fp: "+fp+"|fn: "+fn+"|total: "+totalBits);
*/
return (totalBits + coverBits + uncoverBits);
}
示例5: setSplitPoint
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Sets split point to greatest value in given data smaller or equal to old
* split point. (C4.5 does this for some strange reason).
*/
public final void setSplitPoint(Instances allInstances) {
double newSplitPoint = -Double.MAX_VALUE;
double tempValue;
Instance instance;
if ((allInstances.attribute(m_attIndex).isNumeric()) && (m_numSubsets > 1)) {
Enumeration<Instance> enu = allInstances.enumerateInstances();
while (enu.hasMoreElements()) {
instance = enu.nextElement();
if (!instance.isMissing(m_attIndex)) {
tempValue = instance.value(m_attIndex);
if (Utils.gr(tempValue, newSplitPoint)
&& Utils.smOrEq(tempValue, m_splitPoint)) {
newSplitPoint = tempValue;
}
}
}
m_splitPoint = newSplitPoint;
}
}
示例6: classifyInstance
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Classifies an instance.
*
* @param instance the instance to classify
* @return the classification
* @throws Exception if instance can't be classified successfully
*/
@Override
public double classifyInstance(Instance instance) throws Exception {
double maxProb = -1;
int maxIndex = 0;
// classify by maximum probability
double[] probs = distributionForInstance(instance);
for (int j = 0; j < instance.numClasses(); j++) {
if (Utils.gr(probs[j], maxProb)) {
maxIndex = j;
maxProb = probs[j];
}
}
return maxIndex;
}
示例7: classifyInstance
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Classifies an instance.
*
* @exception Exception if instance can't be classified
*/
public double classifyInstance(Instance instance) throws Exception {
double maxProb = -1;
double[] sumProbs;
int maxIndex = 0;
sumProbs = distributionForInstance(instance);
for (int j = 0; j < sumProbs.length; j++) {
if (Utils.gr(sumProbs[j], maxProb)) {
maxIndex = j;
maxProb = sumProbs[j];
}
}
return maxIndex;
}
示例8: distributionForInstance
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Returns the class distribution for an instance.
*
* @exception Exception if distribution can't be computed
*/
public double[] distributionForInstance(Instance instance) throws Exception {
double[] currentProbs = null;
double[] sumProbs;
double currentWeight, weight = 1;
int i, j;
// Get probabilities.
sumProbs = new double[instance.numClasses()];
i = 0;
while (Utils.gr(weight, 0)) {
currentWeight = theRules.elementAt(i).weight(instance);
if (Utils.gr(currentWeight, 0)) {
currentProbs = theRules.elementAt(i).distributionForInstance(instance);
for (j = 0; j < sumProbs.length; j++) {
sumProbs[j] += weight * currentProbs[j];
}
weight = weight * (1 - currentWeight);
}
i++;
}
return sumProbs;
}
示例9: classifyInstance
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Classifies an instance.
*
* @exception Exception if something goes wrong
*/
public double classifyInstance(Instance instance) throws Exception {
double maxProb = -1;
double currentProb;
int maxIndex = 0;
int j;
for (j = 0; j < instance.numClasses(); j++) {
currentProb = getProbs(j, instance, 1);
if (Utils.gr(currentProb, maxProb)) {
maxIndex = j;
maxProb = currentProb;
}
}
if (Utils.eq(maxProb, 0)) {
return -1.0;
} else {
return maxIndex;
}
}
示例10: dumpLabel
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Prints label for subset index of instances (eg class).
*
* @exception Exception if something goes wrong
*/
public final String dumpLabel(int index,Instances data) throws Exception {
StringBuffer text;
text = new StringBuffer();
text.append(((Instances)data).classAttribute().
value(m_distribution.maxClass(index)));
text.append(" ("+Utils.roundDouble(m_distribution.perBag(index),2));
if (Utils.gr(m_distribution.numIncorrect(index),0))
text.append("/"+Utils.roundDouble(m_distribution.numIncorrect(index),2));
text.append(")");
return text.toString();
}
示例11: actualNumClasses
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Returns number of classes actually occuring in distribution.
*/
public final int actualNumClasses() {
int returnValue = 0;
int i;
for (i = 0; i < m_perClass.length; i++) {
if (Utils.gr(m_perClass[i], 0)) {
returnValue++;
}
}
return returnValue;
}
示例12: laplaceProb
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Returns relative frequency of class for given bag.
*/
public final double laplaceProb(int classIndex, int intIndex) {
if (Utils.gr(m_perBag[intIndex], 0)) {
return (m_perClassPerBag[intIndex][classIndex] + 1.0)
/ (m_perBag[intIndex] + m_perClass.length);
} else {
return laplaceProb(classIndex);
}
}
示例13: computeAverageClassValues
import weka.core.Utils; //导入方法依赖的package包/类
/** Computes average class values for each attribute and value */
private void computeAverageClassValues() {
double totalCounts, sum;
Instance instance;
double[] counts;
double[][] avgClassValues = new double[getInputFormat().numAttributes()][0];
m_Indices = new int[getInputFormat().numAttributes()][0];
for (int j = 0; j < getInputFormat().numAttributes(); j++) {
Attribute att = getInputFormat().attribute(j);
if (att.isNominal()) {
avgClassValues[j] = new double[att.numValues()];
counts = new double[att.numValues()];
for (int i = 0; i < getInputFormat().numInstances(); i++) {
instance = getInputFormat().instance(i);
if (!instance.classIsMissing() && (!instance.isMissing(j))) {
counts[(int) instance.value(j)] += instance.weight();
avgClassValues[j][(int) instance.value(j)] += instance.weight()
* instance.classValue();
}
}
sum = Utils.sum(avgClassValues[j]);
totalCounts = Utils.sum(counts);
if (Utils.gr(totalCounts, 0)) {
for (int k = 0; k < att.numValues(); k++) {
if (Utils.gr(counts[k], 0)) {
avgClassValues[j][k] /= counts[k];
} else {
avgClassValues[j][k] = sum / totalCounts;
}
}
}
m_Indices[j] = Utils.sort(avgClassValues[j]);
}
}
}
示例14: checkClassifier
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Quick and dirty check whether the quadratic programming problem is solved.
*
* @throws Exception if checking fails
*/
protected void checkClassifier() throws Exception {
double sum = 0;
for (int i = 0; i < m_alpha.length; i++) {
if (m_alpha[i] > 0) {
sum += m_class[i] * m_alpha[i];
}
}
System.err.println("Sum of y(i) * alpha(i): " + sum);
for (int i = 0; i < m_alpha.length; i++) {
double output = SVMOutput(i, m_data.instance(i));
if (Utils.eq(m_alpha[i], 0)) {
if (Utils.sm(m_class[i] * output, 1)) {
System.err.println("KKT condition 1 violated: " + m_class[i] * output);
}
}
if (Utils.gr(m_alpha[i], 0) &&
Utils.sm(m_alpha[i], m_C * m_data.instance(i).weight())) {
if (!Utils.eq(m_class[i] * output, 1)) {
System.err.println("KKT condition 2 violated: " + m_class[i] * output);
}
}
if (Utils.eq(m_alpha[i], m_C * m_data.instance(i).weight())) {
if (Utils.gr(m_class[i] * output, 1)) {
System.err.println("KKT condition 3 violated: " + m_class[i] * output);
}
}
}
}
示例15: 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);
}
}