Prints the manual of requested solver.
Parameters: | solver_name – (optional) name of the solver to request a manual from. If none is specified, a general manual is printed. |
---|
Raises KeyError if solver_name is not registered.
Basic function maximization routine. Maximizes f within the given box constraints.
Parameters: |
|
---|---|
Returns: | retrieved maximum, extra information and solver info |
This function will implicitly choose an appropriate solver and its initialization based on num_evals and the box constraints.
Basic function minimization routine. Minimizes f within the given box constraints.
Parameters: |
|
---|---|
Returns: | retrieved minimum, extra information and solver info |
This function will implicitly choose an appropriate solver and its initialization based on num_evals and the box constraints.
Optimizes func with given solver.
Parameters: |
|
---|
Returns the solution and a namedtuple with further details.
Result details includes the following:
Statistics gathered while solving a problem:
Wraps an existing call log (as dictionary) around f.
This allows you to communicate known function values to solvers. (currently available solvers do not use this info)
Decorates f with given input domain constraints.
Parameters: |
|
---|
*custom constraints are binary functions that yield False in case of violations.
>>> def f(x):
... return x
>>> fc = wrap_constraints(f, default=-1, range_oc={'x': [0, 1]})
>>> fc(x=0.5)
0.5
>>> fc(x=1)
1
>>> fc(x=5)
-1
>>> fc(x=0)
-1
We can define any custom constraint that we want. For instance, assume we have a binary function with arguments x and y, and we want to make sure that the provided values remain within the unit circle.
>>> def f(x, y):
... return x + y
>>> circle_constraint = lambda x, y: (x ** 2 + y ** 2) <= 1
>>> fc = wrap_constraints(f, default=1234, custom=[circle_constraint])
>>> fc(0.0, 0.0)
0.0
>>> fc(1.0, 0.0)
1.0
>>> fc(0.5, 0.5)
1.0
>>> fc(1, 0.5)
1234
Creates a Solver from given parameters.
Parameters: |
|
---|
Use optunity.manual() to get a list of registered solvers. For constructor arguments per solver, please refer to Solver overview.
Raises KeyError if
Function decorator to perform cross-validation as configured.
Parameters: |
|
---|---|
Returns: | a cross_validated_callable with the proper configuration. |
This resulting decorator must be used on a function with the following signature (+ potential other arguments):
Parameters: |
|
---|
y_train and y_test must be available of the y argument to this function is not None.
These 4 keyword arguments will be bound upon decoration. Further arguments will remain free (e.g. hyperparameter names).
>>> data = list(range(5))
>>> @cross_validated(x=data, num_folds=5, folds=[[[i] for i in range(5)]], aggregator=identity)
... def f(x_train, x_test, a):
... return x_test[0] + a
>>> f(a=1)
[1, 2, 3, 4, 5]
>>> f(1)
[1, 2, 3, 4, 5]
>>> f(a=2)
[2, 3, 4, 5, 6]
Generates folds for a given number of rows.
Parameters: |
|
---|---|
Returns: | a list of folds, each fold is a list of instance indices |
>>> folds = generate_folds(num_rows=6, num_folds=2, clusters=[[1, 2]], strata=[[3,4]])
>>> len(folds)
2
>>> i1 = [idx for idx, fold in enumerate(folds) if 1 in fold]
>>> i2 = [idx for idx, fold in enumerate(folds) if 2 in fold]
>>> i1 == i2
True
>>> i3 = [idx for idx, fold in enumerate(folds) if 3 in fold]
>>> i4 = [idx for idx, fold in enumerate(folds) if 4 in fold]
>>> i3 == i4
False
Warning
Instances in strata are not necessarily spread out over all folds. Some folds may already be full due to clusters. This effect should be negligible.
Parallel map using multiprocessing.
Parameters: |
|
---|---|
Returns: | a list containing the results |
Warning
This function will not work in IPython: https://github.com/claesenm/optunity/issues/8.
Warning
Python’s multiprocessing library is incompatible with Jython.
Returns a list of all available solvers.
These can be used in optunity.make_solver().