Maximum Likelihood Estimation#
Restricting amptools to limit output: AMPTOOLS_DEBUG_LEVEL=”ERROR”
import os
import time
from pyamptools import atiSetup
from pyamptools.mle import runFits
os.environ["AMPTOOLS_REPORT_LEVEL"] = "ERROR"
Welcome to JupyROOT 6.28/06
############## SET ENVIRONMENT VARIABLES ##############
PYAMPTOOLS_HOME = os.environ["PYAMPTOOLS_HOME"]
USE_MPI, USE_GPU, RANK_MPI = atiSetup.setup(globals())
cfgfile = f"{PYAMPTOOLS_HOME}/tests/samples/SIMPLE_EXAMPLE/fitInit.cfg"
randomSeed = int(time.time())
seedfile = "seed_file"
numRnd = 0
atiSetup| jupyter-book called python3.9
------------------------------------------------
atiSetup| MPI is disabled
atiSetup| GPU is disabled
------------------------------------------------
atiSetup| Loading library libIUAmpTools.so ............ ON
atiSetup| Loading library libAmpTools.so .............. ON
atiSetup| Loading library libAmpPlotter.so ............ ON
atiSetup| Loading library libAmpsDataIO.so ............ ON
atiSetup| Loading library libFSRoot.so ................ OFF
atiSetup| Loading library libAmpsGen.so ............... OFF
------------------------------------------------
------------------------------------------------
atiSetup| Saved aliases found in /d/grid17/ln16/PyAmpTools/src/pyamptools/.aliases.txt, attempting to load...
atiSetup| minor warning: Unable to alias omegapiAngles - doesn't exist under ROOT namespace
atiSetup| minor warning: Unable to alias URConfig - doesn't exist under ROOT namespace
atiSetup| minor warning: Unable to alias URtypes - doesn't exist under ROOT namespace
print("\n\n === COMMANDLINE ARGUMENTS === ")
print("Config file:", cfgfile)
print("Seed file:", seedfile)
print("Number of random fits:", numRnd)
print("Random seed:", randomSeed)
print(" ============================= \n\n")
=== COMMANDLINE ARGUMENTS ===
Config file: /d/grid17/ln16/PyAmpTools/tests/samples/SIMPLE_EXAMPLE/fitInit.cfg
Seed file: seed_file
Number of random fits: 0
Random seed: 1761334904
=============================
We first load the configuration file by first passing it through a parser. We can display a detailed representation of its contents like so
parser = ConfigFileParser(cfgfile)
cfgInfo: ConfigurationInfo = parser.getConfigurationInfo()
cfgInfo.display()
=================================================================
| ^ |
| / \ Version: v0.15.3-2-g0753-dirty |
| /---\ |
| / \ GDouble: 8 bytes |
| / \ MP MPI: NO |
| ------- GPU: NO |
| | |
| | doi.org/10.5281/zenodo.5039377 |
| | OOLS |
=================================================================
AmpToolsInterface is the primary way to interact with the AmpTools minimization library. From this object we can access things like a ParameterManager and a MinimizationManager.
ati = AmpToolsInterface(cfgInfo)
AmpToolsInterface.setRandomSeed(randomSeed)
A fit module is defined in PyAmpTools to run the standard MLE fit. We simply pass the recently created ati instance and the number of fits with random initializations to perform. Randomization is beneficial as the optimizer could get stuck in unwanted local minima.
A single fit is performed without randomization is performed if numRnd=0
See fit for API and source code, including runFits below
nll = runFits(ati, N=numRnd)
LIKELIHOOD BEFORE MINIMIZATION: 112356.11732090596
LIKELIHOOD AFTER MINIMIZATION (NO RANDOMIZATION): 14346.408126566821
After the fit is complete, a .fit file will be created with the name defined by the fit keyword in the cfg file. This file contains the results of the fit. A tutorial on how to plot the results of these .fit files will be shown in
!rm -f seed_0.txt
!rm -f normint
!rm -f result_0.fit