public class CosineSimilarity extends FunctionMetric
Cosine Similarity
evaluation. The function uses Math.cos
and so it needs to convert to double
values at some stage. It can return null for invalid data.
If each dataset has only one (list) object, it is passed to the evaluation function as it is.
If the objects are double arrays
, then they can be processed as is, without using the metric objects.
The desired result is a larger 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 |
---|
CosineSimilarity()
Create a new instance of CosineSimilarity.
|
CosineSimilarity(java.lang.String thisValueType)
Create a new instance of CosineSimilarity.
|
Modifier and Type | Method and Description |
---|---|
double |
evaluate(double[] ds1,
double[] ds2)
Evaluate the comparison between the two data lists and return the result.
|
ReplySet |
evaluate(MetricDataset ds1,
MetricDataset ds2)
Evaluate the comparison between the two data lists 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 CosineSimilarity() throws java.lang.Exception
java.lang.Exception
- any error.public CosineSimilarity(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.ds2
- second value dataset.java.lang.Exception
- any error.public double evaluate(double[] ds1, double[] ds2) throws java.lang.Exception
ds1
- first value dataset.ds2
- second value dataset.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.