public class KullbackLeibler extends FunctionMetric
Kullback-Leibler
divergence going from dataset2 to dataset1.
The function uses MathStat.logBaseTwo
and so the data points should be of type
Float or Double
. The desired result is a smaller distance, but you can use the
isBetter()
method to determine what value is better. Null can be returned for invalid data.config, mathCompare, valueType
Constructor and Description |
---|
KullbackLeibler()
Create a new instance of Kullback-Leibler.
|
KullbackLeibler(java.lang.String thisValueType)
Create a new instance of Kullback-Leibler.
|
Modifier and Type | Method and Description |
---|---|
double |
evaluate(double[] p,
double[] q)
Evaluate the Kullback-Leibler divergence going from q to p.
|
ReplySet |
evaluate(MetricDataset ds1,
MetricDataset ds2)
Evaluate the comparison of the two vectors of data and return the result.
|
protected void |
initialise()
Initialise the function values, setting the config parameters or other.
|
boolean |
isBetter(java.lang.String valueType,
java.lang.Object value1,
java.lang.Object value2)
Return true if value2 is better than value1, as determined by the measurements of
this evaluation function.
|
FunctionMetric |
newInstance()
Create and return a new instance of the function, initialised with this function's
value type
valueType and mathOperation evaluator mathCompare . |
boolean |
sib()
Return true if a smaller distance between the two vectors is better.
|
evaluateCompare, lib
checkValueType, createFunction, createFunction, createFunction, evaluate, getConfigParams, innerObject, isLegalNumber, setConfigParams, setEvaluator, setValueType
public KullbackLeibler() throws java.lang.Exception
java.lang.Exception
- any error.public KullbackLeibler(java.lang.String thisValueType) throws java.lang.Exception
thisValueType
- the type of object being evaluated.java.lang.Exception
- any error.protected void initialise() throws java.lang.Exception
initialise
in class Function
java.lang.Exception
- any error.public ReplySet evaluate(MetricDataset ds1, MetricDataset ds2) throws java.lang.Exception
evaluate
in interface FunctionMetricDef
evaluate
in class FunctionMetric
ds1
- first value dataset. This should store a list of sample (Float or Double
) values.ds2
- second value dataset. This should store a list of base (Float or Double
) values.java.lang.Exception
- any error.public double evaluate(double[] p, double[] q) throws java.lang.Exception
p
- first set of probability values.q
- second set of probability values.java.lang.Exception
- any error.public boolean isBetter(java.lang.String valueType, java.lang.Object value1, java.lang.Object value2) throws java.lang.Exception
isBetter
in class FunctionMetric
valueType
- the java type of the values to be evaluated.value1
- the first value type.value2
- the second value type.java.lang.Exception
- any error.public boolean sib()
sib
in class FunctionMetric
public FunctionMetric newInstance() throws java.lang.Exception
valueType
and mathOperation evaluator mathCompare
.newInstance
in class FunctionMetric
java.lang.Exception
- any error.