benchopt.BaseObjective¶
- class benchopt.BaseObjective(**parameters)¶
Base class to define an objective function
Objectives that derive from this class should implement three methods:
set_data(**data): stores the info from a given dataset to be able to compute the objective value on these data.
get_objective(): exports the data from the dataset and the parameters from the objective function as a dictionary that will be passed as parameters of the solver’s set_objective method in order to specify the objective function of the benchmark.
compute(beta): computes the value of the objective function for an given estimate beta. Beta is given as np.array of size corresponding to the dimension value returned by Dataset.get_data. The output should be a float or a dictionary of floats. If a dictionary is returned, it should at least contain a key value associated to a scalar value which will be used to detect convergence. With a dictionary, multiple metric values can be stored at once instead of runnning each separately.
- abstract compute(beta)¶
Compute the value of the objective given the current estimate beta.
- Parameters
- betandarray or tuple of ndarray
The current estimate of the parameters being optimized.
- Returns
- objective_valuefloat or dict {‘name’: float}
The value(s) of the objective function. If a dictionary is returned, it should at least contain a key value associated to a scalar value which will be used to detect convergence. With a dictionary, multiple metric values can be stored at once instead of runnning each separately.
- abstract get_objective()¶
Return the objective parameters for the solver.
- Returns
- objective_dict: dict
Parameters of the objective that will be given to the solver when calling
Solver.set_objective(**objective_dict)
.
- abstract get_one_solution()¶
Return one solution for which the objective can be evaluated.
This method is mainly for testing purposes, to check that the method Objective.compute can be called and that it returns a compatible type for benchopt. The returned object will be passed to
Objective.compute
.
- abstract set_data(**data)¶
Store the info on a dataset to be able to compute the objective.
- Parameters
- **data: dict
Extra parameters of the objective. This dictionary is retrieved by calling
data = Dataset.get_data()
.
- skip(**data)¶
Used to decide if the
Objective
is compatible with the data.- Parameters
- **data: dict
Extra parameters of the objective. This dictionary is retrieved by calling
data = Dataset.get_data()
.
- Returns
- skipbool
Whether this objective should be skipped or not for this data (accessible in the objective attributes).
- reasonstr | None
The reason why it should be skipped for display purposes. If skip is False, the reason should be None.