00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <iostream>
00013 #include <vector>
00014
00015 #include "TMVA/GeneticAlgorithm.h"
00016 #include "TMVA/GeneticFitter.h"
00017 #include "TMVA/IFitterTarget.h"
00018
00019 using namespace std;
00020
00021 namespace TMVA {
00022
00023
00024 class MyFitness : public IFitterTarget {
00025 public:
00026 MyFitness() : IFitterTarget() {
00027 }
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 Double_t EstimatorFunction( std::vector<Double_t> & factors ){
00041
00042 return (10.- factors.at(0) *factors.at(1) + factors.at(2));
00043
00044
00045 }
00046 };
00047
00048
00049
00050
00051
00052
00053
00054
00055 void exampleGA(){
00056 std::cout << "\nEXAMPLE" << std::endl;
00057
00058
00059 vector<Interval*> ranges;
00060 ranges.push_back( new Interval(0,15,30) );
00061 ranges.push_back( new Interval(0,13) );
00062 ranges.push_back( new Interval(0,5,3) );
00063
00064 for( std::vector<Interval*>::iterator it = ranges.begin(); it != ranges.end(); it++ ){
00065 std::cout << " range: " << (*it)->GetMin() << " " << (*it)->GetMax() << std::endl;
00066 }
00067
00068 IFitterTarget* myFitness = new MyFitness();
00069
00070
00071
00072
00073
00074
00075
00076 const TString name( "exampleGA" );
00077 const TString opts( "PopSize=100:Steps=30" );
00078
00079 GeneticFitter mg( *myFitness, name, ranges, opts);
00080
00081
00082 std::vector<Double_t> result;
00083 Double_t estimator = mg.Run(result);
00084
00085 int n = 0;
00086 for( std::vector<Double_t>::iterator it = result.begin(); it<result.end(); it++ ){
00087 std::cout << "FACTOR " << n << " : " << (*it) << std::endl;
00088 n++;
00089 }
00090
00091 }
00092
00093
00094
00095
00096
00097
00098
00099 }
00100
00101 int main( int argc, char** argv )
00102 {
00103 cout << "Start Test TMVAGAexample" << endl
00104 << "========================" << endl
00105 << endl;
00106
00107 TMVA::exampleGA();
00108 }