|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweka.classifiers.meta.ensembleSelection.ModelBag
public class ModelBag
This class is responsible for the duties of a bag of models. It is designed for use with the EnsembleSelection meta classifier. It handles shuffling the models, doing sort initialization, performing forward selection/ backwards elimination, etc.
We utilize a simple "virtual indexing" scheme inside. If we shuffle and/or sort the models, we change the "virtual" order around. The elements of the bag are always those elements with virtual index 0..(m_bagSize-1). Each "virtual" index maps to some real index in m_models. Not every model in m_models gets a virtual index... the virtual indexing is what defines the subset of models of which our Bag is composed. This makes it easy to refer to models in the bag, by their virtual index, while maintaining the original indexing for our clients.
Constructor Summary | |
---|---|
ModelBag(double[][][] models,
double bag_percent,
boolean debug)
Constructor for ModelBag. |
Method Summary | |
---|---|
void |
backwardEliminate(Instances instances,
int metric)
Find the model whose removal will help the ensemble's performance the most, and remove it. |
void |
forwardSelect(boolean withReplacement,
Instances instances,
int metric)
Forward select one model. |
void |
forwardSelectOrBackwardEliminate(boolean with_replacement,
Instances instances,
int metric)
Find the best action to perform, be it adding a model or removing a model, and perform it. |
double[] |
getIndividualPerformance(Instances instances,
int metric)
Gets the individual performances of all the models in the bag. |
int[] |
getModelWeights()
returns the model weights |
void |
shuffle(java.util.Random rand)
Shuffle the models. |
int[] |
sortInitialize(int num,
boolean greedy,
Instances instances,
int metric)
Sort initialize the bag. |
void |
weightAll(int weight)
Add "weight" to the number of times each model in the bag was chosen. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ModelBag(double[][][] models, double bag_percent, boolean debug)
models
- The complete set of models from which to draw our bag. First
index is for the model, second is for the instance. The last
is a prediction distribution for that instance. Models are
represented by this array of predictions for validation data,
since that's all ensemble selection needs to know.bag_percent
- The percentage of the set of given models that should be used
in the Model Bag.debug
- Whether the ModelBag should print debug information.Method Detail |
---|
public void shuffle(java.util.Random rand)
rand
- the random number generator to usepublic int[] sortInitialize(int num, boolean greedy, Instances instances, int metric) throws java.lang.Exception
num
- the Maximum number of models to initialize withgreedy
- True if we do greedy addition, up to num. Greedy sort
initialization adds models (up to num) in order of best to
worst performance until performance no longer improves.instances
- the data set (needed for performance evaluation)metric
- metric for which to optimize. See EnsembleMetricHelper
java.lang.Exception
- if something goes wrongpublic void weightAll(int weight)
weight
- the weight to addpublic void forwardSelect(boolean withReplacement, Instances instances, int metric) throws java.lang.Exception
withReplacement
- whether a model can be added more than once.instances
- The dataset, for calculating performance.metric
- The metric to which we will optimize. See EnsembleMetricHelper
java.lang.Exception
- if something goes wrongpublic void backwardEliminate(Instances instances, int metric) throws java.lang.Exception
instances
- The data set, for calculating performancemetric
- Metric to optimize for. See EnsembleMetricHelper.
java.lang.Exception
- if something goes wrongpublic void forwardSelectOrBackwardEliminate(boolean with_replacement, Instances instances, int metric) throws java.lang.Exception
with_replacement
- whether we can add a model more than onceinstances
- The dataset, for determining performance.metric
- The metric for which to optimize. See EnsembleMetricHelper.
java.lang.Exception
- if something goes wrongpublic int[] getModelWeights()
public double[] getIndividualPerformance(Instances instances, int metric) throws java.lang.Exception
instances
- The validation data, for which we want performance.metric
- The desired metric (see EnsembleMetricHelper).
java.lang.Exception
- if something goes wrong
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |