本文整理了Java中weka.core.Utils.maxIndex()
方法的一些代码示例,展示了Utils.maxIndex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.maxIndex()
方法的具体详情如下:
包路径:weka.core.Utils
类名称:Utils
方法名:maxIndex
[英]Returns index of maximum element in a given array of doubles. First maximum is returned.
[中]返回给定双精度数组中最大元素的索引。返回第一个最大值。
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
double eval(double[] args) {
return args[Utils.maxIndex(args)];
}
代码示例来源:origin: Waikato/weka-trunk
double eval(double[] args) {
return args[Utils.maxIndex(args)];
}
代码示例来源:origin: net.sf.meka/meka
/**
* Convert Distribution - Given the posterior across combinations, return the distribution across labels.
* @param p the posterior of the super classes (combinations), e.g., P([1,3],[2]) = [1,0]
* @param L the number of labels
* @return the distribution across labels, e.g., P(1,2,3) = [1,0,1]
*/
public static final double[] recombination(double p[], int L, LabelSet map[]) {
double y[] = new double[L];
int i = Utils.maxIndex(p);
LabelSet y_meta = map[i];
for(int j : y_meta.indices) {
y[j] = 1.0;
}
return y;
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Computes log of density for given value.
*/
public double logDensity(double value) {
double[] a = logJointDensities(value);
double max = a[Utils.maxIndex(a)];
double sum = 0.0;
for(int i = 0; i < a.length; i++) {
sum += Math.exp(a[i] - max);
}
return max + Math.log(sum);
}
代码示例来源:origin: nz.ac.waikato.cms.moa/moa
@Override
public double[] getClassVotes(Instance instance) {
double[] votes = super.getClassVotes(instance);
this.lastPrediction = Utils.maxIndex(votes);
return votes;
}
代码示例来源:origin: Waikato/weka-trunk
/**
* Computes log of density for given value.
*/
public double logDensity(double value) {
double[] a = logJointDensities(value);
double max = a[Utils.maxIndex(a)];
double sum = 0.0;
for(int i = 0; i < a.length; i++) {
sum += Math.exp(a[i] - max);
}
return max + Math.log(sum);
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Returns the value as string out of the given distribution
*
* @param c the attribute to get the value for
* @param dist the distribution to extract the value
* @return the value
*/
protected String sourceClass(Attribute c, double []dist) {
if (c.isNominal()) {
return Integer.toString(Utils.maxIndex(dist));
} else {
return Double.toString(dist[0]);
}
}
代码示例来源:origin: Waikato/weka-trunk
/**
* Returns the value as string out of the given distribution
*
* @param c the attribute to get the value for
* @param dist the distribution to extract the value
* @return the value
*/
protected String sourceClass(Attribute c, double []dist) {
if (c.isNominal()) {
return Integer.toString(Utils.maxIndex(dist));
} else {
return Double.toString(dist[0]);
}
}
代码示例来源:origin: nz.ac.waikato.cms.moa/moa
@Override
public double[] getVotesForInstance(Instance inst) {
double[] Pr = new double[inst.numClasses()];
for (int i = 0; i < this.experts.size(); i++) {
double[] pr = this.experts.get(i).getVotesForInstance(inst);
int yHat = Utils.maxIndex(pr);
Pr[yHat] += this.weights.get(i);
} // for
Utils.normalize(Pr);
return Pr;
}
代码示例来源:origin: Waikato/meka
/**
* Return the argmax on #distribution(Instance, double[]).
* @return argmax_{k in 0,1,...} p( y_j = k | x , y_pred )
*/
public double classify(Instance x, double ypred[]) throws Exception {
Instance x_ = transform(x,ypred);
return Utils.maxIndex(h.distributionForInstance(x_));
}
代码示例来源:origin: net.sf.meka/meka
/**
* Return the argmax on #distribution(Instance, double[]).
* @return argmax_{k in 0,1,...} p( y_j = k | x , y_pred )
*/
public double classify(Instance x, double ypred[]) throws Exception {
Instance x_ = transform(x,ypred);
return Utils.maxIndex(h.distributionForInstance(x_));
}
代码示例来源:origin: nz.ac.waikato.cms.moa/moa
@Override
public Node learnFromInstance(Instance inst) {
double[] classVotes = getMajorityClassVotes(inst);
double error = (Utils.maxIndex(classVotes) == (int) inst.classValue()) ? 0.0 : 1.0;
this.majorityClassError += error;
classVotes = getNaiveBayesPrediction(inst);
error = (Utils.maxIndex(classVotes) == (int) inst.classValue()) ? 0.0 : 1.0;
this.naiveBayesError += error;
return super.learnFromInstance(inst);
}
代码示例来源:origin: nz.ac.waikato.cms.moa/moa
@Override
public Node learnFromInstance(Instance inst) {
double[] classVote = getMajorityClassVotes(inst);
double error = (Utils.maxIndex(classVote) == (int) inst.classValue()) ? 0.0 : 1.0;
this.majorityClassError.input(error);
classVote = getNaiveBayesPrediction(inst);
error = (Utils.maxIndex(classVote) == (int) inst.classValue()) ? 0.0 : 1.0;
this.naiveBayesError.input(error);
return super.learnFromInstance(inst);
}
代码示例来源:origin: nz.ac.waikato.cms.moa/moa
private void updateCounters(Instance experiencia) {
double[] classVotes = this.getClassVotes(experiencia);
boolean trueClass = (Utils.maxIndex(classVotes) == (int) experiencia.classValue());
if (estimator != null && ((Iadem3) this.tree).restartAtDrift) {
double error = trueClass == true ? 0.0 : 1.0;
this.estimator.input(error);
if (this.estimator.getChange()) {
this.restartVariablesAtDrift();
}
}
}
代码示例来源:origin: nz.ac.waikato.cms.moa/moa
private void updateCountersForChange(Instance inst) {
double[] classVotes = this.getClassVotes(inst);
boolean trueClass = (Utils.maxIndex(classVotes) == (int) inst.classValue());
if (estimador != null && ((Iadem3) this.tree).restartAtDrift) {
double error = trueClass == true ? 0.0 : 1.0;
this.estimador.input(error);
if (this.estimador.getChange()) {
this.resetVariablesAtDrift();
}
}
}
代码示例来源:origin: nz.ac.waikato.cms.weka/meka
protected void classify(Instance x) throws Exception {
// cut out irrelevant attributes
Instance copy = CCUtils.linkTransformation(x,this.exl,this._template);
// round
for(int k = 0; k < this.j; k++) {
copy.setValue(j,Math.round(copy.value(k)));
}
//set class
double dist[] = this.classifier.distributionForInstance(copy);
int max_index = (int)Utils.maxIndex(dist); // v = max_index(dist)
confidences[this.index] = dist[max_index]; // w_j = dist[v] = p(y_j == v)
x.setValue(this.index,max_index); // y_j = 0
//carry on
if (next!=null) next.classify(x);
}
代码示例来源:origin: nz.ac.waikato.cms.moa/moa
private void updateCounters(Instance inst) {
double[] classVotes = this.getClassVotes(inst);
boolean correct = (Utils.maxIndex(classVotes) == (int) inst.classValue());
if (this.estimator != null && ((Iadem3) this.tree).restartAtDrift) {
double error = correct == true ? 0.0 : 1.0;
this.estimator.input(error);
if (this.estimator.getChange()) {
this.resetVariablesAtDrift();
}
}
}
代码示例来源:origin: nz.ac.waikato.cms.weka/meka
@Override
public double[] distributionForInstance(Instance x) throws Exception {
int L = x.classIndex();
double y[] = new double[L*2];
for (int j = 0; j < L; j++) {
Instance x_j = (Instance)x.copy();
x_j.setDataset(null);
x_j = MLUtils.keepAttributesAt(x_j,new int[]{j},L);
x_j.setDataset(m_Templates[j]);
double w[] = m_MultiClassifiers[j].distributionForInstance(x_j); // e.g. [0.1, 0.8, 0.1]
y[j] = Utils.maxIndex(w); // e.g. 1
y[L+j] = w[(int)y[j]]; // e.g. 0.8
}
return y;
}
代码示例来源:origin: net.sf.meka/meka
@Override
public double[] distributionForInstance(Instance x) throws Exception {
int L = x.classIndex();
double y[] = new double[L*2];
for (int j = 0; j < L; j++) {
Instance x_j = (Instance)x.copy();
x_j.setDataset(null);
x_j = MLUtils.keepAttributesAt(x_j,new int[]{j},L);
x_j.setDataset(m_Templates[j]);
double w[] = m_MultiClassifiers[j].distributionForInstance(x_j); // e.g. [0.1, 0.8, 0.1]
y[j] = Utils.maxIndex(w); // e.g. 1
y[L+j] = w[(int)y[j]]; // e.g. 0.8
}
return y;
}
代码示例来源:origin: Waikato/meka
@Override
public double[] distributionForInstance(Instance x) throws Exception {
int L = x.classIndex();
double y[] = new double[L*2];
for (int j = 0; j < L; j++) {
Instance x_j = (Instance)x.copy();
x_j.setDataset(null);
x_j = MLUtils.keepAttributesAt(x_j,new int[]{j},L);
x_j.setDataset(m_Templates[j]);
double w[] = m_MultiClassifiers[j].distributionForInstance(x_j); // e.g. [0.1, 0.8, 0.1]
y[j] = Utils.maxIndex(w); // e.g. 1
y[L+j] = w[(int)y[j]]; // e.g. 0.8
}
return y;
}
内容来源于网络,如有侵权,请联系作者删除!