@Override public double[] getVotesForInstance(Instance samoaInstance) { weka.core.Instance inst = this.instanceConverter.wekaInstance(samoaInstance); double[] votes = new double[inst.numClasses()]; if (isClassificationEnabled == false) { for (int i = 0; i < inst.numClasses(); i++) { votes[i] = 1.0 / inst.numClasses(); } } else { try { votes = this.classifier.distributionForInstance(inst); } catch (Exception e) { System.err.println(e.getMessage()); } } return votes; }
/** * Returns class probabilities for a weighted instance. * * @exception Exception if something goes wrong */ public final double[] distributionForInstance(Instance instance) throws Exception { double[] doubles = new double[instance.numClasses()]; for (int i = 0; i < doubles.length; i++) { doubles[i] = getProbs(i, instance, 1); } return doubles; }
/** * Returns class probabilities for a weighted instance. * * @exception Exception if something goes wrong */ public final double[] distributionForInstance(Instance instance) throws Exception { double[] doubles = new double[instance.numClasses()]; for (int i = 0; i < doubles.length; i++) { doubles[i] = getProbs(i, instance, 1); } return doubles; }
@Override public double[] distributionForInstance(Instance test) throws Exception { double[] result = new double[test.numClasses()]; int pred = 0; result[pred] = m_Preds[m_Pos]; double residual = (1.0 - result[pred]) / (result.length - 1); for (int i = 0; i < result.length; i++) { if (i != pred) { result[i] = residual; } } m_Pos = (m_Pos + 1) % m_Preds.length; return result; }
@Override public double[] distributionForInstance(Instance test) throws Exception { double[] result = new double[test.numClasses()]; int pred = 0; result[pred] = m_Preds[m_Pos]; double residual = (1.0 - result[pred]) / (result.length - 1); for (int i = 0; i < result.length; i++) { if (i != pred) { result[i] = residual; } } m_Pos = (m_Pos + 1) % m_Preds.length; return result; }
/** * Calculates the class membership probabilities for the given test * instance. * * @param instance the instance to be classified * @return predicted class probability distribution */ public double[] distributionForInstance(Instance instance) { double[] sums = new double[instance.numClasses()], newProbs; for (int i=0; i < numTrees; i++) { newProbs = tree[i].evaluate(instance); for (int j = 0; j < newProbs.length; j++) sums[j] += newProbs[j]; } // Divide by the number of trees for (int j = 0; j < sums.length; j++) sums[j] /= (double) numTrees; return sums; }
/** * Calculates the class membership probabilities for the given test * instance. * * @param instance the instance to be classified * @return predicted class probability distribution */ public double[] distributionForInstance(Instance instance) { double[] sums = new double[instance.numClasses()], newProbs; for (int i=0; i < numTrees; i++) { newProbs = tree[i].evaluate(instance); for (int j = 0; j < newProbs.length; j++) sums[j] += newProbs[j]; } // Divide by the number of trees for (int j = 0; j < sums.length; j++) sums[j] /= (double) numTrees; return sums; }
/** * 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; }
/** * Returns class probabilities for a weighted instance. * * @param instance the instance to get the distribution for * @param useLaplace whether to use laplace or not * @return the distribution * @throws Exception if something goes wrong */ public final double[] distributionForInstance(Instance instance, boolean useLaplace) throws Exception { double[] doubles = new double[instance.numClasses()]; for (int i = 0; i < doubles.length; i++) { if (!useLaplace) { doubles[i] = getProbs(i, instance, 1); } else { doubles[i] = getProbsLaplace(i, instance, 1); } } return doubles; }
/** * 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; }
/** * Returns class probabilities for a weighted instance. * * @param instance the instance to get the distribution for * @param useLaplace whether to use laplace or not * @return the distribution * @throws Exception if something goes wrong */ public final double[] distributionForInstance(Instance instance, boolean useLaplace) throws Exception { double[] doubles = new double[instance.numClasses()]; for (int i = 0; i < doubles.length; i++) { if (!useLaplace) { doubles[i] = getProbs(i, instance, 1); } else { doubles[i] = getProbsLaplace(i, instance, 1); } } return doubles; }
/** * 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; }
/** * 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; }
/** * 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)) && (i < theRules.size())) { 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; }
/** * 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; } }
/** * 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; } }
/** * 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); } }
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); //if there is only one class (as for e.g. in some hier. mtds) predict it if(L == 1) return new double[]{1.0}; Instance x_ = PSUtils.convertInstance(x,L,m_InstancesTemplate); //convertInstance(x,L); x_.setDataset(m_InstancesTemplate); //Get a classification double y[] = new double[x_.numClasses()]; y[(int)m_Classifier.classifyInstance(x_)] = 1.0; return PSUtils.convertDistribution(y,L,m_InstancesTemplate); }
@Override public double[] distributionForInstance(Instance mlInstance) throws Exception { int c = mlInstance.classIndex(); //if there is only one class (as for e.g. in some hier. mtds) predict it if(c == 1) return new double[]{1.0}; Instance slInstance = convertInstance(mlInstance,c); slInstance.setDataset(m_InstancesTemplate); //Get a classification double result[] = new double[slInstance.numClasses()]; result[(int)m_Classifier.classifyInstance(slInstance)] = 1.0; return convertDistribution(result,c); }
@Override public double[] distributionForInstance(Instance x) throws Exception { int L = x.classIndex(); //if there is only one class (as for e.g. in some hier. mtds) predict it if(L == 1) return new double[]{1.0}; Instance x_ = PSUtils.convertInstance(x,L,m_InstancesTemplate); //convertInstance(x,L); x_.setDataset(m_InstancesTemplate); //Get a classification double y[] = new double[x_.numClasses()]; y[(int)m_Classifier.classifyInstance(x_)] = 1.0; return PSUtils.convertDistribution(y,L,m_InstancesTemplate); }