updated include dependencies
This commit is contained in:
parent
6b0cfffe09
commit
40f5377cf1
21 changed files with 87 additions and 59 deletions
|
|
@ -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\
|
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
|
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
|
OBJS= $(CXXSOURCES:.cpp=.o) c_compile.o
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ libsym.a: $(OBJS)
|
||||||
rm libsym.a; ar cq $(SYMLIB) $(OBJS)
|
rm libsym.a; ar cq $(SYMLIB) $(OBJS)
|
||||||
|
|
||||||
check: $(TESTPROGRAMS)
|
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}
|
test/test_compile: test/test_compile.o ${SYMLIB}
|
||||||
$(CXX) -o test/test_compile test/test_compile.o $(SYMLIB) ${LIBS}
|
$(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)
|
test/test_mf: test/test_mf.o $(SYMLIB)
|
||||||
$(CXX) -o test/test_mf test/test_mf.o $(SYMLIB) ${LIBS}
|
$(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
|
# eo
|
||||||
../../src/libeo.a:
|
../../src/libeo.a:
|
||||||
make -C ../../src libeo.a
|
make -C ../../src libeo.a
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@
|
||||||
#define EOSYM_H_
|
#define EOSYM_H_
|
||||||
|
|
||||||
#include <EO.h>
|
#include <EO.h>
|
||||||
#include <Sym.h>
|
#include <sym/Sym.h>
|
||||||
#include <FunDef.h>
|
#include <fun/FunDef.h>
|
||||||
|
|
||||||
|
|
||||||
template <class Fitness>
|
template <class Fitness>
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@
|
||||||
|
|
||||||
#include <eoSymCrossover.h>
|
#include <eoSymCrossover.h>
|
||||||
#include <utils/eoRNG.h>
|
#include <utils/eoRNG.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
bool subtree_quad(Sym& a, Sym& b, NodeSelector& select) {
|
bool subtree_quad(Sym& a, Sym& b, NodeSelector& select) {
|
||||||
NodeSelector::NodeSelection sel_a = select.select_node(a);
|
NodeSelector::NodeSelection sel_a = select.select_node(a);
|
||||||
|
|
@ -75,4 +78,46 @@ bool homologous_bin(Sym& a, const Sym& b) {
|
||||||
return org != a;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
#define EOSYMINIT_H
|
#define EOSYMINIT_H
|
||||||
|
|
||||||
#include <eoInit.h>
|
#include <eoInit.h>
|
||||||
#include <TreeBuilder.h>
|
#include <gen/TreeBuilder.h>
|
||||||
|
|
||||||
/** Default initializer, Koza style */
|
/** Default initializer, Koza style */
|
||||||
template <class EoType>
|
template <class EoType>
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,10 @@ bool mutate_constants(Sym& sym, double stdev) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i = 0; i < values.size(); ++i) {
|
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);
|
sym = set_constants(sym, values);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@
|
||||||
#ifndef SYMMUTATE_H
|
#ifndef SYMMUTATE_H
|
||||||
#define SYMMUTATE_H
|
#define SYMMUTATE_H
|
||||||
|
|
||||||
#include <TreeBuilder.h>
|
#include <gen/TreeBuilder.h>
|
||||||
#include <NodeSelector.h>
|
#include <gen/NodeSelector.h>
|
||||||
|
|
||||||
#include <eoSym.h>
|
#include <eoSym.h>
|
||||||
#include <eoOp.h>
|
#include <eoOp.h>
|
||||||
|
|
|
||||||
|
|
@ -77,39 +77,6 @@ std::ostream& operator<<(std::ostream& os, const Interval& val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TEST_INTERVAL
|
#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
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
#define SYMCOMPILE_H_
|
#define SYMCOMPILE_H_
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <sym/Sym.h>
|
||||||
|
|
||||||
typedef double (*single_function)(const double []);
|
typedef double (*single_function)(const double []);
|
||||||
typedef double (*multi_function)(const double[], double[]);
|
typedef double (*multi_function)(const double[], double[]);
|
||||||
|
|
|
||||||
|
|
@ -247,8 +247,6 @@ class Const : public FunDef {
|
||||||
}
|
}
|
||||||
|
|
||||||
Interval eval(const vector<Interval>& _, const vector<Interval>& inputs) const {
|
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);
|
return Interval(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "Sym.h"
|
#include "sym/Sym.h"
|
||||||
#include "Interval.h"
|
#include "eval/Interval.h"
|
||||||
|
|
||||||
class FunDef {
|
class FunDef {
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
#ifndef SYMOPS_H
|
#ifndef SYMOPS_H
|
||||||
#define 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);
|
||||||
extern Sym operator*(Sym a, Sym b);
|
extern Sym operator*(Sym a, Sym b);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
#ifndef LANGUAGE_TABLE_H
|
#ifndef LANGUAGE_TABLE_H
|
||||||
#define LANGUAGE_TABLE_H
|
#define LANGUAGE_TABLE_H
|
||||||
|
|
||||||
#include "token.h"
|
#include <sym/token.h>
|
||||||
|
|
||||||
class LanguageImpl;
|
class LanguageImpl;
|
||||||
class Sym;
|
class Sym;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
#ifndef NODESELECTOR_H
|
#ifndef NODESELECTOR_H
|
||||||
#define NODESELECTOR_H
|
#define NODESELECTOR_H
|
||||||
|
|
||||||
#include <Sym.h>
|
#include <sym/Sym.h>
|
||||||
|
|
||||||
/** Base class for selecting nodes */
|
/** Base class for selecting nodes */
|
||||||
class NodeSelector {
|
class NodeSelector {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
#ifndef TREEBUILDER_H_
|
#ifndef TREEBUILDER_H_
|
||||||
#define TREEBUILDER_H_
|
#define TREEBUILDER_H_
|
||||||
|
|
||||||
#include "Sym.h"
|
#include "sym/Sym.h"
|
||||||
#include "LanguageTable.h"
|
#include "LanguageTable.h"
|
||||||
|
|
||||||
class TreeBuilder {
|
class TreeBuilder {
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,9 @@ struct UniqueNodeStats { virtual ~UniqueNodeStats(){} };
|
||||||
#else
|
#else
|
||||||
#define USE_TR1 0
|
#define USE_TR1 0
|
||||||
#endif
|
#endif
|
||||||
|
// TR1 is buggy at times
|
||||||
|
#undef USE_TR1
|
||||||
|
#define USE_TR1 0
|
||||||
|
|
||||||
#if USE_TR1
|
#if USE_TR1
|
||||||
#include <tr1/unordered_map>
|
#include <tr1/unordered_map>
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
if (args.pimpl && args.args_ptr == &args.pimpl->owned_args) {
|
||||||
pimpl = new SymArgsImpl(*args.pimpl);
|
pimpl = new SymArgsImpl(*args.pimpl);
|
||||||
args_ptr = &pimpl->owned_args;
|
args_ptr = &pimpl->owned_args;
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class SymArgs {
|
||||||
~SymArgs();
|
~SymArgs();
|
||||||
|
|
||||||
SymArgs(const SymArgs& args);
|
SymArgs(const SymArgs& args);
|
||||||
const SymArgs& SymArgs::operator=(const SymArgs& other);
|
SymArgs& operator=(const SymArgs& other);
|
||||||
|
|
||||||
size_t len() const;
|
size_t len() const;
|
||||||
const std::vector<Sym>& vec() const { return *args_ptr; }
|
const std::vector<Sym>& vec() const { return *args_ptr; }
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
/* Population */
|
/* 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();
|
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);
|
genetic_operator.add( submutate, subtree_mut_prob);
|
||||||
|
|
||||||
// todo, make this parameter, etc
|
// todo, make this parameter, etc
|
||||||
double std = 0.01;
|
double std = 1.0;
|
||||||
eoSymConstantMutate<EoType> constmutate(std);
|
eoSymConstantMutate<EoType> constmutate(std);
|
||||||
genetic_operator.add(constmutate, constant_mut_prob);
|
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
|
// genetic_operator.add(lambda_mutate, lambda_mut_prob); // TODO: prob should be settable
|
||||||
|
|
||||||
//eoQuadSubtreeCrossover<EoType> quad(node_selector);
|
//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);
|
genetic_operator.add(bin, subtree_xover_prob);
|
||||||
|
|
||||||
eoBinHomologousCrossover<EoType> hom;
|
eoBinHomologousCrossover<EoType> hom;
|
||||||
|
|
@ -298,7 +299,7 @@ int main(int argc, char* argv[]) {
|
||||||
eoSymPopEval<EoType> evaluator(check, measure, maximumSize);
|
eoSymPopEval<EoType> evaluator(check, measure, maximumSize);
|
||||||
|
|
||||||
eoDetTournamentSelect<EoType> selectOne(tournamentsize);
|
eoDetTournamentSelect<EoType> selectOne(tournamentsize);
|
||||||
eoGeneralBreeder<EoType> breeder(selectOne, genetic_operator);
|
eoGeneralBreeder<EoType> breeder(selectOne, genetic_operator,1);
|
||||||
eoPlusReplacement<EoType> replace;
|
eoPlusReplacement<EoType> replace;
|
||||||
|
|
||||||
// Terminators
|
// Terminators
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,9 @@ int main() {
|
||||||
multi_function f = compile(pop);
|
multi_function f = compile(pop);
|
||||||
compile_time = time(0);
|
compile_time = time(0);
|
||||||
vector<double> out(pop.size());
|
vector<double> out(pop.size());
|
||||||
|
|
||||||
|
cout << "Compiled" << endl;
|
||||||
|
|
||||||
for (unsigned j = 0; j < dataset.n_records(); ++j) {
|
for (unsigned j = 0; j < dataset.n_records(); ++j) {
|
||||||
f(&dataset.get_inputs(j)[0], &out[0]);
|
f(&dataset.get_inputs(j)[0], &out[0]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
# 101 2 nan nan
|
# 101 2 nan nan
|
||||||
0 -0
|
0.0 -0
|
||||||
0.1 -8.89903723981037e-05
|
0.1 -8.89903723981037e-05
|
||||||
0.2 -0.00122598240763888
|
0.2 -0.00122598240763888
|
||||||
0.3 -0.00517587564272387
|
0.3 -0.00517587564272387
|
||||||
|
|
|
||||||
Reference in a new issue