com.rubecula.darwin.domain.fitness
Class Fitness_

java.lang.Object
  extended by com.rubecula.darwin.domain.fitness.Fitness_
All Implemented Interfaces:
Fitness, com.rubecula.jexpression.EvalExpression
Direct Known Subclasses:
Fitness_Hamiltonian, RouteFitness, WcSdFitness

public abstract class Fitness_
extends java.lang.Object
implements Fitness, com.rubecula.jexpression.EvalExpression

This type represents the fitness of a Trait/EcoFactor combination.

Author:
Robin Hillyard

Field Summary
protected static org.apache.commons.logging.Log LOG
          The logger for this class.
 
Constructor Summary
protected Fitness_()
           
protected Fitness_(FitnessFunction fitnessFunction, FunctionListener functionListener)
           
 
Method Summary
protected abstract  double bandwidth(java.lang.String key)
          Concrete sub-classes must implement this method to indicate how sharp the fitness curve should be with respect to the possible values of the variate.
protected  double calculateFitness(double t, double f, java.lang.String keyT, java.lang.String keyF)
          Calculate and return the value of the probability density function corresponding to the variate value t * sT of a continuous distribution with mean: f * sF and standard deviation: the value of bandwidth(String).
 int compare(double fitness1, double fitness2)
          Compare fitness 1 with fitness 2 (fitter values are higher values).
 boolean equals(java.lang.Object obj)
           
 java.lang.Number getEnvironmentFactor()
           
 java.lang.String getExpression()
           
 com.rubecula.jexpression.Term[] getExpressionTerms()
           
protected  FitnessFunction getFitnessFunction()
           
protected  double getTolerance()
           
 int hashCode()
           
 void resetAdjustment(java.lang.Number factor, java.lang.String trait)
          By default, this method returns null.
 void resetEnvironmentFactor(java.lang.String trait, EcoFactor factor)
           
protected  double scaleFactor(java.lang.String key)
           
protected  double scaleTrait(java.lang.String key)
           
protected  void setTolerance(double tolerance)
          TODO consider making this public
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.rubecula.darwin.domain.helper.Fitness
getFitness, getWeight
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG
The logger for this class.

Constructor Detail

Fitness_

protected Fitness_()

Fitness_

protected Fitness_(FitnessFunction fitnessFunction,
                   FunctionListener functionListener)
Parameters:
fitnessFunction -
functionListener - a listener to function changes
Method Detail

compare

public int compare(double fitness1,
                   double fitness2)
Compare fitness 1 with fitness 2 (fitter values are higher values).

Specified by:
compare in interface Fitness
Parameters:
fitness1 -
fitness2 -
Returns:
-1 if fitness1 is greater than fitness2, etc.

equals

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

getEnvironmentFactor

public java.lang.Number getEnvironmentFactor()
Specified by:
getEnvironmentFactor in interface Fitness
Returns:
the value that is dependent on the environment
See Also:
Fitness.getEnvironmentFactor()

getExpression

public java.lang.String getExpression()
Specified by:
getExpression in interface com.rubecula.jexpression.EvalExpression
See Also:
EvalExpression.getExpression()

getExpressionTerms

public com.rubecula.jexpression.Term[] getExpressionTerms()
Specified by:
getExpressionTerms in interface com.rubecula.jexpression.EvalExpression
See Also:
EvalExpression.getExpressionTerms()

hashCode

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

resetAdjustment

public void resetAdjustment(java.lang.Number factor,
                            java.lang.String trait)
By default, this method returns null.

Specified by:
resetAdjustment in interface Fitness
Parameters:
factor - if 1 is passed in then nothing changes.
trait - XXX
See Also:
Fitness.resetAdjustment(java.lang.Number, java.lang.String)

resetEnvironmentFactor

public void resetEnvironmentFactor(java.lang.String trait,
                                   EcoFactor factor)
Specified by:
resetEnvironmentFactor in interface Fitness
Parameters:
trait - XXX
factor - XXX
See Also:
Fitness.resetEnvironmentFactor(String, com.rubecula.darwin.domain.helper.EcoFactor)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

bandwidth

protected abstract double bandwidth(java.lang.String key)
Concrete sub-classes must implement this method to indicate how sharp the fitness curve should be with respect to the possible values of the variate.

Parameters:
key - the key which determines which bandwidth to get (trait or ecofactor).
Returns:
a measure of the bandwidth of variate. In a normal distribution, bandwidth is identical with standard deviation. Note that the bandwidth should be in the same domain as the scaled values.

calculateFitness

protected double calculateFitness(double t,
                                  double f,
                                  java.lang.String keyT,
                                  java.lang.String keyF)
                           throws FitnessException
Calculate and return the value of the probability density function corresponding to the variate value t * sT of a continuous distribution with mean: f * sF and standard deviation: the value of bandwidth(String). The actual continuous distribution used is defined the the _fitnessFunction. Implementers of Fitness may override this method if they need something different. XXX consider renaming some of the parameters (trait -> variant)

Parameters:
t - the trait value
f - the eco factor value
keyT - the trait key (identifier) used to determine which scale factor to use, using scaleTrait(String)
keyF - the eco factor key (identifier) used to determine which scale factor to use, using scaleFactor(String)
Returns:
the value of FitnessFunction.getFitness(double, double, double) where the mean is f * sF and the value is t * sT and the standardDeviation is given by bandwidth(String) and where sT is the value returned from the method scaleTrait(String) and sF is the value returned from the method scaleFactor(String).
Throws:
FitnessException

getFitnessFunction

protected FitnessFunction getFitnessFunction()

getTolerance

protected double getTolerance()
Returns:
the tolerance

scaleFactor

protected double scaleFactor(java.lang.String key)
Parameters:
key - the key (identifier) of the ecoFactor
Returns:
a scale factor to be applied (to the eco factor value) before the difference is calculated between the trait as a value and the eco factor as a value. By value returned by this base method is 1.0. Specific fitness implementations must override if the value is to be different.

scaleTrait

protected double scaleTrait(java.lang.String key)
Parameters:
key - the key (identifier) of the trait
Returns:
a scale factor to be applied (to the trait value) before the difference is calculated between the trait as a value and the eco factor as a value. By value returned by this base method is 1.0. Specific fitness implementations must override if the value is to be different.

setTolerance

protected void setTolerance(double tolerance)
TODO consider making this public

Parameters:
tolerance - the tolerance to set


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