double eval(double[] args) { return args[Utils.maxIndex(args)]; }
double eval(double[] args) { return args[Utils.maxIndex(args)]; }
/** * 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; }
/** * 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); }
@Override public double[] getClassVotes(Instance instance) { double[] votes = super.getClassVotes(instance); this.lastPrediction = Utils.maxIndex(votes); return votes; }
/** * 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); }
/** * 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]); } }
/** * 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]); } }
@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; }
/** * 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_)); }
/** * 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_)); }
@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); }
@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); }
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(); } } }
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(); } } }
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); }
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(); } } }
@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; }
@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; }
@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; }