org.bigml.binding.MultiVoteList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bigml-binding Show documentation
Show all versions of bigml-binding Show documentation
An open source Java client that gives you a simple binding to interact with BigML. You can use it to
easily create, retrieve, list, update, and delete BigML resources.
package org.bigml.binding;
import org.bigml.binding.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* A multiple vote prediction in compact format
*
* Uses a number of predictions to generate a combined prediction.
* The input should be an ordered list of probability, counts or confidences
* for each of the classes in the objective field.
*/
public class MultiVoteList implements Serializable {
private static final long serialVersionUID = 1L;
/**
* Logging
*/
static Logger LOGGER = LoggerFactory.getLogger(MultiVoteList.class.getName());
ArrayList> predictions;
/**
* Init method, builds a MultiVoteList with a list of predictions
* The constuctor expects a list of well formed predictions like:
* [0.2, 0.34, 0.48] which might correspond to confidences of
* three different classes in the objective field.
*
* @param predictions {array|object} predictions Array of model's predictions
*/
public MultiVoteList(ArrayList> predictions) {
if (predictions == null) {
predictions = new ArrayList>();
}
this.predictions = predictions;
}
/**
* Extending the extend method in lists
*/
public void extend(ArrayList> predictionList) {
this.predictions.addAll(predictionList);
}
/**
* Extending the extend method in lists
*/
public void extend(MultiVoteList predictionList) {
this.predictions.addAll(predictionList.predictions);
}
/**
* Extending the append method in lists
*/
public void append(List prediction) {
this.predictions.add(prediction);
}
/**
* Receives a list of lists. Each element is the list of
* probabilities or confidences associated to each class in the
* ensemble, as described in the `class_names` attribute and ordered
* in the same sequence. Returns the probability obtained by adding
* these predictions into a single one by adding their probabilities
* and normalizing.
*/
public List combineToDistribution(Boolean normalize) {
if (normalize == null) {
normalize = true;
}
double total = 0.0;
Double[] output = new Double[predictions.get(0).size()];
for (int i=0; i dist = (List) distribution;
for (int i=0; i
© 2015 - 2024 Weber Informatics LLC | Privacy Policy