public abstract class Estimator extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable, OptionHandler, CapabilitiesHandler, CapabilitiesIgnorer, RevisionHandler
// create a histogram for estimation
EqualWidthEstimator est = new EqualWidthEstimator();
est.addValues(instances, attrIndex);
Example code for an incremental estimator (incremental estimators must
implement interface IncrementalEstimator)
// Create a discrete estimator that takes values 0 to 9
DiscreteEstimator newEst = new DiscreteEstimator(10, true);
// Create 50 random integers first predicting the probability of the
// value, then adding the value to the estimator
Random r = new Random(seed);
for(int i = 0; i < 50; i++) {
current = Math.abs(r.nextInt() % 10);
System.out.println(newEst);
System.out.println("Prediction for " + current
+ " = " + newEst.getProbability(current));
newEst.addValue(current, 1);
}
Example code for a main method for an estimator.
public static void main(String [] argv) {
try {
LoglikeliEstimator est = new LoglikeliEstimator();
Estimator.buildEstimator((Estimator) est, argv, false);
System.out.println(est.toString());
} catch (Exception ex) {
ex.printStackTrace();
System.out.println(ex.getMessage());
}
}
Constructor and Description |
---|
Estimator() |
Modifier and Type | Method and Description |
---|---|
void |
addValue(double data,
double weight)
Add a new data value to the current estimator.
|
void |
addValues(Instances data,
int attrIndex)
Initialize the estimator with a new dataset.
|
void |
addValues(Instances data,
int attrIndex,
double min,
double max,
double factor)
Initialize the estimator with all values of one attribute of a dataset.
|
void |
addValues(Instances data,
int attrIndex,
int classIndex,
int classValue)
Initialize the estimator using only the instances of one class.
|
void |
addValues(Instances data,
int attrIndex,
int classIndex,
int classValue,
double min,
double max)
Initialize the estimator using only the instances of one class.
|
static void |
buildEstimator(Estimator est,
Instances instances,
int attrIndex,
int classIndex,
int classValueIndex,
boolean isIncremental) |
static void |
buildEstimator(Estimator est,
java.lang.String[] options,
boolean isIncremental)
Build an estimator using the options.
|
static Estimator |
clone(Estimator model)
Creates a deep copy of the given estimator using serialization.
|
java.lang.String |
debugTipText()
Returns the tip text for this property
|
java.lang.String |
doNotCheckCapabilitiesTipText()
Returns the tip text for this property
|
boolean |
equals(java.lang.Object obj)
Tests whether the current estimation object is equal to another estimation
object
|
static Estimator |
forName(java.lang.String name,
java.lang.String[] options)
Creates a new instance of a estimator given it's class name and (optional)
arguments to pass to it's setOptions method.
|
Capabilities |
getCapabilities()
Returns the Capabilities of this Estimator.
|
boolean |
getDebug()
Get whether debugging is turned on.
|
boolean |
getDoNotCheckCapabilities()
Get whether capabilities checking is turned off.
|
java.lang.String[] |
getOptions()
Gets the current settings of the Estimator.
|
abstract double |
getProbability(double data)
Get a probability estimate for a value.
|
java.lang.String |
getRevision()
Returns the revision string.
|
java.util.Enumeration<Option> |
listOptions()
Returns an enumeration describing the available options.
|
static Estimator[] |
makeCopies(Estimator model,
int num)
Creates a given number of deep copies of the given estimator using
serialization.
|
static Estimator |
makeCopy(Estimator model)
Creates a deep copy of the given estimator using serialization.
|
void |
setDebug(boolean debug)
Set debugging mode.
|
void |
setDoNotCheckCapabilities(boolean doNotCheckCapabilities)
Set whether not to check capabilities.
|
void |
setOptions(java.lang.String[] options)
Parses a given list of options.
|
void |
testCapabilities(Instances data,
int attrIndex)
Test if the estimator can handle the data.
|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
makeCopy
public java.lang.String doNotCheckCapabilitiesTipText()
public void setDoNotCheckCapabilities(boolean doNotCheckCapabilities)
setDoNotCheckCapabilities
in interface CapabilitiesIgnorer
doNotCheckCapabilities
- true if capabilities are not to be checked.public boolean getDoNotCheckCapabilities()
getDoNotCheckCapabilities
in interface CapabilitiesIgnorer
public void addValue(double data, double weight)
data
- the new data valueweight
- the weight assigned to the data valuepublic void addValues(Instances data, int attrIndex) throws java.lang.Exception
data
- the dataset used to build this estimatorattrIndex
- attribute the estimator is forjava.lang.Exception
- if building of estimator goes wrongpublic void addValues(Instances data, int attrIndex, double min, double max, double factor) throws java.lang.Exception
data
- the dataset used to build this estimatorattrIndex
- attribute the estimator is formin
- minimal border of rangemax
- maximal border of rangefactor
- number of instances has been reduced to that factorjava.lang.Exception
- if building of estimator goes wrongpublic void addValues(Instances data, int attrIndex, int classIndex, int classValue) throws java.lang.Exception
data
- the dataset used to build this estimatorattrIndex
- attribute the estimator is forclassIndex
- index of the class attributeclassValue
- the class valuejava.lang.Exception
- if building of estimator goes wrongpublic void addValues(Instances data, int attrIndex, int classIndex, int classValue, double min, double max) throws java.lang.Exception
data
- the dataset used to build this estimatorattrIndex
- attribute the estimator is forclassIndex
- index of the class attributeclassValue
- the class valuemin
- minimal value of this attributemax
- maximal value of this attributejava.lang.Exception
- if building of estimator goes wrongpublic abstract double getProbability(double data)
data
- the value to estimate the probability ofpublic static void buildEstimator(Estimator est, java.lang.String[] options, boolean isIncremental) throws java.lang.Exception
est
- the estimator usedoptions
- the list of optionsisIncremental
- true if estimator is incrementaljava.lang.Exception
- if something goes wrong or the user requests help on
command optionspublic static void buildEstimator(Estimator est, Instances instances, int attrIndex, int classIndex, int classValueIndex, boolean isIncremental) throws java.lang.Exception
java.lang.Exception
public static Estimator clone(Estimator model) throws java.lang.Exception
model
- the estimator to copyjava.lang.Exception
- if an error occurspublic static Estimator makeCopy(Estimator model) throws java.lang.Exception
model
- the estimator to copyjava.lang.Exception
- if an error occurspublic static Estimator[] makeCopies(Estimator model, int num) throws java.lang.Exception
model
- the estimator to copynum
- the number of estimator copies to create.java.lang.Exception
- if an error occurspublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the object to compare againstpublic java.util.Enumeration<Option> listOptions()
listOptions
in interface OptionHandler
public void setOptions(java.lang.String[] options) throws java.lang.Exception
-D
If set, estimator is run in debug mode and may output additional info to
the console.
-do-not-check-capabilities
If set, estimator capabilities are not checked before estimator is built
(use with caution).
setOptions
in interface OptionHandler
options
- the list of options as an array of stringsjava.lang.Exception
- if an option is not supportedpublic java.lang.String[] getOptions()
getOptions
in interface OptionHandler
public static Estimator forName(java.lang.String name, java.lang.String[] options) throws java.lang.Exception
name
- the fully qualified class name of the estimatoroptions
- an array of options suitable for passing to setOptions. May
be null.java.lang.Exception
- if the estimator name is invalid, or the options
supplied are not acceptable to the estimatorpublic void setDebug(boolean debug)
debug
- true if debug output should be printedpublic boolean getDebug()
public java.lang.String debugTipText()
public Capabilities getCapabilities()
getCapabilities
in interface CapabilitiesHandler
Capabilities
public java.lang.String getRevision()
getRevision
in interface RevisionHandler
public void testCapabilities(Instances data, int attrIndex) throws java.lang.Exception
data
- the dataset the estimator takes an attribute fromattrIndex
- the index of the attributejava.lang.Exception
Capabilities