Using apprentice to perform function optimization
In apprentice, we can perform optimization on predition functions so as to minimize
the loss function
For this purpose, a base class Minimizer is provided in apprentice.
In this tutorial, we describe the Minimizer base class, the available implementation
of the Minimizer base class, and how you can create your own implementation of the
Minimizer base class.
More specifically, in this tutorial, we will:
Test the install
Learn about the
Minimizerbase classLearn about the available implementation of the
Minimizerbase classLearn how to construct a different implementations of the
Minimizerbase class
Getting started
To install apprentice, execute the following commands:
git clone git@github.com:HEPonHPC/apprentice.git
cd apprentice/
pip install .
cd ..
Then, test the installation as described in the test installation documentation.
Minimizer base class
Here, the functions of the Minimizer base class are discussed. More details
can be found in minimizer code documentation.
Construction methods
To construct a Minimizer object, call the __init__ function:
def __init__(self, function, **kwargs)
where function is the object of a class that inherits the Function base class.
Abstract (unimplemented) methods
Minimizer has one abstract (unimplemented) method.
def minimize(self,x0): Minimize the prediction function with starting pointx0. This function is required to be implemented in the inheriting class.
Available implementations of the Function base class in apprentice
ScipyMinimizer
The implementation of the minimize function in ScipyMinimizer minimizes
the prediction function using SciPy. The signature of the abstract function is:
def minimize(self, x0=<array>, nrestart=<int>, method=<str>, tol=<float>)
where
x0: starting pointnrestart: starting pointmethod: solver (method) to use. The allowed values include“lbfgsb”: L-BFGS-B algorithm
tol: tolerance value
See ScipyMinimizer code documentation
for more details. Additionally, the ScipyMinimizer unit test script contains the
construction and usage of the operations over the ScipyMinimizer object.
Construct your own implementation of the Minimizer base class
To implement your own minimizer (optimization) function, all you have to do is to
implement the abstract function.
Then you can construct your object using the
construction methods.
To override the __init__ constructor method, use the template in the code snippet below:
def __init__(self, function, **kwargs):
super(<Your class name>, self).__init__(function, **kwargs)
"""
add additional construction code here
"""
# ...