net.sf.amiba.genegrammar
Class GeneGrammar<T>

Object
  extended by GeneGrammar<T>
Direct Known Subclasses:
ScientificGrammar

public abstract class GeneGrammar<T>
extends Object

This abstract class represents the grammar that will be used by a genome. A grammar is a set of terminals, operators and the related semantics. It is necessary to separate the grammar from genome and genes that will use it. This provides for a lot of pluggability. Subclasses should make use of a parser generator like JavaCC/JJTree to write elaborate grammars quickly. JJTree also allows the use of visitor pattern which makes things easier to maintain. The root node of the Abstract Syntax Tree must implement the interface GEPRootNode. Unlike the original GEP, a prefix-based grammar should be used for efficiency and ease of processing, although it is not mandated.

Author:
juber patel

Constructor Summary
GeneGrammar(List<Character> terminals, Character linkingFunction)
           
 
Method Summary
abstract  String decode(Gene gene)
          explain the given gene in a human readable form
 double evaluate(Gene[] genes, List<FitnessCase<T>> fitnessCases)
          evaluate the gene array and put a value on it.
 List<Character> getAlphabet()
           
 Character getLinkingFunction()
           
abstract  int getMaximumArity()
          get the maximum arity among the operators of this grammar
abstract  List<Character> getOperators()
          return the operators that are valid for this grammar
 List<Character> getTerminals()
           
 boolean isOperator(Character symbol)
           
 boolean isTerminal(Character symbol)
           
protected abstract  T link(List<T> geneValues)
          Link the separate gene values in the Individual and assign a representative value to them.
protected abstract  GEPRootNode<T> parse(String sequence)
          parse the given sequence and return the root of the AST.
protected abstract  double percentError(T calculated, T expected)
          compare the Individual's value for a fitness case to the expected value of the fitness case and express the difference as (positive double) percent error in estimation.
 List<T> useOn(Gene[] genes, List<FitnessCase<T>> fitnessCases)
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeneGrammar

public GeneGrammar(List<Character> terminals,
                   Character linkingFunction)
Parameters:
terminals - the valid termianls for this grammar
linkingFunction - the function that links the genes
Method Detail

getTerminals

public List<Character> getTerminals()

getAlphabet

public List<Character> getAlphabet()

isTerminal

public boolean isTerminal(Character symbol)

isOperator

public boolean isOperator(Character symbol)

getLinkingFunction

public Character getLinkingFunction()

useOn

public List<T> useOn(Gene[] genes,
                     List<FitnessCase<T>> fitnessCases)
              throws AmibaException
Throws:
AmibaException

evaluate

public double evaluate(Gene[] genes,
                       List<FitnessCase<T>> fitnessCases)
                throws AmibaException
evaluate the gene array and put a value on it. The higher the value, the better the fitness

Parameters:
genes -
Returns:
a number that represents the fitness of the given gene array
Throws:
AmibaException

parse

protected abstract GEPRootNode<T> parse(String sequence)
                                 throws AmibaException
parse the given sequence and return the root of the AST. To be implemented using JavaCC. This is the entry point into the grammar specification

Parameters:
sequence -
Returns:
Throws:
AmibaException

decode

public abstract String decode(Gene gene)
explain the given gene in a human readable form

Parameters:
gene -
Returns:

getOperators

public abstract List<Character> getOperators()
return the operators that are valid for this grammar


getMaximumArity

public abstract int getMaximumArity()
get the maximum arity among the operators of this grammar

Returns:

percentError

protected abstract double percentError(T calculated,
                                       T expected)
compare the Individual's value for a fitness case to the expected value of the fitness case and express the difference as (positive double) percent error in estimation. This number will be used as a measure of error in the Individual The calculated value should be compared with the expected value and a measure of the difference should be returned. The returned value will generally be percent error. The higher the returned value, the higher the error.

Returns:
a value indicating percent error

link

protected abstract T link(List<T> geneValues)
Link the separate gene values in the Individual and assign a representative value to them. The implementation should make collective sense of gene values so as to assign a value to the Individual.

Parameters:
geneValues -
Returns: