ramped half and half initialization procedure for eoParseTree populations
added.
This commit is contained in:
parent
8f1af522a6
commit
7e885e8f8c
1 changed files with 46 additions and 0 deletions
|
|
@ -31,6 +31,7 @@
|
||||||
#include <gp/eoParseTree.h>
|
#include <gp/eoParseTree.h>
|
||||||
#include <eoInit.h>
|
#include <eoInit.h>
|
||||||
#include <eoOp.h>
|
#include <eoOp.h>
|
||||||
|
#include <eoPop.h>
|
||||||
|
|
||||||
using namespace gp_parse_tree;
|
using namespace gp_parse_tree;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -142,4 +143,49 @@ class eoGpDepthInitializer : public eoInit< eoParseTree<FType, Node> >
|
||||||
bool grow;
|
bool grow;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A template function for ramped half and half initialization of an eoParseTree population
|
||||||
|
* @param pop the population to be created
|
||||||
|
* @param population_size the size of the population to be created
|
||||||
|
* @param init_max_depth the initial maximum tree depth
|
||||||
|
* @param initializor A vector containing the possible nodes
|
||||||
|
|
||||||
|
\ingroup ParseTree
|
||||||
|
*/
|
||||||
|
template <class FType, class Node>
|
||||||
|
void eoInitRampedHalfAndHalf(eoPop< eoParseTree<FType,Node> > &pop, unsigned int population_size, unsigned int init_max_depth, vector<Node> &initializor)
|
||||||
|
{
|
||||||
|
typedef eoParseTree<FType,Node> EoType;
|
||||||
|
typedef eoPop< EoType > Pop;
|
||||||
|
|
||||||
|
unsigned int M = init_max_depth - 1;
|
||||||
|
unsigned int part_pop_size = population_size / (2*M);
|
||||||
|
unsigned int m=0;
|
||||||
|
|
||||||
|
|
||||||
|
pop.clear();
|
||||||
|
|
||||||
|
// initialize with Depth's (D) -> 2
|
||||||
|
for(m=init_max_depth; m >= 2; m--)
|
||||||
|
{
|
||||||
|
eoGpDepthInitializer<FType, Node> grow_initializer(m, initializor, true);
|
||||||
|
Pop grow(part_pop_size, grow_initializer);
|
||||||
|
pop.insert(pop.begin(), grow.begin(), grow.end());
|
||||||
|
|
||||||
|
eoGpDepthInitializer<FType, Node> full_initializer(m, initializor, false);
|
||||||
|
Pop full(part_pop_size, full_initializer);
|
||||||
|
pop.insert(pop.begin(), full.begin(), full.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool g = true;
|
||||||
|
while (pop.size() < population_size)
|
||||||
|
{
|
||||||
|
eoGpDepthInitializer<FType, Node> initializer(init_max_depth, initializor, g);
|
||||||
|
Pop p(1, initializer);
|
||||||
|
pop.insert(pop.begin(), p.begin(), p.end());
|
||||||
|
g= !g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Reference in a new issue