This exectutable gives an example of a very simple use of the genetic algorithm of TMVA
- Project : TMVA - a Root-integrated toolkit for multivariate data analysis
- Package : TMVA
- Exectuable: TMVAGAexample
Start Test TMVAGAexample
========================
EXAMPLE
range: 0 15
range: 0 13
range: 0 5
: fitness: -163.187 f_0: 13.4483 f_1: 12.878 f_2: 0
---
: fitness: -165.016 f_0: 13.9655 f_1: 12.532 f_2: 0
---
: fitness: -171.229 f_0: 13.9655 f_1: 12.9769 f_2: 0
---
: fitness: -171.498 f_0: 14.4828 f_1: 12.532 f_2: 0
---
: fitness: -171.498 f_0: 14.4828 f_1: 12.532 f_2: 0
---
: fitness: -171.498 f_0: 14.4828 f_1: 12.532 f_2: 0
---
: fitness: -171.498 f_0: 14.4828 f_1: 12.532 f_2: 0
---
: fitness: -177.217 f_0: 14.4828 f_1: 12.9269 f_2: 0
---
: fitness: -177.217 f_0: 14.4828 f_1: 12.9269 f_2: 0
---
: fitness: -177.941 f_0: 14.4828 f_1: 12.9769 f_2: 0
---
: fitness: -177.941 f_0: 14.4828 f_1: 12.9769 f_2: 0
---
: fitness: -177.941 f_0: 14.4828 f_1: 12.9769 f_2: 0
---
: fitness: -177.98 f_0: 15 f_1: 12.532 f_2: 0
---
: fitness: -177.98 f_0: 15 f_1: 12.532 f_2: 0
---
: fitness: -180.815 f_0: 15 f_1: 12.721 f_2: 0
---
: fitness: -183.903 f_0: 15 f_1: 12.9269 f_2: 0
---
: fitness: -184.653 f_0: 15 f_1: 12.9769 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
: fitness: -184.937 f_0: 15 f_1: 12.9958 f_2: 0
---
FACTOR 0 : 15
FACTOR 1 : 12.9958
FACTOR 2 : 0
#include <iostream>
#include <vector>
using namespace std;
class MyFitness : public IFitterTarget {
public:
MyFitness() : IFitterTarget() {
}
Double_t EstimatorFunction( std::vector<Double_t> & factors ){
return (10.- factors.at(0) *factors.at(1) + factors.at(2));
}
};
class MyGA2nd : public GeneticAlgorithm {
public:
MyGA2nd( IFitterTarget& target,
Int_t size, vector<Interval*>& ranges ) : GeneticAlgorithm(target,
size, ranges ){
}
};
void TMVAGAexample() {
std::cout << "Start Test TMVAGAexample" << std::endl
<< "========================" << std::endl
<< "\nEXAMPLE" << std::endl;
vector<Interval*> ranges;
ranges.push_back( new Interval(0,15,30) );
ranges.push_back( new Interval(0,13) );
ranges.push_back( new Interval(0,5,3) );
for( std::vector<Interval*>::iterator it = ranges.begin(); it != ranges.end(); it++ ){
std::cout << " range: " << (*it)->GetMin() << " " << (*it)->GetMax() << std::endl;
}
IFitterTarget* myFitness = new MyFitness();
MyGA2nd
mg( *myFitness, 100, ranges );
#define CONVSTEPS 20
#define CONVCRIT 0.0001
#define SCSTEPS 10
#define SCRATE 5
#define SCFACTOR 0.95
do {
mg.GetGeneticPopulation().Print(0);
std::cout << "---" << std::endl;
mg.GetGeneticPopulation().TrimPopulation();
mg.SpreadControl( SCSTEPS, SCRATE, SCFACTOR );
}
while (!
mg.HasConverged( CONVSTEPS, CONVCRIT ));
GeneticGenes* genes =
mg.GetGeneticPopulation().GetGenes( 0 );
std::vector<Double_t> gvec;
gvec = genes->GetFactors();
for( std::vector<Double_t>::iterator it = gvec.begin(); it<gvec.end(); it++ ){
std::cout <<
"FACTOR " <<
n <<
" : " << (*it) << std::endl;
}
}
int main(
int argc,
char** argv )
{
TMVAGAexample();
}
int main(int argc, char **argv)
static constexpr double mg
create variable transformations
- Author
- Andreas Hoecker
Definition in file TMVAGAexample.C.