/** * Returns the class probability distribution for an instance. * * @param instance the instance to be classified * * @return the distribution the forest generates for the instance * * @throws Exception if computation fails */ public double[] distributionForInstance(Instance instance) throws Exception{ if(m_ZeroR != null){ // default model? return m_ZeroR.distributionForInstance(instance); } return m_bagger.distributionForInstance(instance); }
/** * Returns the class probability distribution for an instance. * * @param instance the instance to be classified * * @return the distribution the forest generates for the instance * * @throws Exception if computation fails */ public double[] distributionForInstance(Instance instance) throws Exception{ if(m_ZeroR != null){ // default model? return m_ZeroR.distributionForInstance(instance); } return m_bagger.distributionForInstance(instance); }
protected void probability(Instance x) throws Exception { // cut out irrelevant attributes Instance copy = CCUtils.linkTransformation(x,this.exl,this._template); // classify int v = (int)Math.round(x.value(this.index)); // v = path[this.index] = 0 double dist[] = this.classifier.distributionForInstance(copy); // confidences[this.index] = dist[v]; // w_j = dist[v] = p(y_j == v) //y[this.index] = Utils.maxIndex(dist); // y_j = max_index(dist) <-- THE CLASSIFICATION!!! // (we used to pass this along as next.probability(x,y)) //carry on if (next!=null) next.probability(x); }
public Matrix predictOne(Matrix input) { try { double[] probabilities = null; Instance instance = new SampleToInstanceWrapper(input, null, null, discrete, true); instance.setDataset(instances); probabilities = wekaClassifier.distributionForInstance(instance); double[][] v = new double[1][]; v[0] = probabilities; Matrix output = Matrix.Factory.linkToArray(v); return output; } catch (Exception e) { throw new RuntimeException(e); } }
public double[][] call(){ final int numInstances = data.numInstances(); final int numOfClasses = data.numClasses(); final double[][] probabilityDistribution = new double[numOfClasses][numInstances]; for (int i=0; i<numInstances; i++) { try{ if (0 == i % 4000) counter.addAndGet(4000); double[] probs = classifier.distributionForInstance(data.instance(i)); for (int c = 0; c < numOfClasses; c++) probabilityDistribution[c][i] = probs[c]; }catch(Exception e){ IJ.showMessage("Could not apply Classifier!"); e.printStackTrace(); return null; } } return probabilityDistribution; } };
score = this.classifier.distributionForInstance(instance_i);
public double[][] call(){ final int numInstances = data.numInstances(); final int numOfClasses = data.numClasses(); final double[][] probabilityDistribution = new double[numOfClasses][numInstances]; for (int i=0; i<numInstances; i++) { try{ if (0 == i % 4000) counter.addAndGet(4000); double[] probs = classifier.distributionForInstance(data.instance(i)); for (int c = 0; c < numOfClasses; c++) probabilityDistribution[c][i] = probs[c]; }catch(Exception e){ IJ.showMessage("Could not apply Classifier!"); e.printStackTrace(); return null; } } return probabilityDistribution; } };
/** * Batch prediction method. This default implementation simply calls * distributionForInstance() for each instance in the batch. If subclasses can * produce batch predictions in a more efficient manner than this they should * override this method and also return true from * implementsMoreEfficientBatchPrediction() * * @param batch the instances to get predictions for * @return an array of probability distributions, one for each instance in the * batch * @throws Exception if a problem occurs. */ @Override public double[][] distributionsForInstances(Instances batch) throws Exception { double[][] batchPreds = new double[batch.numInstances()][]; for (int i = 0; i < batch.numInstances(); i++) { batchPreds[i] = distributionForInstance(batch.instance(i)); } return batchPreds; }
protected void sample(Instance x, Random r) throws Exception { // cut out irrelevant attributes Instance copy = CCUtils.linkTransformation(x,this.exl,this._template); // the pmf for the K classes, e.g. pmf( {1,2,3} ) = [0.3,0.3,0.4] ; pdf( {0,1} ) = [0.1,0.9] double dist[] = this.classifier.distributionForInstance(copy); // the chosen value k \in {1,2,3}, e.g. 3 ; k \in {0,1}, e.g. 1 int k = A.rndsrc(dist,r); // dist[k] confidences[this.index] = dist[k]; // w_j = dist[v] = p(y_j == v) x.setValue(this.index,k); // y_j = 0 //carry on if (next!=null) next.sample(x,r); }
/** * Batch prediction method. This default implementation simply calls * distributionForInstance() for each instance in the batch. If subclasses can * produce batch predictions in a more efficient manner than this they should * override this method and also return true from * implementsMoreEfficientBatchPrediction() * * @param batch the instances to get predictions for * @return an array of probability distributions, one for each instance in the * batch * @throws Exception if a problem occurs. */ @Override public double[][] distributionsForInstances(Instances batch) throws Exception { double[][] batchPreds = new double[batch.numInstances()][]; for (int i = 0; i < batch.numInstances(); i++) { batchPreds[i] = distributionForInstance(batch.instance(i)); } return batchPreds; }
double[] prob = classifier.distributionForInstance(data.get(i)); for(int k = 0 ; k < numClasses; k++) classificationResult[k][i] = prob[k];
double[] prob = classifier.distributionForInstance(data.get(i)); for(int k = 0 ; k < numClasses; k++) classificationResult[k][i] = prob[k];
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); }
public double classifyInstance(Instance instance) throws Exception { double[] dist = distributionForInstance(instance); if (dist == null) { throw new Exception("Null distribution predicted");
public double classifyInstance(Instance instance) throws Exception { double[] dist = distributionForInstance(instance); if (dist == null) { throw new Exception("Null distribution predicted");
double[] prob = classifier.distributionForInstance( ins ); for(int k = 0 ; k < numClasses; k++) classificationResult[k][i] = prob[k];
double[] prob = classifier.distributionForInstance( ins ); for(int k = 0 ; k < numClasses; k++) classificationResult[k][i] = prob[k];
protected void classify(Instance test) throws Exception { // copy Instance copy = (Instance)test.copy(); copy.setDataset(null); // delete attributes we don't need for(int i = excld.length-1; i >= 0; i--) { copy.deleteAttributeAt(this.excld[i]); } //set template copy.setDataset(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 = Utils.maxIndex(dist); confidences[this.index] = dist[max_index]; test.setValue(this.index,max_index); //carry on if (next!=null) next.classify(test); }
protected void classify(Instance test) throws Exception { // copy Instance copy = (Instance)test.copy(); copy.setDataset(null); // delete attributes we don't need for(int i = excld.length-1; i >= 0; i--) { copy.deleteAttributeAt(this.excld[i]); } //set template copy.setDataset(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 = Utils.maxIndex(dist); confidences[this.index] = dist[max_index]; test.setValue(this.index,max_index); //carry on if (next!=null) next.classify(test); }
protected void classify(Instance test) throws Exception { // copy Instance copy = (Instance)test.copy(); copy.setDataset(null); // delete attributes we don't need for(int i = excld.length-1; i >= 0; i--) { copy.deleteAttributeAt(this.excld[i]); } //set template copy.setDataset(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 = Utils.maxIndex(dist); confidences[this.index] = dist[max_index]; test.setValue(this.index,max_index); //carry on if (next!=null) next.classify(test); }