Using TestFunctions
The high_dimensional_sampling
package implements a variety of functions on
which sampling procedures can be tested. These are all classes with the
functions.TestFunction
class as their base. This base class automatically
keeps track of the number of function evaluations and performs checks on the
input data to make sure it has the correct number of dimensions. The
TestFunction
class is abstract and can not be instantiated itself.
As testfunctions are implemented as classes, they can be evaluated after
initialisation. For example, if we want to evaluate the Cosine
testfunction
at x=2.65
, we would use the following script:
import high_dimensional_sampling as hds
f = hds.functions.Cosine()
y = f(2.65)
Some testfunctions also have their derivative implemented. To get the
derivative at a specific location, simply add True
as second argument to the
function call:
y_prime = f(2.65, True)
If no derivative is implemented for the instantiated testfunction, a
functions.NoDerivativeError
is raised.
Currently the following functions are implemented in the functions
module
of the package:
Dimensionalities provided between parentheses can be configured at initialisation.
For all functions in the table above the function can in principle be known by the user performing the optimisation. This makes for a possible biassed optimisation, as the user can tune the parameters of the optimisation procedure. To counteract this, there are additionally four hidden functions implemented, which get their evaluated values from precompiled binaries. This makes their functional values unknown to the user.
The HiddenFunction
s are implemented in the functions
module. Their
properties are listed in the table below. All of them have an optional
compiled_against
input argument, which can be either '18.04' or '16.04'.
This value indicated the binary to use for the function, which differ in
the version of Ubuntu against they were compiled.
None of the HiddenFunction
s have their derivative implemented.
Function | #dimensions | Range minimum | Range maximum |
---|---|---|---|
HiddenFunction1 | 2 | -30 | 30 |
HiddenFunction2 | 4 | -7 | 7 |
HiddenFunction3 | 6 | 0 | 1 |
HiddenFunction4 | 16 | -500 | 500 |
You can define your own testfunctions by creating a class that derives from the
functions.TestFunction
base class. Your new testfunction should implement
the following methods:
- init(self, ...): initialisation method. Can take extra input in the form of extra input arguments, but any such parameters should have defaults defined.
-
_evaluate(self, x): method that evaluates the test function at coordinate
x
. Be aware thatx
is a numpy array of shape(nDatapoints, nVariables)
and can contain multiple rows (i.e. data points). This method should return the function values of your test fucntion in the form of a numpy array of shape(nDatapoints, nOutputVariables)
. -
_derivative(self, x): same as
_evaluate
, but now for the derivative of the testfunction. If no derivative is implemented, this method should raise afunctions.NoDerivativeError
.
Have a look at Using and Looping over TestFunctions for more information on how to automatically select and loop over test functions.