Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# testeo.cpp

    00001 /*
    00002  *             Copyright (C) 2005 Maarten Keijzer
    00003  *
    00004  *          This program is free software; you can redistribute it and/or modify
    00005  *          it under the terms of version 2 of the GNU General Public License as
    00006  *          published by the Free Software Foundation.
    00007  *
    00008  *          This program is distributed in the hope that it will be useful,
    00009  *          but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010  *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00011  *          GNU General Public License for more details.
    00012  *
    00013  *          You should have received a copy of the GNU General Public License
    00014  *          along with this program; if not, write to the Free Software
    00015  *          Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00016  */
    00017
    00018
    00019 #include <LanguageTable.h>
    00020 #include <TreeBuilder.h>
    00021 #include <FunDef.h>
    00022 #include <Dataset.h>
    00023
    00024 #include <eoSymInit.h>
    00025 #include <eoSym.h>
    00026 #include <eoPop.h>
    00027 #include <eoSymMutate.h>
    00028 #include <eoSymCrossover.h>
    00029 #include <eoSymEval.h>
    00030
    00031 typedef EoSym<double> EoType;
    00032
    00033 int main() {
    00034
    00035     LanguageTable table;
    00036     table.add_function(sum_token, 2);
    00037     table.add_function(prod_token, 2);
    00038     table.add_function(inv_token, 1);
    00039     table.add_function(min_token, 1);
    00040     table.add_function( SymVar(0).token(), 0);
    00041
    00042     table.add_function(tan_token, 1);
    00043
    00044     table.add_function(sum_token, 0);
    00045     table.add_function(prod_token, 0);
    00046
    00047     TreeBuilder builder(table);
    00048
    00049     eoSymInit<EoType> init(builder);
    00050
    00051     eoPop<EoType> pop(10, init);
    00052
    00053     for (unsigned i = 0; i < pop.size(); ++i) {
    00054         // write out pretty printed
    00055         cout << (Sym) pop[i] << endl;
    00056     }
    00057
    00058     BiasedNodeSelector node_selector;
    00059     eoSymSubtreeMutate<EoType> mutate1(builder, node_selector);
    00060     eoSymNodeMutate<EoType> mutate2(table);
    00061
    00062     cout << "****** MUTATION ************" << endl;
    00063
    00064     for (unsigned i = 0; i < pop.size(); ++i) {
    00065
    00066         cout << "Before  " << (Sym) pop[i] << endl;
    00067         mutate1(pop[i]);
    00068         cout << "After 1 " << (Sym) pop[i] << endl;
    00069         mutate2(pop[i]);
    00070         cout << "After 2 " << (Sym) pop[i] << endl;
    00071     }
    00072
    00073     cout << "****** CROSSOVER ***********" << endl;
    00074
    00075     eoQuadSubtreeCrossover<EoType> quad(node_selector);
    00076     eoBinSubtreeCrossover<EoType> bin(node_selector);
    00077     eoBinHomologousCrossover<EoType> hom;
    00078
    00079     for (unsigned i = 0; i < pop.size()-1; ++i) {
    00080         cout << "Before    " << (Sym) pop[i] << endl;
    00081         cout << "Before    " << (Sym) pop[i+1] << endl;
    00082
    00083         hom(pop[i], pop[i+1]);
    00084
    00085         cout << "After hom  " << (Sym) pop[i] << endl;
    00086         cout << "After hom  " << (Sym) pop[i+1] << endl;
    00087
    00088
    00089         quad(pop[i], pop[i+1]);
    00090
    00091         cout << "After quad " << (Sym) pop[i] << endl;
    00092         cout << "After quad " << (Sym) pop[i+1] << endl;
    00093
    00094         bin(pop[i], pop[i+1]);
    00095
    00096         cout << "After bin  " << (Sym) pop[i] << endl;
    00097         cout << "After bin  " << (Sym) pop[i+1] << endl;
    00098
    00099         cout << endl;
    00100     }
    00101
    00102     cout << "****** Evaluation **********" << endl;
    00103
    00104     Dataset dataset;
    00105     dataset.load_data("test_data.txt");
    00106     IntervalBoundsCheck check(dataset.input_minima(), dataset.input_maxima());
    00107     ErrorMeasure measure(dataset, 0.90, ErrorMeasure::mean_squared_scaled);
    00108
    00109     eoSymPopEval<EoType> evaluator(check, measure, 20000);
    00110
    00111     eoPop<EoType> dummy;
    00112     evaluator(pop, dummy);
    00113
    00114     for (unsigned i = 0; i < pop.size(); ++i) {
    00115         cout << pop[i] << endl;
    00116     }
    00117
    00118 }
    00119