GEP::Chromosome< ChromosomeType > Class Template Reference

Karva chromosome template. Implemented as a vector<unsigned short> holding indexes of elements in _oneArgFunction, _twoArgFunction and _terminals vectors. More...

#include <Chromosome.h>

Inheritance diagram for GEP::Chromosome< ChromosomeType >:
Inheritance graph
[legend]

List of all members.

Public Types

typedef ChromosomeType CType

Public Member Functions

 Chromosome ()
 Chromosome (const Chromosome &)
virtual ~Chromosome ()
 Chromosome (const std::vector< CElement > &chromo)
u_short evaluateTreeDepth (const u_short &idx) const
ChromosomeType evaluateGeneTree (const u_short &idx) const
virtual ChromosomeType calculateValue ()
void calculateSubValues (std::vector< std::pair< bool, ChromosomeType > > &vals)
void terminalsUsed (const u_short &idx, std::vector< short > &ref, const bool &append=false) const
void terminalsUsed (std::vector< short > &ref) const
CElementoperator[] (const u_short &idx)
CElement operator[] (const u_short &idx) const
CElement getElement (const u_short &gidx, const u_short &idx) const
CElement getElement (const u_short &gidx, const u_short &idx)
std::vector< CElement > & getChromosome ()
const std::vector< CElement > & getChromosome () const
std::vector< u_short > & getLinks ()
const std::vector< u_short > & getLinks () const
twoArg< ChromosomeType > * getLink (const u_short &idx)
twoArg< ChromosomeType > * getLink (const u_short &idx) const
std::vector< double > & getRandomConstants ()
const std::vector< double > & getRandomConstants () const
bool isViable () const
void setElement (const u_short &gidx, const u_short &idx, const CElement &element)
void insertHeadElement (const u_short &gidx, const u_short &idx, const CElement &element)
void setEmpty ()
void setChromosome (const std::vector< CElement > &fchromo)
void setLinks (const std::vector< u_short > &links)
void setLink (const u_short &link, const size_t &pos)
void setViable (const bool &b)
void setRandomConstants (const std::vector< double > &rcs)
void kill ()
std::string geneToString (const u_short &numGene) const
virtual std::string toString () const

Static Public Member Functions

static void readConfig (const std::string &path)
static void readConfig (const ConfigArgs &cfg)
static std::string symbolic (const CElement &a)
static std::string terminalToLetter (const u_short &a)
static CElement getCombinedIndex (const std::string &name)
static u_short getRcLength ()
static u_short getTermLength ()
static u_short getHeadLength ()
static u_short getTailLength ()
static u_short getGeneLength ()
static u_short getChromosomeLength ()
static u_short getNumGenes ()
static std::vector< twoArg
< ChromosomeType > * > 
getLinkPool ()
static std::vector< oneArg
< ChromosomeType > * > 
getOneArgFunctions ()
static std::vector< oneArg
< ChromosomeType > * > & 
getROneArgFunctions ()
static std::vector< twoArg
< ChromosomeType > * > 
getTwoArgFunctions ()
static std::vector< twoArg
< ChromosomeType > * > & 
getRTwoArgFunctions ()
static std::vector
< ChromosomeType > 
getTerminals ()
static std::vector
< ChromosomeType > & 
getRTerminals ()
static void setHeadLength (const u_short &fhead)
static void setLinkPool (const std::string &easy)
static void setOneArgFunctions (const std::string &easyones)
static void setTwoArgFunctions (const std::string &easytwos)
static void assignValues (const std::vector< ChromosomeType > &vals, const size_t pop_age=0)
static void clearFunctionPointers ()
static void setNumGenes (const u_short &fgenes)
static void setOneArgFunctions (const std::vector< oneArg< ChromosomeType > * > &ones)
static void setTwoArgFunctions (const std::vector< twoArg< ChromosomeType > * > &twos)
static void setLinkPool (const std::vector< twoArg< ChromosomeType > * > &pool)
static void setLinkPool (const twoArg< ChromosomeType > *&pool)
static void setTerminals (const std::vector< ChromosomeType > &terms)
static void setTerminals (const u_short &tSize)
static void setTerminal (const ChromosomeType &term, const size_t &idx)
static void setRcLength (const u_short &length)

Protected Attributes

std::vector< CElement_chromosome
std::vector< u_short > _links
std::vector< double > _rconstants
bool _viable

Static Protected Attributes

static std::vector< twoArg
< ChromosomeType > * > 
_linkPool = std::vector< twoArg<ChromosomeType>* >()
static std::vector< oneArg
< ChromosomeType > * > 
_oneArgFunctions = std::vector< oneArg<ChromosomeType>* >()
static std::vector< twoArg
< ChromosomeType > * > 
_twoArgFunctions = std::vector< twoArg<ChromosomeType>* >()
static std::vector
< ChromosomeType > 
_terminals = std::vector<ChromosomeType>()
static std::vector
< ChromosomeType > 
_results = std::vector<ChromosomeType>()
static u_short _termLength = 0
static u_short _rcLength = 0
static u_short _numGenes = 3
static u_short _headLength = 10
static u_short _tailLength = (_headLength + 1)
static u_short _geneLength = Chromosome<ChromosomeType>::_headLength + Chromosome<ChromosomeType>::_tailLength

Friends

template<class T2 >
std::ostream & operator<< (std::ostream &os, const Chromosome< T2 > &a)

Detailed Description

template<class ChromosomeType = double>
class GEP::Chromosome< ChromosomeType >

Karva chromosome template. Implemented as a vector<unsigned short> holding indexes of elements in _oneArgFunction, _twoArgFunction and _terminals vectors.

Parameters:
ChromosomeType - type of variables held in _terminals and calculated by fuctions.

Member Typedef Documentation

template<class ChromosomeType = double>
typedef ChromosomeType GEP::Chromosome< ChromosomeType >::CType

Type of the chromosome terminals and functions


Constructor & Destructor Documentation

template<class ChromosomeType >
GEP::Chromosome< ChromosomeType >::Chromosome (  )  [inline]

Default constructor

template<class ChromosomeType >
GEP::Chromosome< ChromosomeType >::Chromosome ( const Chromosome< ChromosomeType > &  copy  )  [inline]

Copy constructor

template<class ChromosomeType = double>
virtual GEP::Chromosome< ChromosomeType >::~Chromosome (  )  [inline, virtual]
template<class ChromosomeType >
GEP::Chromosome< ChromosomeType >::Chromosome ( const std::vector< CElement > &  chromo  )  [inline]

"We know better" Constructor - sets head, tail and the lengths.

Parameters:
chromo - new chromosome

Member Function Documentation

template<class ChromosomeType>
void GEP::Chromosome< ChromosomeType >::assignValues ( const std::vector< ChromosomeType > &  vals,
const size_t  pop_age = 0 
) [inline, static]

Assigns the values of the _terminals vector.

Parameters:
vals values of the terminals
pop_age supportive parameter for ABFT analysis, by default - unused
template<class ChromosomeType>
void GEP::Chromosome< ChromosomeType >::calculateSubValues ( std::vector< std::pair< bool, ChromosomeType > > &  vals  )  [inline]

Calculates value of the chromosome genes. places values of genes of a given chromosome in

Parameters:
vals 
template<class ChromosomeType >
ChromosomeType GEP::Chromosome< ChromosomeType >::calculateValue (  )  [inline, virtual]

Calculates value of the chromosome, linking the results of ORFs with the linking function of the chromosome.

Returns:
value of a given chromosome
template<class ChromosomeType >
void GEP::Chromosome< ChromosomeType >::clearFunctionPointers (  )  [inline, static]

Gracefully deletes the pointers to the linking function, one argument and two argument functions. Should be invoked after the work with GEP::Chromosome.

template<class ChromosomeType >
ChromosomeType GEP::Chromosome< ChromosomeType >::evaluateGeneTree ( const u_short &  idx  )  const [inline]

Evaluates value of given ORF, following ET. Uses _treeDepth[idx].

Parameters:
idx - index of ORF to be evaluated
Returns:
value of a given tree
template<class ChromosomeType >
u_short GEP::Chromosome< ChromosomeType >::evaluateTreeDepth ( const u_short &  idx  )  const [inline]

Evaluates ET depth for a given ORF, results will be placed in _treeDepth[idx].

Parameters:
idx - index of ORF to be evaluated
Returns:
tree depth (besides placing it in _treeDepth[idx])
template<class ChromosomeType >
std::string GEP::Chromosome< ChromosomeType >::geneToString ( const u_short &  numGene  )  const [inline]
Returns:
Parameters:
numGene ORF represented as string.
template<class ChromosomeType = double>
const std::vector<CElement>& GEP::Chromosome< ChromosomeType >::getChromosome (  )  const [inline]
template<class ChromosomeType = double>
std::vector<CElement>& GEP::Chromosome< ChromosomeType >::getChromosome (  )  [inline]
template<class ChromosomeType = double>
static u_short GEP::Chromosome< ChromosomeType >::getChromosomeLength (  )  [inline, static]
template<class ChromosomeType >
CElement GEP::Chromosome< ChromosomeType >::getCombinedIndex ( const std::string &  name  )  [inline, static]

Returns the absolute index of the searched function, i.e. if the searched name will be in _twoArgFunctions vector, result will be _oneArgFunctions.size()+index of searched function.

Parameters:
name name of the searched function
Returns:
absolute index of the searched function
template<class ChromosomeType = double>
CElement GEP::Chromosome< ChromosomeType >::getElement ( const u_short &  gidx,
const u_short &  idx 
) [inline]
Returns:
element in given ORF (gidx) , on a given position(idx).
Parameters:
gidx - index of gene
idx - index of gene element
template<class ChromosomeType = double>
CElement GEP::Chromosome< ChromosomeType >::getElement ( const u_short &  gidx,
const u_short &  idx 
) const [inline]
Returns:
element in given ORF (gidx), on a given position(idx).
template<class ChromosomeType = double>
static u_short GEP::Chromosome< ChromosomeType >::getGeneLength (  )  [inline, static]
template<class ChromosomeType = double>
static u_short GEP::Chromosome< ChromosomeType >::getHeadLength (  )  [inline, static]
template<class ChromosomeType = double>
twoArg<ChromosomeType>* GEP::Chromosome< ChromosomeType >::getLink ( const u_short &  idx  )  const [inline]
template<class ChromosomeType = double>
twoArg<ChromosomeType>* GEP::Chromosome< ChromosomeType >::getLink ( const u_short &  idx  )  [inline]
template<class ChromosomeType = double>
static std::vector< twoArg<ChromosomeType>* > GEP::Chromosome< ChromosomeType >::getLinkPool (  )  [inline, static]
template<class ChromosomeType = double>
const std::vector<u_short>& GEP::Chromosome< ChromosomeType >::getLinks (  )  const [inline]
template<class ChromosomeType = double>
std::vector<u_short>& GEP::Chromosome< ChromosomeType >::getLinks (  )  [inline]
template<class ChromosomeType = double>
static u_short GEP::Chromosome< ChromosomeType >::getNumGenes (  )  [inline, static]
template<class ChromosomeType = double>
static std::vector< oneArg<ChromosomeType>* > GEP::Chromosome< ChromosomeType >::getOneArgFunctions (  )  [inline, static]
template<class ChromosomeType = double>
const std::vector<double>& GEP::Chromosome< ChromosomeType >::getRandomConstants (  )  const [inline]
template<class ChromosomeType = double>
std::vector<double>& GEP::Chromosome< ChromosomeType >::getRandomConstants (  )  [inline]
template<class ChromosomeType = double>
static u_short GEP::Chromosome< ChromosomeType >::getRcLength (  )  [inline, static]
template<class ChromosomeType = double>
static std::vector< oneArg<ChromosomeType>* >& GEP::Chromosome< ChromosomeType >::getROneArgFunctions (  )  [inline, static]
template<class ChromosomeType = double>
static std::vector<ChromosomeType>& GEP::Chromosome< ChromosomeType >::getRTerminals (  )  [inline, static]
template<class ChromosomeType = double>
static std::vector< twoArg<ChromosomeType>* >& GEP::Chromosome< ChromosomeType >::getRTwoArgFunctions (  )  [inline, static]
template<class ChromosomeType = double>
static u_short GEP::Chromosome< ChromosomeType >::getTailLength (  )  [inline, static]
template<class ChromosomeType = double>
static std::vector<ChromosomeType> GEP::Chromosome< ChromosomeType >::getTerminals (  )  [inline, static]
template<class ChromosomeType = double>
static u_short GEP::Chromosome< ChromosomeType >::getTermLength (  )  [inline, static]
template<class ChromosomeType = double>
static std::vector< twoArg<ChromosomeType>* > GEP::Chromosome< ChromosomeType >::getTwoArgFunctions (  )  [inline, static]
template<class ChromosomeType >
void GEP::Chromosome< ChromosomeType >::insertHeadElement ( const u_short &  gidx,
const u_short &  idx,
const CElement element 
) [inline]

Inserts element in head of given ORF (gidx), on a given position(idx). Last element of the head is removed.

Parameters:
gidx - index of gene
idx - index of gene element
element - element to be placed at a given position
template<class ChromosomeType = double>
bool GEP::Chromosome< ChromosomeType >::isViable (  )  const [inline]
template<class ChromosomeType = double>
void GEP::Chromosome< ChromosomeType >::kill (  )  [inline]
template<class ChromosomeType = double>
CElement GEP::Chromosome< ChromosomeType >::operator[] ( const u_short &  idx  )  const [inline]

Operator[] overload.

Returns:
ORF element on a given position (
Parameters:
idx). 
template<class ChromosomeType = double>
CElement& GEP::Chromosome< ChromosomeType >::operator[] ( const u_short &  idx  )  [inline]

Operator[] overload.

Returns:
ORF element on a given position (
Parameters:
idx). 
template<class ChromosomeType >
void GEP::Chromosome< ChromosomeType >::readConfig ( const ConfigArgs cfg  )  [inline, static]

Reads the config stored in

Parameters:
cfg of type ConfigArgs.
template<class ChromosomeType >
void GEP::Chromosome< ChromosomeType >::readConfig ( const std::string &  path  )  [inline, static]

Reads the config stored in the file indicated by

Parameters:
path 
template<class ChromosomeType = double>
void GEP::Chromosome< ChromosomeType >::setChromosome ( const std::vector< CElement > &  fchromo  )  [inline]
template<class ChromosomeType = double>
void GEP::Chromosome< ChromosomeType >::setElement ( const u_short &  gidx,
const u_short &  idx,
const CElement element 
) [inline]

Sets element in given ORF (gidx), on a given position(idx) to element.

Parameters:
gidx - index of gene
idx - index of gene element
element - element to be placed at a given position
template<class ChromosomeType >
void GEP::Chromosome< ChromosomeType >::setEmpty (  )  [inline]
template<class ChromosomeType >
void GEP::Chromosome< ChromosomeType >::setHeadLength ( const u_short &  fhead  )  [inline, static]

Function setting head, tail and result lengths.

Parameters:
fhead size of the head part of the chromosome
template<class ChromosomeType = double>
void GEP::Chromosome< ChromosomeType >::setLink ( const u_short &  link,
const size_t &  pos 
) [inline]
template<class ChromosomeType = double>
static void GEP::Chromosome< ChromosomeType >::setLinkPool ( const twoArg< ChromosomeType > *&  pool  )  [inline, static]
template<class ChromosomeType = double>
static void GEP::Chromosome< ChromosomeType >::setLinkPool ( const std::vector< twoArg< ChromosomeType > * > &  pool  )  [inline, static]
template<class ChromosomeType >
void GEP::Chromosome< ChromosomeType >::setLinkPool ( const std::string &  easy  )  [inline, static]

Sets the linking function on the basis of the given symbol - the name of the function. Looks up only functions in the basic Function set.

Parameters:
easy symbol of the linking functions pool
template<class ChromosomeType = double>
void GEP::Chromosome< ChromosomeType >::setLinks ( const std::vector< u_short > &  links  )  [inline]
template<class ChromosomeType = double>
static void GEP::Chromosome< ChromosomeType >::setNumGenes ( const u_short &  fgenes  )  [inline, static]
template<class ChromosomeType = double>
static void GEP::Chromosome< ChromosomeType >::setOneArgFunctions ( const std::vector< oneArg< ChromosomeType > * > &  ones  )  [inline, static]
template<class ChromosomeType >
void GEP::Chromosome< ChromosomeType >::setOneArgFunctions ( const std::string &  easyones  )  [inline, static]

Sets the vector of one argument functiona on the basis of the vector of given symbols - the names of the functions. Looks up only functions in the basic Function set.

Parameters:
easyones - vector of symbols of the one argument functions.
template<class ChromosomeType = double>
void GEP::Chromosome< ChromosomeType >::setRandomConstants ( const std::vector< double > &  rcs  )  [inline]
template<class ChromosomeType = double>
static void GEP::Chromosome< ChromosomeType >::setRcLength ( const u_short &  length  )  [inline, static]
template<class ChromosomeType = double>
static void GEP::Chromosome< ChromosomeType >::setTerminal ( const ChromosomeType &  term,
const size_t &  idx 
) [inline, static]
template<class ChromosomeType = double>
static void GEP::Chromosome< ChromosomeType >::setTerminals ( const u_short &  tSize  )  [static]
template<class ChromosomeType = double>
static void GEP::Chromosome< ChromosomeType >::setTerminals ( const std::vector< ChromosomeType > &  terms  )  [inline, static]
template<class ChromosomeType = double>
static void GEP::Chromosome< ChromosomeType >::setTwoArgFunctions ( const std::vector< twoArg< ChromosomeType > * > &  twos  )  [inline, static]
template<class ChromosomeType >
void GEP::Chromosome< ChromosomeType >::setTwoArgFunctions ( const std::string &  easytwos  )  [inline, static]

Sets the vector of two argument functiona on the basis of the vector of given symbols - the names of the functions. Looks up only functions in the basic Function set.

Parameters:
easytwos - vector of symbols of the two argument functions.
template<class ChromosomeType = double>
void GEP::Chromosome< ChromosomeType >::setViable ( const bool &  b  )  [inline]
template<class ChromosomeType >
std::string GEP::Chromosome< ChromosomeType >::symbolic ( const CElement a  )  [inline, static]
Returns:
the symbol of a given element in the chromosome (
Parameters:
a). 
template<class ChromosomeType >
void GEP::Chromosome< ChromosomeType >::terminalsUsed ( std::vector< short > &  ref  )  const [inline]

Provides the set of indexes of terminals used by functions in the chromosome.

Returns:
vector of indexes of terminals used by the chromosome
template<class ChromosomeType >
void GEP::Chromosome< ChromosomeType >::terminalsUsed ( const u_short &  idx,
std::vector< short > &  ref,
const bool &  append = false 
) const [inline]

Provides the set of indexes of terminals used by functions in a given gene.

Parameters:
idx index of a gene to check
ref target vector
append if false, ref will be cleared
Returns:
vector of indexes of terminals used by this gene
template<class ChromosomeType >
std::string GEP::Chromosome< ChromosomeType >::terminalToLetter ( const u_short &  a  )  [inline, static]
Returns:
the letter representing a given terminal in the chromosome (
Parameters:
a). 
template<class ChromosomeType >
std::string GEP::Chromosome< ChromosomeType >::toString (  )  const [inline, virtual]
Returns:
this chromosome represented as string.

Friends And Related Function Documentation

template<class ChromosomeType = double>
template<class T2 >
std::ostream& operator<< ( std::ostream &  os,
const Chromosome< T2 > &  a 
) [friend]

Member Data Documentation

template<class ChromosomeType = double>
std::vector<CElement> GEP::Chromosome< ChromosomeType >::_chromosome [protected]

GEP Chromosome - a vector of CElements holding indexes of elements in _oneArgFunction, _twoArgFunction and _terminals vectors. CElement.first describes the type anf CElement.second the value of an element

template<class ChromosomeType = double>
u_short GEP::Chromosome< ChromosomeType >::_geneLength = Chromosome<ChromosomeType>::_headLength + Chromosome<ChromosomeType>::_tailLength [inline, static, protected]

Gene length

template<class ChromosomeType = double>
u_short GEP::Chromosome< ChromosomeType >::_headLength = 10 [inline, static, protected]

Head length

template<class ChromosomeType = double>
std::vector< twoArg< ChromosomeType > * > GEP::Chromosome< ChromosomeType >::_linkPool = std::vector< twoArg<ChromosomeType>* >() [inline, static, protected]

Linking function. Two argument, as it has to link values of genes, thus take more than one value and return one value.

template<class ChromosomeType = double>
std::vector<u_short> GEP::Chromosome< ChromosomeType >::_links [protected]

Linking functions between the genes.

template<class ChromosomeType = double>
u_short GEP::Chromosome< ChromosomeType >::_numGenes = 3 [inline, static, protected]

Number of genes in one chromosome

template<class ChromosomeType = double>
std::vector< oneArg< ChromosomeType > * > GEP::Chromosome< ChromosomeType >::_oneArgFunctions = std::vector< oneArg<ChromosomeType>* >() [inline, static, protected]

One Argument Functions

template<class ChromosomeType = double>
u_short GEP::Chromosome< ChromosomeType >::_rcLength = 0 [inline, static, protected]

'Random constants' vector length

template<class ChromosomeType = double>
std::vector<double> GEP::Chromosome< ChromosomeType >::_rconstants [protected]

Random constants vector.

template<class ChromosomeType = double>
std::vector< ChromosomeType > GEP::Chromosome< ChromosomeType >::_results = std::vector<ChromosomeType>() [inline, static, protected]

Holds the results of evaluation

template<class ChromosomeType = double>
u_short GEP::Chromosome< ChromosomeType >::_tailLength = (_headLength + 1) [inline, static, protected]

Tail length

template<class ChromosomeType = double>
std::vector< ChromosomeType > GEP::Chromosome< ChromosomeType >::_terminals = std::vector<ChromosomeType>() [inline, static, protected]

Terminals

template<class ChromosomeType = double>
u_short GEP::Chromosome< ChromosomeType >::_termLength = 0 [inline, static, protected]

'Terminals' vector length

template<class ChromosomeType = double>
std::vector< twoArg< ChromosomeType > * > GEP::Chromosome< ChromosomeType >::_twoArgFunctions = std::vector< twoArg<ChromosomeType>* >() [inline, static, protected]

Two Argument Functions

template<class ChromosomeType = double>
bool GEP::Chromosome< ChromosomeType >::_viable [protected]

Is this chromosome viable.


The documentation for this class was generated from the following file:

Generated on Fri Dec 11 22:28:17 2009 for LibGEP by  doxygen 1.6.1