updated include dependencies

This commit is contained in:
maartenkeijzer 2007-09-23 08:35:51 +00:00
commit 40f5377cf1
21 changed files with 87 additions and 59 deletions

View file

@ -19,7 +19,7 @@ CXXSOURCES=FunDef.cpp Sym.cpp SymImpl.cpp SymOps.cpp sym_compile.cpp TreeBuilder
Dataset.cpp ErrorMeasure.cpp Scaling.cpp TargetInfo.cpp BoundsCheck.cpp util.cpp NodeSelector.cpp\
eoSymCrossover.cpp sym_operations.cpp eoSymMutate.cpp eoSymLambdaMutate.cpp MultiFunction.cpp
TESTPROGRAMS=test/test_compile test/testeo test/test_simplify test/test_diff test/test_lambda test/test_mf
TESTPROGRAMS=test/test_compile test/testeo test/test_simplify test/test_diff test/test_lambda test/test_mf test/test_interval
OBJS= $(CXXSOURCES:.cpp=.o) c_compile.o
@ -40,7 +40,7 @@ libsym.a: $(OBJS)
rm libsym.a; ar cq $(SYMLIB) $(OBJS)
check: $(TESTPROGRAMS)
test/test_compile && test/testeo && test/test_simplify && test/test_diff && test/test_lambda && echo "all tests succeeded"
test/test_compile && test/test_interval && test/testeo && test/test_simplify && test/test_diff && test/test_lambda && echo "all tests succeeded"
test/test_compile: test/test_compile.o ${SYMLIB}
$(CXX) -o test/test_compile test/test_compile.o $(SYMLIB) ${LIBS}
@ -60,6 +60,10 @@ test/test_lambda: test/test_lambda.o $(SYMLIB)
test/test_mf: test/test_mf.o $(SYMLIB)
$(CXX) -o test/test_mf test/test_mf.o $(SYMLIB) ${LIBS}
test/test_interval: test/test_interval.o
$(CXX) -o test/test_interval test/test_interval.o $(SYMLIB) ${LIBS}
# eo
../../src/libeo.a:
make -C ../../src libeo.a

View file

@ -19,8 +19,8 @@
#define EOSYM_H_
#include <EO.h>
#include <Sym.h>
#include <FunDef.h>
#include <sym/Sym.h>
#include <fun/FunDef.h>
template <class Fitness>

View file

@ -21,6 +21,9 @@
#include <eoSymCrossover.h>
#include <utils/eoRNG.h>
#include <vector>
using namespace std;
bool subtree_quad(Sym& a, Sym& b, NodeSelector& select) {
NodeSelector::NodeSelection sel_a = select.select_node(a);
@ -75,4 +78,46 @@ bool homologous_bin(Sym& a, const Sym& b) {
return org != a;
}
void set_size_levels(Sym sym, vector<unsigned>& l, vector<unsigned>& s, unsigned level = 1) {
l.push_back(level);
s.push_back(sym.size());
for (unsigned i = 0; i < sym.args().size(); ++i) {
set_size_levels(sym.args()[i], l, s, level+1);
}
}
bool size_level_xover(Sym& a, const Sym& b) {
Sym org = a;
vector<unsigned> levela;
vector<unsigned> sizesa;
vector<unsigned> levelb;
vector<unsigned> sizesb;
set_size_levels(a, levela, sizesa);
set_size_levels(b, levelb, sizesb);
unsigned p0;
unsigned p1;
for (unsigned tries = 0;; ++tries) {
p0 = rng.random(a.size());
p1 = rng.random(b.size());
if (tries < 5 && (sizesa[p0] != sizesb[p1] && levela[p0] != levelb[p1])) {
continue;
}
break;
}
a = insert_subtree(a, p0, get_subtree(b, p1));
return org != a;
}

View file

@ -60,5 +60,14 @@ class eoBinHomologousCrossover : public eoBinOp<EoType> {
};
extern bool size_level_xover(Sym& a, const Sym& b);
template <class EoType>
class eoSizeLevelCrossover : public eoBinOp<EoType> {
public:
bool operator()(EoType& a, const EoType& b) {
return size_level_xover(a,b);
}
};
#endif

View file

@ -19,7 +19,7 @@
#define EOSYMINIT_H
#include <eoInit.h>
#include <TreeBuilder.h>
#include <gen/TreeBuilder.h>
/** Default initializer, Koza style */
template <class EoType>

View file

@ -63,11 +63,10 @@ bool mutate_constants(Sym& sym, double stdev) {
}
for (unsigned i = 0; i < values.size(); ++i) {
values[i] += rng.normal() * stdev;
values[i] += rng.normal() * stdev / values.size();
}
sym = set_constants(sym, values);
return true;
}

View file

@ -18,8 +18,8 @@
#ifndef SYMMUTATE_H
#define SYMMUTATE_H
#include <TreeBuilder.h>
#include <NodeSelector.h>
#include <gen/TreeBuilder.h>
#include <gen/NodeSelector.h>
#include <eoSym.h>
#include <eoOp.h>

View file

@ -77,39 +77,6 @@ std::ostream& operator<<(std::ostream& os, const Interval& val) {
}
#ifdef TEST_INTERVAL
using namespace std;
using namespace boost::numeric;
int main() {
Interval a(0, 10);
Interval b(-1.5, 2);
cout << "a = " << a << endl;
cout << "b = " << b << endl;
cout << "a + b = " << a + b << endl;
cout << "a - b = " << a - b << endl;
cout << "b - a = " << b - a << endl;
cout << "-a = " << -a << endl;
cout << "a * b = " << a * b << endl;
cout << "b/(a+1) = " << b / (a + 1.0) << endl;
cout << "b * a = " << b * a << endl;
cout << "b / a = " << b/a << endl;
cout << "cos(a) = " << cos(a) << endl;
cout << "cos(b) = " << cos(b) << endl;
cout << "log(b) = " << log(b) << endl;
cout << "sqrt(b) = " << sqrt(b) << endl;
cout << "sqrt(a) = " << sqrt(a) << endl;
cout << "sqr(b) = " << sqr(b) << endl;
cout << "exp(b*a)= " << exp(b*a) << endl;
cout << "atan(a) = " << atan(a) << endl;
cout << "cosh(b) = " << cosh(b) << endl;
}
#endif
#endif

View file

@ -19,7 +19,7 @@
#define SYMCOMPILE_H_
#include <vector>
#include <sym/Sym.h>
typedef double (*single_function)(const double []);
typedef double (*multi_function)(const double[], double[]);

View file

@ -247,8 +247,6 @@ class Const : public FunDef {
}
Interval eval(const vector<Interval>& _, const vector<Interval>& inputs) const {
// Profil/Bias seems to have a problem with 0 * inf when the Interval is exact zero (fpe)
//if (value == 0.0) return Interval(-BiasEpsilon,BiasEpsilon);
return Interval(value);
}

View file

@ -23,8 +23,8 @@
#include <memory>
#include <iostream>
#include "Sym.h"
#include "Interval.h"
#include "sym/Sym.h"
#include "eval/Interval.h"
class FunDef {
public:

View file

@ -18,7 +18,7 @@
#ifndef SYMOPS_H
#define SYMOPS_H
#include "Sym.h"
#include "sym/Sym.h"
extern Sym operator+(Sym a, Sym b);
extern Sym operator*(Sym a, Sym b);

View file

@ -18,7 +18,7 @@
#ifndef LANGUAGE_TABLE_H
#define LANGUAGE_TABLE_H
#include "token.h"
#include <sym/token.h>
class LanguageImpl;
class Sym;

View file

@ -18,7 +18,7 @@
#ifndef NODESELECTOR_H
#define NODESELECTOR_H
#include <Sym.h>
#include <sym/Sym.h>
/** Base class for selecting nodes */
class NodeSelector {

View file

@ -18,7 +18,7 @@
#ifndef TREEBUILDER_H_
#define TREEBUILDER_H_
#include "Sym.h"
#include "sym/Sym.h"
#include "LanguageTable.h"
class TreeBuilder {

View file

@ -38,6 +38,9 @@ struct UniqueNodeStats { virtual ~UniqueNodeStats(){} };
#else
#define USE_TR1 0
#endif
// TR1 is buggy at times
#undef USE_TR1
#define USE_TR1 0
#if USE_TR1
#include <tr1/unordered_map>

View file

@ -47,7 +47,7 @@ SymArgs::SymArgs(const SymArgs& args) : pimpl(0), args_ptr(args.args_ptr) {
}
}
const SymArgs& SymArgs::operator=(const SymArgs& args) {
SymArgs& SymArgs::operator=(const SymArgs& args) {
if (args.pimpl && args.args_ptr == &args.pimpl->owned_args) {
pimpl = new SymArgsImpl(*args.pimpl);
args_ptr = &pimpl->owned_args;

View file

@ -47,7 +47,7 @@ class SymArgs {
~SymArgs();
SymArgs(const SymArgs& args);
const SymArgs& SymArgs::operator=(const SymArgs& other);
SymArgs& operator=(const SymArgs& other);
size_t len() const;
const std::vector<Sym>& vec() const { return *args_ptr; }

View file

@ -115,7 +115,7 @@ int main(int argc, char* argv[]) {
/* Population */
unsigned pop_size = parser.createParam(1500u, "population-size", "Population Size", 'p', string("Population")).value();
unsigned pop_size = parser.createParam(500u, "population-size", "Population Size", 'p', string("Population")).value();
uint32_t seed = parser.createParam( uint32_t(time(0)), "random-seed", "Seed for rng", 'D').value();
@ -274,7 +274,7 @@ int main(int argc, char* argv[]) {
genetic_operator.add( submutate, subtree_mut_prob);
// todo, make this parameter, etc
double std = 0.01;
double std = 1.0;
eoSymConstantMutate<EoType> constmutate(std);
genetic_operator.add(constmutate, constant_mut_prob);
@ -285,7 +285,8 @@ int main(int argc, char* argv[]) {
// genetic_operator.add(lambda_mutate, lambda_mut_prob); // TODO: prob should be settable
//eoQuadSubtreeCrossover<EoType> quad(node_selector);
eoBinSubtreeCrossover<EoType> bin(node_selector);
eoSizeLevelCrossover<EoType> bin;//(node_selector);
//eoBinSubtreeCrossover<EoType> bin(node_selector);
genetic_operator.add(bin, subtree_xover_prob);
eoBinHomologousCrossover<EoType> hom;
@ -298,7 +299,7 @@ int main(int argc, char* argv[]) {
eoSymPopEval<EoType> evaluator(check, measure, maximumSize);
eoDetTournamentSelect<EoType> selectOne(tournamentsize);
eoGeneralBreeder<EoType> breeder(selectOne, genetic_operator);
eoGeneralBreeder<EoType> breeder(selectOne, genetic_operator,1);
eoPlusReplacement<EoType> replace;
// Terminators

View file

@ -109,7 +109,9 @@ int main() {
multi_function f = compile(pop);
compile_time = time(0);
vector<double> out(pop.size());
cout << "Compiled" << endl;
for (unsigned j = 0; j < dataset.n_records(); ++j) {
f(&dataset.get_inputs(j)[0], &out[0]);
}

View file

@ -1,5 +1,5 @@
# 101 2 nan nan
0 -0
0.0 -0
0.1 -8.89903723981037e-05
0.2 -0.00122598240763888
0.3 -0.00517587564272387