de.dfki.mycbr.core.similarity
Class DoubleFct

java.lang.Object
  extended by java.util.Observable
      extended by de.dfki.mycbr.core.similarity.NumberFct
          extended by de.dfki.mycbr.core.similarity.DoubleFct
All Implemented Interfaces:
ISimFct, java.util.Observer

public class DoubleFct
extends NumberFct

Calculates the similarity of DoubleAttribute objects. There are four modes which can be chosen for the similarity function:

You have to configure the similarity for two cases: If the function is symmetric, the configurations should be the same. The similarity of a value to itself is assumed to be 1.00 in any case.

Author:
myCBR Team

Constructor Summary
DoubleFct(Project prj, DoubleDesc desc, java.lang.String name)
          Constructor should only be called by FunctionContainer.
 
Method Summary
 Similarity calculateSimilarity(Attribute a1, Attribute a2)
          Returns the similarity of the given attributes.
 Similarity calculateSimilarity(java.lang.Double value1, java.lang.Double value2)
          Calculates the similarity of the given Floats.
 void clone(AttributeDesc descNEW, boolean active)
          Creates a new function which is the same function as this but with a different description, namely descNEW.
 boolean fitsDistance(double x)
           
 double getDiff()
           
 double getFunctionParameterL()
          Gets the function's parameter for case < query to value.
 double getFunctionParameterR()
          Gets the function's parameter for query < case to value.
 NumberConfig getFunctionTypeL()
           
 NumberConfig getFunctionTypeR()
           
 double getMax()
           
 double getMaxForQuotient()
           
 double getMin()
           
 void setDistanceFct(DistanceConfig df)
          Sets the mode of this function to mode
 boolean setFunctionParameterL(double value)
          Sets the function's parameter for query < case to value.
 boolean setFunctionParameterR(double value)
          Sets the function's parameter for query < case to value.
 void setFunctionTypeL(NumberConfig type)
          Sets the type of the function for case < query.
 void setFunctionTypeR(NumberConfig type)
          Sets the type of the function for query < case.
 void setMaxForQuotient(double max)
           
 void update(java.util.Observable arg0, java.lang.Object arg1)
           
 void updateFunctionParams()
           
 
Methods inherited from class de.dfki.mycbr.core.similarity.NumberFct
getDesc, getDistanceFct, getMultipleConfig, getName, getProject, isSymmetric, setMultipleConfig, setName, setSymmetric
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DoubleFct

public DoubleFct(Project prj,
                 DoubleDesc desc,
                 java.lang.String name)
Constructor should only be called by FunctionContainer. Initializes this with the given description.

Parameters:
desc - the description of the attributes this function can be applied to
Method Detail

calculateSimilarity

public Similarity calculateSimilarity(Attribute a1,
                                      Attribute a2)
                               throws java.lang.Exception
Returns the similarity of the given attributes. Returns invalid similarity if an error occurs. The similarity computation depends on the type of the function and it's parameter. We refer to the right part of the function if case < query and to the left part otherwise. The possible computations are:

Parameters:
a1 - the first value
a2 - the second value
Returns:
Similarity of the given attributes, invalid similarity if an error occurs.
Throws:
java.lang.Exception

calculateSimilarity

public Similarity calculateSimilarity(java.lang.Double value1,
                                      java.lang.Double value2)
                               throws java.lang.Exception
Calculates the similarity of the given Floats. Calls calculateSimilarity(Attribute, Attribute). Be aware that calculateSimilarity(value1, values2) might differ from calculateSimilarity(value2, values1). When calculating similarities, the first attribute is always referred to as the query value, the second parameter as the case value.

Parameters:
value1 - the first attribute to be compared
value2 - the second attribute to be compared
Returns:
similarity of the given attributes
Throws:
java.lang.Exception

setFunctionParameterR

public boolean setFunctionParameterR(double value)
Sets the function's parameter for query < case to value. The function parameter depends on the type of the function. The parameter specifies: If the parameter for "smooth step" or "step at" does not fit the range given by max/min, the parameter will not be updated. If the parameter for "constant" is not within the range (0.0,1.0), the parameter will not be updated. Or if the parameter for "polynomial with" is smaller than 0 the parameter will not be updated. Be aware to set the function type before setting the parameter, because the parameter depends on the current function type.

Parameters:
value - the function parameter for query < case
Returns:
true, if the parameter was successfully updated, false otherwise

setFunctionParameterL

public boolean setFunctionParameterL(double value)
Sets the function's parameter for query < case to value. The function parameter depends on the type of the function. The parameter specifies: If the parameter for "smooth step" or "step at" does not fit the range given by max/min, the parameter will not be updated. If the parameter for "constant" is not within the range (0.0,1.0), the parameter will not be updated. Or if the parameter for "polynomial with" is smaller than 0 the parameter will not be updated. Be aware to set the function type before setting the parameter, because the parameter depends on the current function type.

Parameters:
value - the function parameter for query < case
Returns:
true, if the parameter was successfully updated, false otherwise

getFunctionParameterR

public double getFunctionParameterR()
Gets the function's parameter for query < case to value. The function parameter depends on the type of the function. The parameter specifies:

Returns:
the function parameter for query < case

getFunctionParameterL

public double getFunctionParameterL()
Gets the function's parameter for case < query to value. The function parameter depends on the type of the function. The parameter specifies:

Returns:
the function parameter for case < query

setFunctionTypeR

public void setFunctionTypeR(NumberConfig type)
Sets the type of the function for query < case. Updates function parameter if necessary. Be aware to set the function type before setting the parameter, because the parameter depends on the current function type.

Parameters:
type - the type of the function

setFunctionTypeL

public void setFunctionTypeL(NumberConfig type)
Sets the type of the function for case < query. Updates function parameter if necessary. Be aware to set the function type before setting the parameter, because the parameter depends on the current function type.

Parameters:
type - the type of the function

getFunctionTypeL

public NumberConfig getFunctionTypeL()

getFunctionTypeR

public NumberConfig getFunctionTypeR()

getMin

public double getMin()

getMax

public double getMax()

getDiff

public double getDiff()

setDistanceFct

public void setDistanceFct(DistanceConfig df)
Description copied from class: NumberFct
Sets the mode of this function to mode

Overrides:
setDistanceFct in class NumberFct
Parameters:
df - the new mode of this function

clone

public void clone(AttributeDesc descNEW,
                  boolean active)
Description copied from interface: ISimFct
Creates a new function which is the same function as this but with a different description, namely descNEW. Assumption: this function fits the description of descNEW.


update

public void update(java.util.Observable arg0,
                   java.lang.Object arg1)

updateFunctionParams

public void updateFunctionParams()

fitsDistance

public boolean fitsDistance(double x)
Parameters:
x - a value to be checked
Returns:
true, if x is still in the domain defined by desc wrt to the given distance function

getMaxForQuotient

public double getMaxForQuotient()

setMaxForQuotient

public void setMaxForQuotient(double max)