com.rubecula.darwin.foundation
Class Function_

java.lang.Object
  extended by com.rubecula.darwin.foundation.Function_
All Implemented Interfaces:
Function, com.rubecula.jexpression.EvalExpression, com.rubecula.jexpression.EvalExpressionMutable, com.rubecula.jexpression.Valuable, net.sf.tostring0.Identifiable
Direct Known Subclasses:
FitnessFunction_, Function_Choosy, Function_Desirable

public abstract class Function_
extends java.lang.Object
implements Function, com.rubecula.jexpression.EvalExpressionMutable

This is the base class for all functions which can be implemented by evaluating an expression via an Evaluator. The methods operate generally by delegation to the evaluator field.

Author:
Robin Hillyard

Field Summary
protected  com.rubecula.jexpression.Evaluator evaluator
           
protected static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
protected Function_()
          Protected constructor to construct a Function_ with no evaluator.
protected Function_(com.rubecula.jexpression.Evaluator evaluator)
          Protected constructor to construct a Function_ with given evaluator.
 
Method Summary
 void addListener(FunctionListener listener)
          Method to add a function listener.
protected  java.lang.Number addSymbol(java.lang.String name, java.lang.Number value)
          Delegate to evaluator TEST
 boolean equals(java.lang.Object obj)
          WARNING: do not rewrite this method unless you really know what you are doing!
protected  java.lang.Number evaluate(java.lang.Object... parameters)
          Evaluate the function based on the variables passed in as parameters.
protected  java.lang.Object getErrorInfo()
           
protected  com.rubecula.jexpression.Evaluator getEvaluator()
           
 java.lang.String getExpression()
          If getEvaluator() returns an EvalExpression, delegate to it.
protected  ExpressionMap getExpressionMap()
           
 com.rubecula.jexpression.Term[] getExpressionTerms()
          If getEvaluator() returns an EvalExpression, delegate to it.
 java.lang.Number getValue()
          Delegate to evaluator
 int hashCode()
          WARNING: do not rewrite this method unless you really know what you are doing!
protected  boolean isDifferent()
           
 boolean isMutable()
           
static double normalDistributionDensityFunction(double value, double mean, double stdDev)
          TODO when the 2.0 version of the commons match package comes out, I think we can use the density() method of the NormalDistributionImpl class.
static double normalDistributionDensityFunctionScaled(double value, double mean, double stdDev)
          TODO when the 2.0 version of the commons match package comes out, I think we can use the density() method of the NormalDistributionImpl class with the appropriate scaling factor.
protected  void onFunctionChange()
           
protected  java.lang.Object removeVariable(java.lang.String name)
          Delegate to evaluator TEST
protected  void reset()
           
protected  void setEvaluator(com.rubecula.jexpression.Evaluator evaluator)
           
 void setExpression(java.lang.CharSequence... tokens)
          Conditionally set expression (only if it is different).
 void setExpression(java.lang.String expression)
           
protected abstract  double standardFunction(java.lang.Object... arguments)
           
protected abstract  java.lang.CharSequence[] standardFunctionTokens(com.rubecula.jexpression.Notation notation)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.tostring0.Identifiable
getIdentifier
 

Field Detail

evaluator

protected com.rubecula.jexpression.Evaluator evaluator

LOG

protected static final org.apache.commons.logging.Log LOG
Constructor Detail

Function_

protected Function_()
Protected constructor to construct a Function_ with no evaluator.


Function_

protected Function_(com.rubecula.jexpression.Evaluator evaluator)
Protected constructor to construct a Function_ with given evaluator.

Parameters:
evaluator - the evaluator (expression engine) used to evaluate the expression.
Method Detail

normalDistributionDensityFunction

public static double normalDistributionDensityFunction(double value,
                                                       double mean,
                                                       double stdDev)
TODO when the 2.0 version of the commons match package comes out, I think we can use the density() method of the NormalDistributionImpl class.

Parameters:
value -
mean -
stdDev -
Returns:
e ^ (-diff * diff / 2 / stdDev / stdDev) / stdDev / FACTOR_NORMAL_DIST_PDF

normalDistributionDensityFunctionScaled

public static double normalDistributionDensityFunctionScaled(double value,
                                                             double mean,
                                                             double stdDev)
TODO when the 2.0 version of the commons match package comes out, I think we can use the density() method of the NormalDistributionImpl class with the appropriate scaling factor. XXX to be consistent with (unscaled) normal distribution, the stdDev should be squared inside the exponent of E.

Parameters:
value -
mean -
stdDev -
Returns:
e ^ (-diff * diff / 2 /stdDev) where diff = value - mean

addListener

public void addListener(FunctionListener listener)
Description copied from interface: Function
Method to add a function listener.

Specified by:
addListener in interface Function
See Also:
Function.addListener(com.rubecula.darwin.foundation.FunctionListener)

equals

public boolean equals(java.lang.Object obj)
WARNING: do not rewrite this method unless you really know what you are doing!

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

getExpression

public java.lang.String getExpression()
If getEvaluator() returns an EvalExpression, delegate to it. Else throw new DarwinException;

Specified by:
getExpression in interface com.rubecula.jexpression.EvalExpression
Throws:
DarwinException
See Also:
EvalExpression.getExpression()

getExpressionTerms

public com.rubecula.jexpression.Term[] getExpressionTerms()
If getEvaluator() returns an EvalExpression, delegate to it. Else throw new DarwinException;

Specified by:
getExpressionTerms in interface com.rubecula.jexpression.EvalExpression
Throws:
DarwinException
See Also:
EvalExpression.getExpressionTerms()

getValue

public java.lang.Number getValue()
                          throws com.rubecula.jexpression.JexpressionException
Delegate to evaluator

Specified by:
getValue in interface com.rubecula.jexpression.Valuable
Returns:
the value as an object (or null if the evaluator is not set).
Throws:
com.rubecula.jexpression.JexpressionException
See Also:
Valuable.getValue()

hashCode

public int hashCode()
WARNING: do not rewrite this method unless you really know what you are doing!

Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

isMutable

public boolean isMutable()
Specified by:
isMutable in interface com.rubecula.jexpression.EvalExpressionMutable
Returns:
true if the underlying function can be varied by setting a new expression in the evaluator. If there is no evaluator, then false is returned.

setExpression

public void setExpression(java.lang.CharSequence... tokens)
                   throws com.rubecula.jexpression.JexpressionException
Conditionally set expression (only if it is different).

Specified by:
setExpression in interface com.rubecula.jexpression.EvalExpressionMutable
Throws:
com.rubecula.jexpression.JexpressionException
See Also:
EvalExpressionMutable.setExpression(java.lang.CharSequence[])

setExpression

public void setExpression(java.lang.String expression)
                   throws com.rubecula.jexpression.JexpressionException
Specified by:
setExpression in interface com.rubecula.jexpression.EvalExpressionMutable
Parameters:
expression -
Throws:
com.rubecula.jexpression.JexpressionException
See Also:
EvalExpressionMutable.setExpression(java.lang.String)

addSymbol

protected java.lang.Number addSymbol(java.lang.String name,
                                     java.lang.Number value)
Delegate to evaluator TEST

Parameters:
name -
value -
Returns:
the value actually set

evaluate

protected java.lang.Number evaluate(java.lang.Object... parameters)
                             throws FunctionException
Evaluate the function based on the variables passed in as parameters. *

Parameters:
parameters -
Returns:
the value of the expression evaluated by the Evaluator or the value returned from evaluateByEvaluator(Object...).
Throws:
FunctionException
See Also:
FitnessFunction.getFitness(double, double, double)

getErrorInfo

protected java.lang.Object getErrorInfo()
                                 throws FunctionException
Returns:
delegate to evaluator and return the result.
Throws:
FunctionException

getEvaluator

protected com.rubecula.jexpression.Evaluator getEvaluator()
Returns:
the value of evaluator

getExpressionMap

protected ExpressionMap getExpressionMap()
Returns:
Identifiable.getIdentifier(),this in a new HashMap

isDifferent

protected boolean isDifferent()
Returns:
true if the expression has changed from the original expression.

onFunctionChange

protected void onFunctionChange()

removeVariable

protected java.lang.Object removeVariable(java.lang.String name)
                                   throws FunctionException
Delegate to evaluator TEST

Parameters:
name -
Returns:
the reult of invoking Evaluator.removeSymbol(String)
Throws:
FunctionException

reset

protected void reset()
              throws FunctionException
Throws:
FunctionException

setEvaluator

protected void setEvaluator(com.rubecula.jexpression.Evaluator evaluator)
                     throws FunctionException
Parameters:
evaluator -
Throws:
FunctionException

standardFunction

protected abstract double standardFunction(java.lang.Object... arguments)
                                    throws FunctionException
Parameters:
arguments - a variable set of Objects which must be passed to the actual implemented version of standardFunction(Object...).
Returns:
the standard value for this function. This is called when isDifferent() returns false.
Throws:
FunctionException - XXX

standardFunctionTokens

protected abstract java.lang.CharSequence[] standardFunctionTokens(com.rubecula.jexpression.Notation notation)
Parameters:
notation - the notation type used by the evaluator.
Returns:
the sequence of tokens that corresponds to the standardFunction(Object...). This is called by reset().


Copyright © 2010 Rubecula Software, LLC. All Rights Reserved.