Skip to content
Snippets Groups Projects
Commit 019a75d2 authored by Julian Pychy's avatar Julian Pychy
Browse files

improvements for evo minimizer

parent bba6fcce
No related branches found
No related tags found
No related merge requests found
......@@ -429,6 +429,44 @@ int main(int __argc,char *__argv[]){
}
if(mode == "evoserver"){
std::vector<std::string>::const_iterator itFix;
for (itFix=fixedParams.begin(); itFix!=fixedParams.end(); ++itFix){
upar.Fix( (*itFix) );
}
std::shared_ptr<NetworkServer> theServer(new NetworkServer(theAppParams->serverPort(),
theAppParams->noOfClients(),
eventsData.size(),
mcData.size()));
PwaFcnServer theFcnServer(theLhPtr, theFitParamBase, theServer, outputFileNameSuffix);
theServer->WaitForFirstClientLogin();
EvoMinimizer theEvoMinimizer(theFcnServer, upar, pbarpEnv::instance()->parser()->evoPopulation(),
pbarpEnv::instance()->parser()->evoIterations());
Info <<"start evolutionary minimizer "<< endmsg;
std::vector<double> finalParamVec = theEvoMinimizer.Minimize();
theServer->BroadcastClosingMessage();
Info << "Closing server." << endmsg;
fitParams finalFitParams=theStartparams;
theFitParamBase->getFitParamVal(finalParamVec, finalFitParams);
fitParams finalFitErrs=theErrorparams;
std::ostringstream finalResultname;
finalResultname << "finalResult" << outputFileNameSuffix << ".dat";
std::ofstream theStream ( finalResultname.str().c_str() );
theFitParamBase->dumpParams(theStream, finalFitParams, finalFitErrs);
return 1;
}
std::shared_ptr<EvtDataBaseList> pbarpEventListPtr(new EvtDataBaseList(pbarpEnv::instance()));
pbarpEventListPtr->read(eventsData, mcData);
......
......@@ -31,6 +31,7 @@ EvoMinimizer::EvoMinimizer(AbsFcn& theAbsFcn, MnUserParameters upar, int populat
, _theAbsFcn(&theAbsFcn)
{
_bestParamsGlobal = upar;
Info << evologo << endmsg;
}
......@@ -39,17 +40,23 @@ std::vector<double> EvoMinimizer::Minimize(){
double startlh = (*_theAbsFcn)(_bestParamsGlobal.Params());
double minlh = startlh;
double itlh = startlh;
int numnoimprovement = 0;
Info << "Start LH = " << startlh << endmsg;
for(int i = 0; i<_iterations; i++){
Info << "Iteration " << i+1 << " / " << _iterations << " Best LH "<< minlh << endmsg;
_bestParamsIteration = _bestParamsGlobal;
int numbetterlh = 0;
double maxitlhspread=0;
for(int j = 0; j<_population; j++){
_tmpParams = _bestParamsIteration;
_tmpParams = _bestParamsGlobal;
itlh = minlh;
ShuffleParams();
double currentlh = (*_theAbsFcn)(_tmpParams.Params());
if(fabs(currentlh - minlh) > maxitlhspread){
maxitlhspread = fabs(currentlh - minlh);
}
if(currentlh < minlh){
minlh = currentlh;
_bestParamsGlobal = _tmpParams;
......@@ -58,11 +65,31 @@ std::vector<double> EvoMinimizer::Minimize(){
numbetterlh++;
}
}
if(maxitlhspread < 0.1)
break;
if(numbetterlh == 0)
numnoimprovement++;
if(numnoimprovement>5){
numnoimprovement=0;
AdjustSigma(0.5);
}
if((numbetterlh / _population) < 0.15)
AdjustSigma(0.95);
else if((numbetterlh / _population) > 0.2)
AdjustSigma(1.05);
Info << "===============================================" << endmsg;
Info << "Iteration " << i+1 << " / " << _iterations << " done. Best LH " << minlh << endmsg;
Info << "Likelihood improvements " << numbetterlh << " / " << _population << endmsg;
if(((double)numbetterlh / (double)_population) <= 0.01){
AdjustSigma(0.9);
Info << "Decreasing errors." << endmsg;
}
else if(((double)numbetterlh / (double)_population) > 0.05){
AdjustSigma(1.1);
Info << "Increasing errors." << endmsg;
}
Info << "===============================================" << endmsg;
}
return _bestParamsGlobal.Params();
......@@ -108,3 +135,57 @@ void EvoMinimizer::AdjustSigma(double factor){
_bestParamsGlobal.SetError(i, _bestParamsGlobal.Error(i) * factor);
}
}
const char* EvoMinimizer::evologo = R"(
....$$$$ZZZ$$Z7ZZ:..... .
.~$ZZ.............O$ZZ+.
.. ... ...=...............ZZZ.. .... .. ..ZOO: ...
......$OZZ$7$ZZ$ZZZZZZZZZZ$ZZ.....ZO$.... .. .ZO. .
..:8OO...................:ZZ.......Z$. .. .. ..OO...
...OOO. .... .. .... ....$Z...
.8OO..... . . .. . +$Z...
. .OO... .......$Z...
.OO. ... ....Z:Z$... .
OO...... . ........ .. ...$$:ZZ.ZZOZ.. .
OOO88O8OOI........... .. ....... .....ZZZZZ...$ZZO...
8O.....,$ZZOZZOOOO8OOOZ$........ ..$OZ$..........7$7..
88.. . . ....~ZZOOZOOZZZ$.... .Z....ZZZ$... .$$$:....
.8O..... ................ZZ.. .... ....ZZ.. ..$ZZ....
..8OO... . ....... ........ ....... .OO$. ..$:Z...
...888~.... ..... ....ZOZ.. ...ZZ$..
......88OO. .. ..... .,OZZ.. ....ZZ$.
.888OO............. . ..OOZ.. . ....ZZOO. ..$$Z....
...7888OO$........ . ...ZOOZZZZDZZZO.... ...ZZ$...
.......ZO8O8OOZZ.. . ...ZOOO8Z$..... . ... ZZZ..
....,ZOOOOZ.. . ........=ZOOZZO$...... .ZZ$....
.........=O8.... ..O88OZZ...$ZZZZ?.. ...ZZ....
. ..88O... .. ...OO?ZOZZ... ..ZZZZ.......ZZ...
... .O8O?.... .O8,.ZOZZ$. ....ZZZZ......ZO..
.....ODOI.. .O8.....ZO.. .... .ZZZZ. ..OO.
..OOO8OI.. .. ..O8. ZZZ... . ...Z$$$?.Z$....
.O8..ZOOOOZ..... ZZ.. .ZO.... .. ...ZZZ$$$$.. .
....O8,...ZOOO88O...... .Z.. ..ZZ.... .ZZ$$Z...
...OO8.....ZOO.O8OZ. .....:. .. .ZO... ....$$Z$.
.. .Z8...... .OO$.ZOOO.Z.,O8. . ..$O.. .. ..$$$.
....OO........,OOOOOOOO$Z.OO..... ..$O~....... .ZZZ:
....IZO.......8888O8OO..Z$ZZOO.... ..,Z8....... ...ZO$O
.......=O8888O.. .O88O....OO+OOOOZO88O........~,ZZZ$Z....... . ....ZZ..
.Z888OOO7....O88O............ZOZOOZOOOOZOOOO$.............. ....7ZOO...
..O888OOOO8OOOO8OZZ=IZZOZO8OOO8OOOZZOZ..ZZZ~$ZZ$?.7?I?::?$OOOZZZZZZ$Z.OOZ.
. .O88888888OOOOOOOO8OOOOOOZZOOOZ~..,ZZ=.~=7......ZZZZ$$ZZZZ$Z$ZZZZZZZOZ...
.. .......... ....... .Z$?ZZZOZ$IIZ$=7Z:=7ZZ~.....................$ZZO..
. ... .... ....... .... ..$+I7Z$$ZZZZZZZ$ZZZZZZZZZZZZZ$Z$$..
. ........ ...............+?=...
//**********************************************************************************//
// //
// ApeFrog evolutionary minimizer //
// //
//**********************************************************************************//
)";
......@@ -21,6 +21,8 @@
// //
//************************************************************************//
#pragma once
#include <vector>
#include "AbsFcn.hh"
#include "Minuit2/MnUserParameters.h"
......@@ -40,9 +42,10 @@ private:
int _iterations;
AbsFcn* _theAbsFcn;
MnUserParameters _bestParamsGlobal;
MnUserParameters _bestParamsIteration;
MnUserParameters _tmpParams;
void ShuffleParams();
void AdjustSigma(double factor);
static const char* evologo;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment