Objective¶
-
class
pypesto.objective.
AggregatedObjective
(objectives: List[pypesto.objective.objective.Objective], x_names: List[str] = None)¶ Bases:
pypesto.objective.objective.Objective
This class aggregates multiple objectives into one objective.
-
__call__
()¶ Method to obtain arbitrary sensitivities. This is the central method which is always called, also by the get_* methods.
There are different ways in which an optimizer calls the objective function, and in how the objective function provides information (e.g. derivatives via separate functions or along with the function values). The different calling modes increase efficiency in space and time and make the objective flexible.
Parameters: - x – The parameters for which to evaluate the objective function.
- sensi_orders – Specifies which sensitivities to compute, e.g. (0,1) -> fval, grad.
- mode – Whether to compute function values or residuals.
- return_dict – If False (default), the result is a Tuple of the requested values in the requested order. Tuples of length one are flattened. If True, instead a dict is returned which can carry further information.
Returns: By default, this is a tuple of the requested function values and derivatives in the requested order (if only 1 value, the tuple is flattened). If return_dict, then instead a dict is returned with function values and derivatives indicated by ids.
Return type: result
-
__class__
¶ alias of
builtins.type
-
__deepcopy__
(memodict=None)¶
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.aggregated', '__doc__': '\n This class aggregates multiple objectives into one objective.\n ', '__init__': <function AggregatedObjective.__init__>, '__deepcopy__': <function AggregatedObjective.__deepcopy__>, 'aggregate_fun_sensi_orders': <function AggregatedObjective.aggregate_fun_sensi_orders>, 'aggregate_res_sensi_orders': <function AggregatedObjective.aggregate_res_sensi_orders>, 'aggregate_res': <function AggregatedObjective.aggregate_res>, 'aggregate_sres': <function AggregatedObjective.aggregate_sres>, 'aggregate_fun': <function AggregatedObjective.aggregate_fun>, 'aggregate_grad': <function AggregatedObjective.aggregate_grad>, 'aggregate_hess': <function AggregatedObjective.aggregate_hess>, 'aggregate_hessp': <function AggregatedObjective.aggregate_hessp>, 'reset_steadystate_guesses': <function AggregatedObjective.reset_steadystate_guesses>})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
(objectives: List[pypesto.objective.objective.Objective], x_names: List[str] = None)¶ Constructor.
Parameters: objectives (list) – List of pypesto.objetive instances
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.aggregated'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
aggregate_fun
(x)¶
-
aggregate_fun_sensi_orders
(x, sensi_orders)¶
-
aggregate_grad
(x)¶
-
aggregate_hess
(x)¶
-
aggregate_hessp
(x)¶
-
aggregate_res
(x)¶
-
aggregate_res_sensi_orders
(x, sensi_orders)¶
-
aggregate_sres
(x)¶
-
check_grad
(x: numpy.ndarray, x_indices: List[int] = None, eps: float = 1e-05, verbosity: int = 1, mode: str = 'mode_fun') → pandas.core.frame.DataFrame¶ Compare gradient evaluation: Firstly approximate via finite differences, and secondly use the objective gradient.
Parameters: - x – The parameters for which to evaluate the gradient.
- x_indices – List of index values for which to compute gradients. Default: all.
- eps – Finite differences step size. Default: 1e-5.
- verbosity – Level of verbosity for function output. * 0: no output, * 1: summary for all parameters, * 2: summary for individual parameters. Default: 1.
- mode – Residual (MODE_RES) or objective function value (MODE_FUN, default) computation mode.
Returns: gradient, finite difference approximations and error estimates.
Return type: result
-
check_sensi_orders
(sensi_orders, mode) → None¶ Check if the objective is able to compute the requested sensitivities. If not, throw an exception.
Raises: - ValueError if the objective function cannot be called as
requested.
-
get_fval
(x: numpy.ndarray) → float¶ Get the function value at x.
-
get_grad
(x: numpy.ndarray) → numpy.ndarray¶ Get the gradient at x.
-
get_hess
(x: numpy.ndarray) → numpy.ndarray¶ Get the Hessian at x.
-
get_res
(x: numpy.ndarray) → numpy.ndarray¶ Get the residuals at x.
-
get_sres
(x: numpy.ndarray) → numpy.ndarray¶ Get the residual sensitivities at x.
-
has_fun
¶
-
has_grad
¶
-
has_hess
¶
-
has_hessp
¶
-
has_res
¶
-
has_sres
¶
-
initialize
()¶ Initialize the objective function. This function is used at the beginning of an analysis, e.g. optimization, and can e.g. reset the objective memory. By default does nothing.
-
static
output_to_dict
()¶ Convert output tuple to dict.
-
static
output_to_tuple
()¶ Return values as requested by the caller, since usually only a subset is demanded. One output is returned as-is, more than one output are returned as a tuple in order (fval, grad, hess).
-
reset_steadystate_guesses
()¶ Propagates reset_steadystate_guesses() to child objectives if available (currently only applies for amici_objective)
-
update_from_problem
(dim_full: int, x_free_indices: List[int], x_fixed_indices: List[int], x_fixed_vals: List[int])¶ Handle fixed parameters. Later, the objective will be given parameter vectors x of dimension dim, which have to be filled up with fixed parameter values to form a vector of dimension dim_full >= dim. This vector is then used to compute function value and derivatives. The derivatives must later be reduced again to dimension dim.
This is so as to make the fixing of parameters transparent to the caller.
The methods preprocess, postprocess are overwritten for the above functionality, respectively.
Parameters: - dim_full – Dimension of the full vector including fixed parameters.
- x_free_indices – Vector containing the indices (zero-based) of free parameters (complimentary to x_fixed_indices).
- x_fixed_indices – Vector containing the indices (zero-based) of parameter components that are not to be optimized.
- x_fixed_vals – Vector of the same length as x_fixed_indices, containing the values of the fixed parameters.
-
-
class
pypesto.objective.
AmiciCalculator
¶ Bases:
object
Class to perform the actual call to AMICI and obtain requested objective function values.
-
__call__
(x_dct: Dict, sensi_order: int, mode: str, amici_model: Union[amici.Model, amici.ModelPtr], amici_solver: Union[amici.Solver, amici.SolverPtr], edatas: List[amici.ExpData], n_threads: int, x_ids: Sequence[str], parameter_mapping: ParameterMapping)¶ Perform the actual AMICI call.
Called within the
AmiciObjective.__call__()
method.Parameters: - x_dct – Parameters for which to compute function value and derivatives.
- sensi_order – Maximum sensitivity order.
- mode – Call mode (function value or residual based).
- amici_model – The AMICI model.
- amici_solver – The AMICI solver.
- edatas – The experimental data.
- n_threads – Number of threads for AMICI call.
- x_ids – Ids of optimization parameters.
- parameter_mapping – Mapping of optimization to simulation parameters.
-
__class__
¶ alias of
builtins.type
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.amici_calculator', '__doc__': '\n Class to perform the actual call to AMICI and obtain requested objective\n function values.\n ', 'initialize': <function AmiciCalculator.initialize>, '__call__': <function AmiciCalculator.__call__>, '__dict__': <attribute '__dict__' of 'AmiciCalculator' objects>, '__weakref__': <attribute '__weakref__' of 'AmiciCalculator' objects>})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.amici_calculator'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
initialize
()¶ Initialize the calculator. Default: Do nothing.
-
-
class
pypesto.objective.
AmiciObjectBuilder
¶ Bases:
abc.ABC
Allows to build AMICI model, solver, and edatas.
This class is useful for pickling an
pypesto.AmiciObjective
, which is required in some parallelization schemes. Therefore, this class itself must be picklable.-
__abstractmethods__
= frozenset({'create_solver', 'create_edatas', 'create_model'})¶
-
__class__
¶ alias of
abc.ABCMeta
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.amici_objective', '__doc__': 'Allows to build AMICI model, solver, and edatas.\n\n This class is useful for pickling an :class:`pypesto.AmiciObjective`,\n which is required in some parallelization schemes. Therefore, this\n class itself must be picklable.\n ', 'create_model': <function AmiciObjectBuilder.create_model>, 'create_solver': <function AmiciObjectBuilder.create_solver>, 'create_edatas': <function AmiciObjectBuilder.create_edatas>, '__abstractmethods__': frozenset({'create_solver', 'create_edatas', 'create_model'}), '_abc_registry': <_weakrefset.WeakSet object>, '_abc_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache_version': 48})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.amici_objective'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
create_edatas
(model: Union[amici.Model, amici.ModelPtr]) → Sequence[amici.ExpData]¶ Create AMICI experimental data.
-
create_model
() → Union[amici.Model, amici.ModelPtr]¶ Create an AMICI model.
-
create_solver
(model: Union[amici.Model, amici.ModelPtr]) → Union[amici.Solver, amici.SolverPtr]¶ Create an AMICI solver.
-
-
class
pypesto.objective.
AmiciObjective
(amici_model: Union[amici.Model, amici.ModelPtr], amici_solver: Union[amici.Solver, amici.SolverPtr], edatas: Union[Sequence[amici.ExpData], amici.ExpData], max_sensi_order: int = None, x_ids: Sequence[str] = None, x_names: Sequence[str] = None, parameter_mapping: ParameterMapping = None, guess_steadystate: bool = True, n_threads: int = 1, amici_object_builder: pypesto.objective.amici_objective.AmiciObjectBuilder = None, calculator: pypesto.objective.amici_calculator.AmiciCalculator = None)¶ Bases:
pypesto.objective.objective.Objective
This class allows to create an objective directly from an amici model.
-
__call__
()¶ Method to obtain arbitrary sensitivities. This is the central method which is always called, also by the get_* methods.
There are different ways in which an optimizer calls the objective function, and in how the objective function provides information (e.g. derivatives via separate functions or along with the function values). The different calling modes increase efficiency in space and time and make the objective flexible.
Parameters: - x – The parameters for which to evaluate the objective function.
- sensi_orders – Specifies which sensitivities to compute, e.g. (0,1) -> fval, grad.
- mode – Whether to compute function values or residuals.
- return_dict – If False (default), the result is a Tuple of the requested values in the requested order. Tuples of length one are flattened. If True, instead a dict is returned which can carry further information.
Returns: By default, this is a tuple of the requested function values and derivatives in the requested order (if only 1 value, the tuple is flattened). If return_dict, then instead a dict is returned with function values and derivatives indicated by ids.
Return type: result
-
__class__
¶ alias of
builtins.type
-
__deepcopy__
(memodict: Dict = None) → pypesto.objective.amici_objective.AmiciObjective¶
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.amici_objective', '__doc__': '\n This class allows to create an objective directly from an amici model.\n ', '__init__': <function AmiciObjective.__init__>, 'initialize': <function AmiciObjective.initialize>, 'get_bound_fun': <function AmiciObjective.get_bound_fun>, 'get_bound_res': <function AmiciObjective.get_bound_res>, 'rebind_fun': <function AmiciObjective.rebind_fun>, 'rebind_res': <function AmiciObjective.rebind_res>, '__deepcopy__': <function AmiciObjective.__deepcopy__>, '__getstate__': <function AmiciObjective.__getstate__>, '__setstate__': <function AmiciObjective.__setstate__>, '_call_amici': <function AmiciObjective._call_amici>, 'par_arr_to_dct': <function AmiciObjective.par_arr_to_dct>, 'apply_steadystate_guess': <function AmiciObjective.apply_steadystate_guess>, 'store_steadystate_guess': <function AmiciObjective.store_steadystate_guess>, 'reset_steadystate_guesses': <function AmiciObjective.reset_steadystate_guesses>})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__getstate__
() → Dict¶
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
(amici_model: Union[amici.Model, amici.ModelPtr], amici_solver: Union[amici.Solver, amici.SolverPtr], edatas: Union[Sequence[amici.ExpData], amici.ExpData], max_sensi_order: int = None, x_ids: Sequence[str] = None, x_names: Sequence[str] = None, parameter_mapping: ParameterMapping = None, guess_steadystate: bool = True, n_threads: int = 1, amici_object_builder: pypesto.objective.amici_objective.AmiciObjectBuilder = None, calculator: pypesto.objective.amici_calculator.AmiciCalculator = None)¶ Constructor.
Parameters: - amici_model – The amici model.
- amici_solver – The solver to use for the numeric integration of the model.
- edatas – The experimental data. If a list is passed, its entries correspond to multiple experimental conditions.
- max_sensi_order – Maximum sensitivity order supported by the model. Defaults to 2 if the model was compiled with o2mode, otherwise 1.
- x_ids – Ids of optimization parameters. In the simplest case, this will be the AMICI model parameters (default).
- x_names – Names of optimization parameters.
- parameter_mapping – Mapping of optimization parameters to model parameters. Format as created by amici.petab_objective.create_parameter_mapping. The default is just to assume that optimization and simulation parameters coincide.
- guess_steadystate – Whether to guess steadystates based on previous steadystates and respective derivatives. This option may lead to unexpected results for models with conservation laws and should accordingly be deactivated for those models.
- n_threads – Number of threads that are used for parallelization over experimental conditions. If amici was not installed with openMP support this option will have no effect.
- amici_object_builder – AMICI object builder. Allows recreating the objective for pickling, required in some parallelization schemes.
- calculator – Performs the actual calculation of the function values and derivatives.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.amici_objective'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__setstate__
(state: Dict)¶
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
apply_steadystate_guess
(condition_ix: int, x_dct: Dict)¶ Use the stored steadystate as well as the respective sensitivity ( if available) and parameter value to approximate the steadystate at the current parameters using a zeroth or first order taylor approximation: x_ss(x’) = x_ss(x) [+ dx_ss/dx(x)*(x’-x)]
-
check_grad
(x: numpy.ndarray, x_indices: List[int] = None, eps: float = 1e-05, verbosity: int = 1, mode: str = 'mode_fun') → pandas.core.frame.DataFrame¶ Compare gradient evaluation: Firstly approximate via finite differences, and secondly use the objective gradient.
Parameters: - x – The parameters for which to evaluate the gradient.
- x_indices – List of index values for which to compute gradients. Default: all.
- eps – Finite differences step size. Default: 1e-5.
- verbosity – Level of verbosity for function output. * 0: no output, * 1: summary for all parameters, * 2: summary for individual parameters. Default: 1.
- mode – Residual (MODE_RES) or objective function value (MODE_FUN, default) computation mode.
Returns: gradient, finite difference approximations and error estimates.
Return type: result
-
check_sensi_orders
(sensi_orders, mode) → None¶ Check if the objective is able to compute the requested sensitivities. If not, throw an exception.
Raises: - ValueError if the objective function cannot be called as
requested.
-
get_bound_fun
()¶ Generate a fun function that calls _call_amici with MODE_FUN. Defining a non-class function that references self as a local variable will bind the function to a copy of the current self object and will accordingly not take future changes to self into account.
-
get_bound_res
()¶ Generate a res function that calls _call_amici with MODE_RES. Defining a non-class function that references self as a local variable will bind the function to a copy of the current self object and will accordingly not take future changes to self into account.
-
get_fval
(x: numpy.ndarray) → float¶ Get the function value at x.
-
get_grad
(x: numpy.ndarray) → numpy.ndarray¶ Get the gradient at x.
-
get_hess
(x: numpy.ndarray) → numpy.ndarray¶ Get the Hessian at x.
-
get_res
(x: numpy.ndarray) → numpy.ndarray¶ Get the residuals at x.
-
get_sres
(x: numpy.ndarray) → numpy.ndarray¶ Get the residual sensitivities at x.
-
has_fun
¶
-
has_grad
¶
-
has_hess
¶
-
has_hessp
¶
-
has_res
¶
-
has_sres
¶
-
initialize
()¶ Initialize the objective function. This function is used at the beginning of an analysis, e.g. optimization, and can e.g. reset the objective memory. By default does nothing.
-
static
output_to_dict
()¶ Convert output tuple to dict.
-
static
output_to_tuple
()¶ Return values as requested by the caller, since usually only a subset is demanded. One output is returned as-is, more than one output are returned as a tuple in order (fval, grad, hess).
-
par_arr_to_dct
(x: Sequence[float]) → Dict[str, float]¶ Create dict from parameter vector.
-
rebind_fun
()¶ Replace the current fun function with one that is bound to the current instance
-
rebind_res
()¶ Replace the current res function with one that is bound to the current instance
-
reset_steadystate_guesses
()¶ Resets all steadystate guess data
-
store_steadystate_guess
(condition_ix: int, x_dct: Dict, rdata: amici.ReturnData)¶ Store condition parameter, steadystate and steadystate sensitivity in steadystate_guesses if steadystate guesses are enabled for this condition
-
update_from_problem
(dim_full: int, x_free_indices: List[int], x_fixed_indices: List[int], x_fixed_vals: List[int])¶ Handle fixed parameters. Later, the objective will be given parameter vectors x of dimension dim, which have to be filled up with fixed parameter values to form a vector of dimension dim_full >= dim. This vector is then used to compute function value and derivatives. The derivatives must later be reduced again to dimension dim.
This is so as to make the fixing of parameters transparent to the caller.
The methods preprocess, postprocess are overwritten for the above functionality, respectively.
Parameters: - dim_full – Dimension of the full vector including fixed parameters.
- x_free_indices – Vector containing the indices (zero-based) of free parameters (complimentary to x_fixed_indices).
- x_fixed_indices – Vector containing the indices (zero-based) of parameter components that are not to be optimized.
- x_fixed_vals – Vector of the same length as x_fixed_indices, containing the values of the fixed parameters.
-
-
class
pypesto.objective.
CsvHistory
(file: str, x_names: Iterable[str] = None, options: Dict = None)¶ Bases:
pypesto.objective.history.History
Stores a representation of the history in a CSV file.
Parameters: - file – CSV file name.
- x_names – Parameter names.
- options – History options.
-
__abstractmethods__
= frozenset()¶
-
__class__
¶ alias of
abc.ABCMeta
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.history', '__doc__': 'Stores a representation of the history in a CSV file.\n\n Parameters\n ----------\n file:\n CSV file name.\n x_names:\n Parameter names.\n options:\n History options.\n ', '__init__': <function CsvHistory.__init__>, 'update': <function CsvHistory.update>, 'finalize': <function CsvHistory.finalize>, '_update_trace': <function CsvHistory._update_trace>, '_init_trace': <function CsvHistory._init_trace>, '_save_trace': <function CsvHistory._save_trace>, 'get_fval_trace': <function CsvHistory.get_fval_trace>, '__abstractmethods__': frozenset(), '_abc_registry': <_weakrefset.WeakSet object>, '_abc_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache_version': 48})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
(file: str, x_names: Iterable[str] = None, options: Dict = None)¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.history'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
finalize
()¶ Finalize history. Called after a run.
-
get_chi2_trace
() → Sequence[numpy.ndarray]¶ Chi2 value trace.
-
get_fval_trace
() → pandas.core.series.Series¶ Function value trace.
-
get_grad_trace
() → Sequence[numpy.ndarray]¶ Gradient trace.
-
get_hess_trace
() → Sequence[numpy.ndarray]¶ Hessian trace.
-
get_res_trace
() → Sequence[numpy.ndarray]¶ Residual trace.
-
get_schi2_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Chi2 value sensitivity trace.
-
get_sres_trace
() → Sequence[numpy.ndarray]¶ Residual sensitivity trace.
-
get_time_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Execution time trace.
-
get_x_trace
() → Sequence[numpy.ndarray]¶ Parameter trace.
-
n_fval
¶ Number of function evaluations.
-
n_grad
¶ Number of gradient evaluations.
-
n_hess
¶ Number of Hessian evaluations.
-
n_res
¶ Number of residual evaluations.
-
n_sres
¶ Number or residual sensitivity evaluations.
-
start_time
¶ Start time.
-
update
(x: numpy.ndarray, sensi_orders: Tuple[int, ...], mode: str, result: Dict[str, Union[float, numpy.ndarray]]) → None¶ Update history after a function evaluation.
Parameters: - x – The parameter vector.
- sensi_orders – The sensitivity orders computed.
- mode – The objective function mode computed (function value or residuals).
- result – The objective function values for parameters x, sensitivities sensi_orders and mode mode.
-
class
pypesto.objective.
Hdf5History
(id: str, file: str, options: Dict = None)¶ Bases:
pypesto.objective.history.History
Stores a representation of the history in an HDF5 file.
Parameters: - id – Id of the history
- file – HDF5 file name.
- options – History options.
-
__abstractmethods__
= frozenset()¶
-
__class__
¶ alias of
abc.ABCMeta
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.history', '__doc__': 'Stores a representation of the history in an HDF5 file.\n\n Parameters\n ----------\n id:\n Id of the history\n file:\n HDF5 file name.\n options:\n History options.\n ', '__init__': <function Hdf5History.__init__>, 'update': <function Hdf5History.update>, 'finalize': <function Hdf5History.finalize>, 'get_x_trace': <function Hdf5History.get_x_trace>, 'get_fval_trace': <function Hdf5History.get_fval_trace>, 'get_grad_trace': <function Hdf5History.get_grad_trace>, 'get_hess_trace': <function Hdf5History.get_hess_trace>, 'get_res_trace': <function Hdf5History.get_res_trace>, 'get_sres_trace': <function Hdf5History.get_sres_trace>, 'get_chi2_trace': <function Hdf5History.get_chi2_trace>, 'get_schi2_trace': <function Hdf5History.get_schi2_trace>, 'get_time_trace': <function Hdf5History.get_time_trace>, '__abstractmethods__': frozenset(), '_abc_registry': <_weakrefset.WeakSet object>, '_abc_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache_version': 48})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
(id: str, file: str, options: Dict = None)¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.history'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
finalize
()¶ Finalize history. Called after a run.
-
get_chi2_trace
() → Sequence[numpy.ndarray]¶ Chi2 value trace.
-
get_fval_trace
() → Sequence[float]¶ Function value trace.
-
get_grad_trace
() → Sequence[numpy.ndarray]¶ Gradient trace.
-
get_hess_trace
() → Sequence[numpy.ndarray]¶ Hessian trace.
-
get_res_trace
() → Sequence[numpy.ndarray]¶ Residual trace.
-
get_schi2_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Chi2 value sensitivity trace.
-
get_sres_trace
() → Sequence[numpy.ndarray]¶ Residual sensitivity trace.
-
get_time_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Execution time trace.
-
get_x_trace
() → Sequence[numpy.ndarray]¶ Parameter trace.
-
n_fval
¶ Number of function evaluations.
-
n_grad
¶ Number of gradient evaluations.
-
n_hess
¶ Number of Hessian evaluations.
-
n_res
¶ Number of residual evaluations.
-
n_sres
¶ Number or residual sensitivity evaluations.
-
start_time
¶ Start time.
-
update
(x: numpy.ndarray, sensi_orders: Tuple[int, ...], mode: str, result: Dict[str, Union[float, numpy.ndarray]]) → None¶ Update history after a function evaluation.
Parameters: - x – The parameter vector.
- sensi_orders – The sensitivity orders computed.
- mode – The objective function mode computed (function value or residuals).
- result – The objective function values for parameters x, sensitivities sensi_orders and mode mode.
-
class
pypesto.objective.
History
(options: Dict = None)¶ Bases:
pypesto.objective.history.HistoryBase
Tracks numbers of function evaluations only, no trace.
Parameters: options – History options. -
__abstractmethods__
= frozenset()¶
-
__class__
¶ alias of
abc.ABCMeta
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.history', '__doc__': 'Tracks numbers of function evaluations only, no trace.\n\n Parameters\n ----------\n options:\n History options.\n ', '__init__': <function History.__init__>, 'update': <function History.update>, 'finalize': <function History.finalize>, '_update_counts': <function History._update_counts>, 'n_fval': <property object>, 'n_grad': <property object>, 'n_hess': <property object>, 'n_res': <property object>, 'n_sres': <property object>, 'start_time': <property object>, '__abstractmethods__': frozenset(), '_abc_registry': <_weakrefset.WeakSet object>, '_abc_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache_version': 48})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
(options: Dict = None)¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.history'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
finalize
()¶ Finalize history. Called after a run.
-
get_chi2_trace
() → Sequence[numpy.ndarray]¶ Chi2 value trace.
-
get_fval_trace
() → Sequence[float]¶ Function value trace.
-
get_grad_trace
() → Sequence[numpy.ndarray]¶ Gradient trace.
-
get_hess_trace
() → Sequence[numpy.ndarray]¶ Hessian trace.
-
get_res_trace
() → Sequence[numpy.ndarray]¶ Residual trace.
-
get_schi2_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Chi2 value sensitivity trace.
-
get_sres_trace
() → Sequence[numpy.ndarray]¶ Residual sensitivity trace.
-
get_time_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Execution time trace.
-
get_x_trace
() → Sequence[numpy.ndarray]¶ Parameter trace.
-
n_fval
¶ Number of function evaluations.
-
n_grad
¶ Number of gradient evaluations.
-
n_hess
¶ Number of Hessian evaluations.
-
n_res
¶ Number of residual evaluations.
-
n_sres
¶ Number or residual sensitivity evaluations.
-
start_time
¶ Start time.
-
update
(x: numpy.ndarray, sensi_orders: Tuple[int, ...], mode: str, result: Dict[str, Union[float, numpy.ndarray]]) → None¶ Update history after a function evaluation.
Parameters: - x – The parameter vector.
- sensi_orders – The sensitivity orders computed.
- mode – The objective function mode computed (function value or residuals).
- result – The objective function values for parameters x, sensitivities sensi_orders and mode mode.
-
-
class
pypesto.objective.
HistoryBase
¶ Bases:
abc.ABC
Abstract base class for history objects.
Can be used as a dummy history, but does not implement any history functionality.
-
__abstractmethods__
= frozenset()¶
-
__class__
¶ alias of
abc.ABCMeta
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.history', '__doc__': 'Abstract base class for history objects.\n\n Can be used as a dummy history, but does not implement any history\n functionality.\n ', 'update': <function HistoryBase.update>, 'finalize': <function HistoryBase.finalize>, 'n_fval': <property object>, 'n_grad': <property object>, 'n_hess': <property object>, 'n_res': <property object>, 'n_sres': <property object>, 'start_time': <property object>, 'get_x_trace': <function HistoryBase.get_x_trace>, 'get_fval_trace': <function HistoryBase.get_fval_trace>, 'get_grad_trace': <function HistoryBase.get_grad_trace>, 'get_hess_trace': <function HistoryBase.get_hess_trace>, 'get_res_trace': <function HistoryBase.get_res_trace>, 'get_sres_trace': <function HistoryBase.get_sres_trace>, 'get_chi2_trace': <function HistoryBase.get_chi2_trace>, 'get_schi2_trace': <function HistoryBase.get_schi2_trace>, 'get_time_trace': <function HistoryBase.get_time_trace>, '__abstractmethods__': frozenset(), '_abc_registry': <_weakrefset.WeakSet object>, '_abc_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache_version': 48})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.history'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
finalize
()¶ Finalize history. Called after a run.
-
get_chi2_trace
() → Sequence[numpy.ndarray]¶ Chi2 value trace.
-
get_fval_trace
() → Sequence[float]¶ Function value trace.
-
get_grad_trace
() → Sequence[numpy.ndarray]¶ Gradient trace.
-
get_hess_trace
() → Sequence[numpy.ndarray]¶ Hessian trace.
-
get_res_trace
() → Sequence[numpy.ndarray]¶ Residual trace.
-
get_schi2_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Chi2 value sensitivity trace.
-
get_sres_trace
() → Sequence[numpy.ndarray]¶ Residual sensitivity trace.
-
get_time_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Execution time trace.
-
get_x_trace
() → Sequence[numpy.ndarray]¶ Parameter trace.
-
n_fval
¶ Number of function evaluations.
-
n_grad
¶ Number of gradient evaluations.
-
n_hess
¶ Number of Hessian evaluations.
-
n_res
¶ Number of residual evaluations.
-
n_sres
¶ Number or residual sensitivity evaluations.
-
start_time
¶ Start time.
-
update
(x: numpy.ndarray, sensi_orders: Tuple[int, ...], mode: str, result: Dict[str, Union[float, numpy.ndarray]]) → None¶ Update history after a function evaluation.
Parameters: - x – The parameter vector.
- sensi_orders – The sensitivity orders computed.
- mode – The objective function mode computed (function value or residuals).
- result – The objective function values for parameters x, sensitivities sensi_orders and mode mode.
-
-
class
pypesto.objective.
HistoryOptions
(trace_record: bool = False, trace_record_grad: bool = True, trace_record_hess: bool = True, trace_record_res: bool = True, trace_record_sres: bool = True, trace_record_chi2: bool = True, trace_record_schi2: bool = True, trace_save_iter: int = 10, storage_file: str = None)¶ Bases:
dict
Options for the objective that are used in optimization, profiles and sampling.
In addition implements a factory pattern to generate history objects.
Parameters: - trace_record – Flag indicating whether to record the trace of function calls. The trace_record_* flags only become effective if trace_record is True. Default: False.
- trace_record_grad – Flag indicating whether to record the gradient in the trace. Default: True.
- trace_record_hess – Flag indicating whether to record the Hessian in the trace. Default: False.
- trace_record_res – Flag indicating whether to record the residual in the trace. Default: False.
- trace_record_sres – Flag indicating whether to record the residual sensitivities in the trace. Default: False.
- trace_record_chi2 – Flag indicating whether to record the chi2 in the trace. Default: True.
- trace_record_schi2 – Flag indicating whether to record the chi2 sensitivities in the trace. Default: True.
- trace_save_iter – After how many iterations to store the trace.
- storage_file – File to save the history to. Can be any of None, a “{filename}.csv”, or a “{filename}.hdf5” file. Depending on the values, the create_history method creates the appropriate object. Occurrences of “{id}” in the file name are replaced by the id upon creation of a history, if applicable.
-
__class__
¶ alias of
builtins.type
-
__contains__
()¶ True if D has a key k, else False.
-
__delattr__
¶ Delete self[key].
-
__delitem__
¶ Delete self[key].
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.history', '__doc__': '\n Options for the objective that are used in optimization, profiles\n and sampling.\n\n In addition implements a factory pattern to generate history objects.\n\n Parameters\n ----------\n trace_record:\n Flag indicating whether to record the trace of function calls.\n The trace_record_* flags only become effective if\n trace_record is True.\n Default: False.\n trace_record_grad:\n Flag indicating whether to record the gradient in the trace.\n Default: True.\n trace_record_hess:\n Flag indicating whether to record the Hessian in the trace.\n Default: False.\n trace_record_res:\n Flag indicating whether to record the residual in\n the trace.\n Default: False.\n trace_record_sres:\n Flag indicating whether to record the residual sensitivities in\n the trace.\n Default: False.\n trace_record_chi2:\n Flag indicating whether to record the chi2 in the trace.\n Default: True.\n trace_record_schi2:\n Flag indicating whether to record the chi2 sensitivities in the\n trace.\n Default: True.\n trace_save_iter:\n After how many iterations to store the trace.\n storage_file:\n File to save the history to. Can be any of None, a\n "{filename}.csv", or a "{filename}.hdf5" file. Depending on the values,\n the `create_history` method creates the appropriate object.\n Occurrences of "{id}" in the file name are replaced by the `id`\n upon creation of a history, if applicable.\n ', '__init__': <function HistoryOptions.__init__>, '__getattr__': <function HistoryOptions.__getattr__>, '__setattr__': <slot wrapper '__setitem__' of 'dict' objects>, '__delattr__': <slot wrapper '__delitem__' of 'dict' objects>, 'assert_instance': <staticmethod object>, 'create_history': <function HistoryOptions.create_history>, '__dict__': <attribute '__dict__' of 'HistoryOptions' objects>, '__weakref__': <attribute '__weakref__' of 'HistoryOptions' objects>})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattr__
(key)¶
-
__getattribute__
¶ Return getattr(self, name).
-
__getitem__
()¶ x.__getitem__(y) <==> x[y]
-
__gt__
¶ Return self>value.
-
__hash__
= None¶
-
__init__
(trace_record: bool = False, trace_record_grad: bool = True, trace_record_hess: bool = True, trace_record_res: bool = True, trace_record_sres: bool = True, trace_record_chi2: bool = True, trace_record_schi2: bool = True, trace_save_iter: int = 10, storage_file: str = None)¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__iter__
¶ Implement iter(self).
-
__le__
¶ Return self<=value.
-
__len__
¶ Return len(self).
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.history'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Set self[key] to value.
-
__setitem__
¶ Set self[key] to value.
-
__sizeof__
() → size of D in memory, in bytes¶
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
static
assert_instance
(maybe_options: Union[HistoryOptions, Dict]) → pypesto.objective.history.HistoryOptions¶ Returns a valid options object.
Parameters: maybe_options (HistoryOptions or dict) –
-
clear
() → None. Remove all items from D.¶
-
copy
() → a shallow copy of D¶
-
create_history
(id: str, x_names: Iterable[str]) → pypesto.objective.history.History¶ Factory method creating a
History
object.Parameters: - id – Identifier for the history.
- x_names – Parameter names.
-
fromkeys
()¶ Returns a new dict with keys from iterable and values equal to value.
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised
-
popitem
() → (k, v), remove and return some (key, value) pair as a¶ 2-tuple; but raise KeyError if D is empty.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
([E, ]**F) → None. Update D from dict/iterable E and F.¶ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
-
values
() → an object providing a view on D's values¶
-
class
pypesto.objective.
MemoryHistory
(options: Dict = None)¶ Bases:
pypesto.objective.history.History
Tracks numbers of function evaluations and keeps an in-memory trace of function evaluations.
Parameters: options – History options. -
__abstractmethods__
= frozenset()¶
-
__class__
¶ alias of
abc.ABCMeta
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.history', '__doc__': 'Tracks numbers of function evaluations and keeps an in-memory\n trace of function evaluations.\n\n Parameters\n ----------\n options:\n History options.\n ', '__init__': <function MemoryHistory.__init__>, 'update': <function MemoryHistory.update>, '_update_trace': <function MemoryHistory._update_trace>, 'get_x_trace': <function MemoryHistory.get_x_trace>, 'get_fval_trace': <function MemoryHistory.get_fval_trace>, 'get_grad_trace': <function MemoryHistory.get_grad_trace>, 'get_hess_trace': <function MemoryHistory.get_hess_trace>, 'get_res_trace': <function MemoryHistory.get_res_trace>, 'get_sres_trace': <function MemoryHistory.get_sres_trace>, 'get_chi2_trace': <function MemoryHistory.get_chi2_trace>, 'get_schi2_trace': <function MemoryHistory.get_schi2_trace>, 'get_time_trace': <function MemoryHistory.get_time_trace>, '__abstractmethods__': frozenset(), '_abc_registry': <_weakrefset.WeakSet object>, '_abc_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache_version': 48})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
(options: Dict = None)¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.history'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
finalize
()¶ Finalize history. Called after a run.
-
get_chi2_trace
() → Sequence[numpy.ndarray]¶ Chi2 value trace.
-
get_fval_trace
() → Sequence[float]¶ Function value trace.
-
get_grad_trace
() → Sequence[numpy.ndarray]¶ Gradient trace.
-
get_hess_trace
() → Sequence[numpy.ndarray]¶ Hessian trace.
-
get_res_trace
() → Sequence[numpy.ndarray]¶ Residual trace.
-
get_schi2_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Chi2 value sensitivity trace.
-
get_sres_trace
() → Sequence[numpy.ndarray]¶ Residual sensitivity trace.
-
get_time_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Execution time trace.
-
get_x_trace
() → Sequence[numpy.ndarray]¶ Parameter trace.
-
n_fval
¶ Number of function evaluations.
-
n_grad
¶ Number of gradient evaluations.
-
n_hess
¶ Number of Hessian evaluations.
-
n_res
¶ Number of residual evaluations.
-
n_sres
¶ Number or residual sensitivity evaluations.
-
start_time
¶ Start time.
-
update
(x: numpy.ndarray, sensi_orders: Tuple[int, ...], mode: str, result: Dict[str, Union[float, numpy.ndarray]]) → None¶ Update history after a function evaluation.
Parameters: - x – The parameter vector.
- sensi_orders – The sensitivity orders computed.
- mode – The objective function mode computed (function value or residuals).
- result – The objective function values for parameters x, sensitivities sensi_orders and mode mode.
-
-
class
pypesto.objective.
Objective
(fun: Callable = None, grad: Union[Callable, bool] = None, hess: Callable = None, hessp: Callable = None, res: Callable = None, sres: Union[Callable, bool] = None, fun_accept_sensi_orders: bool = False, res_accept_sensi_orders: bool = False, x_names: List[str] = None)¶ Bases:
object
The objective class is a simple wrapper around the objective function, giving a standardized way of calling. Apart from that, it manages several things including fixing of parameters and history.
The objective function is assumed to be in the format of a cost function, log-likelihood function, or log-posterior function. These functions are subject to minimization. For profiling and sampling, the sign is internally flipped, all returned and stored values are however given as returned by this objective function. If maximization is to be performed, the sign should be flipped before creating the objective function.
Parameters: - fun –
The objective function to be minimized. If it only computes the objective function value, it should be of the form
fun(x) -> float
where x is an 1-D array with shape (n,), and n is the parameter space dimension.
- grad –
Method for computing the gradient vector. If it is a callable, it should be of the form
grad(x) -> array_like, shape (n,).
If its value is True, then fun should return the gradient as a second output.
- hess –
Method for computing the Hessian matrix. If it is a callable, it should be of the form
hess(x) -> array, shape (n,n).
If its value is True, then fun should return the gradient as a second, and the Hessian as a third output, and grad should be True as well.
- hessp –
Method for computing the Hessian vector product, i.e.
hessp(x, v) -> array_like, shape (n,)
computes the product H*v of the Hessian of fun at x with v.
- res –
Method for computing residuals, i.e.
res(x) -> array_like, shape(m,).
- sres –
Method for computing residual sensitivities. If its is a callable, it should be of the form
sres(x) -> array, shape (m,n).
If its value is True, then res should return the residual sensitivities as a second output.
- fun_accept_sensi_orders – Flag indicating whether fun takes sensi_orders as an argument. Default: False.
- res_accept_sensi_orders – Flag indicating whether res takes sensi_orders as an argument. Default: False
- x_names – Parameter names. None if no names provided, otherwise a list of str, length dim_full (as in the Problem class). Can be read by the problem.
-
history
¶ For storing the call history. Initialized by the methods, e.g. the optimizer, in initialize_history().
-
pre_post_processor
¶ Preprocess input values to and postprocess output values from __call__. Configured in update_from_problem().
Notes
If fun_accept_sensi_orders resp. res_accept_sensi_orders is True, fun resp. res can also return dictionaries instead of tuples. In that case, they are expected to follow the naming conventions in
constants.py
. This is of interest, because when __call__ is called with return_dict = True, the full dictionary is returned, which can contain e.g. also simulation data or debugging information.-
__call__
()¶ Method to obtain arbitrary sensitivities. This is the central method which is always called, also by the get_* methods.
There are different ways in which an optimizer calls the objective function, and in how the objective function provides information (e.g. derivatives via separate functions or along with the function values). The different calling modes increase efficiency in space and time and make the objective flexible.
Parameters: - x – The parameters for which to evaluate the objective function.
- sensi_orders – Specifies which sensitivities to compute, e.g. (0,1) -> fval, grad.
- mode – Whether to compute function values or residuals.
- return_dict – If False (default), the result is a Tuple of the requested values in the requested order. Tuples of length one are flattened. If True, instead a dict is returned which can carry further information.
Returns: By default, this is a tuple of the requested function values and derivatives in the requested order (if only 1 value, the tuple is flattened). If return_dict, then instead a dict is returned with function values and derivatives indicated by ids.
Return type: result
-
__class__
¶ alias of
builtins.type
-
__deepcopy__
(memodict=None) → pypesto.objective.objective.Objective¶
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.objective', '__doc__': '\n The objective class is a simple wrapper around the objective function,\n giving a standardized way of calling. Apart from that, it manages several\n things including fixing of parameters and history.\n\n The objective function is assumed to be in the format of a cost function,\n log-likelihood function, or log-posterior function. These functions are\n subject to minimization. For profiling and sampling, the sign is internally\n flipped, all returned and stored values are however given as returned\n by this objective function. If maximization is to be performed, the sign\n should be flipped before creating the objective function.\n\n Parameters\n ----------\n\n fun:\n The objective function to be minimized. If it only computes the\n objective function value, it should be of the form\n\n ``fun(x) -> float``\n\n where x is an 1-D array with shape (n,), and n is the parameter space\n dimension.\n\n grad:\n Method for computing the gradient vector. If it is a callable,\n it should be of the form\n\n ``grad(x) -> array_like, shape (n,).``\n\n If its value is True, then fun should return the gradient as a second\n output.\n\n hess:\n Method for computing the Hessian matrix. If it is a callable,\n it should be of the form\n\n ``hess(x) -> array, shape (n,n).``\n\n If its value is True, then fun should return the gradient as a\n second, and the Hessian as a third output, and grad should be True as\n well.\n\n hessp:\n Method for computing the Hessian vector product, i.e.\n\n ``hessp(x, v) -> array_like, shape (n,)``\n\n computes the product H*v of the Hessian of fun at x with v.\n\n res:\n Method for computing residuals, i.e.\n\n ``res(x) -> array_like, shape(m,).``\n\n sres:\n Method for computing residual sensitivities. If its is a callable,\n it should be of the form\n\n ``sres(x) -> array, shape (m,n).``\n\n If its value is True, then res should return the residual\n sensitivities as a second output.\n\n fun_accept_sensi_orders:\n Flag indicating whether fun takes sensi_orders as an argument.\n Default: False.\n\n res_accept_sensi_orders:\n Flag indicating whether res takes sensi_orders as an argument.\n Default: False\n\n x_names:\n Parameter names. None if no names provided, otherwise a list of str,\n length dim_full (as in the Problem class). Can be read by the\n problem.\n\n Attributes\n ----------\n\n history:\n For storing the call history. Initialized by the methods, e.g. the\n optimizer, in `initialize_history()`.\n\n pre_post_processor:\n Preprocess input values to and postprocess output values from\n __call__. Configured in `update_from_problem()`.\n\n Notes\n -----\n\n If fun_accept_sensi_orders resp. res_accept_sensi_orders is True,\n fun resp. res can also return dictionaries instead of tuples.\n In that case, they are expected to follow the naming conventions\n in ``constants.py``. This is of interest, because when __call__ is\n called with return_dict = True, the full dictionary is returned, which\n can contain e.g. also simulation data or debugging information.\n ', '__init__': <function Objective.__init__>, '__deepcopy__': <function Objective.__deepcopy__>, 'initialize': <function Objective.initialize>, 'has_fun': <property object>, 'has_grad': <property object>, 'has_hess': <property object>, 'has_hessp': <property object>, 'has_res': <property object>, 'has_sres': <property object>, 'check_sensi_orders': <function Objective.check_sensi_orders>, '__call__': <function Objective.__call__>, '_call_unprocessed': <function Objective._call_unprocessed>, '_call_mode_fun': <function Objective._call_mode_fun>, '_call_mode_res': <function Objective._call_mode_res>, 'output_to_dict': <staticmethod object>, 'output_to_tuple': <staticmethod object>, 'get_fval': <function Objective.get_fval>, 'get_grad': <function Objective.get_grad>, 'get_hess': <function Objective.get_hess>, 'get_res': <function Objective.get_res>, 'get_sres': <function Objective.get_sres>, 'update_from_problem': <function Objective.update_from_problem>, 'check_grad': <function Objective.check_grad>, '__dict__': <attribute '__dict__' of 'Objective' objects>, '__weakref__': <attribute '__weakref__' of 'Objective' objects>})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
(fun: Callable = None, grad: Union[Callable, bool] = None, hess: Callable = None, hessp: Callable = None, res: Callable = None, sres: Union[Callable, bool] = None, fun_accept_sensi_orders: bool = False, res_accept_sensi_orders: bool = False, x_names: List[str] = None)¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.objective'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
check_grad
(x: numpy.ndarray, x_indices: List[int] = None, eps: float = 1e-05, verbosity: int = 1, mode: str = 'mode_fun') → pandas.core.frame.DataFrame¶ Compare gradient evaluation: Firstly approximate via finite differences, and secondly use the objective gradient.
Parameters: - x – The parameters for which to evaluate the gradient.
- x_indices – List of index values for which to compute gradients. Default: all.
- eps – Finite differences step size. Default: 1e-5.
- verbosity – Level of verbosity for function output. * 0: no output, * 1: summary for all parameters, * 2: summary for individual parameters. Default: 1.
- mode – Residual (MODE_RES) or objective function value (MODE_FUN, default) computation mode.
Returns: gradient, finite difference approximations and error estimates.
Return type: result
-
check_sensi_orders
(sensi_orders, mode) → None¶ Check if the objective is able to compute the requested sensitivities. If not, throw an exception.
Raises: - ValueError if the objective function cannot be called as
requested.
-
get_fval
(x: numpy.ndarray) → float¶ Get the function value at x.
-
get_grad
(x: numpy.ndarray) → numpy.ndarray¶ Get the gradient at x.
-
get_hess
(x: numpy.ndarray) → numpy.ndarray¶ Get the Hessian at x.
-
get_res
(x: numpy.ndarray) → numpy.ndarray¶ Get the residuals at x.
-
get_sres
(x: numpy.ndarray) → numpy.ndarray¶ Get the residual sensitivities at x.
-
has_fun
¶
-
has_grad
¶
-
has_hess
¶
-
has_hessp
¶
-
has_res
¶
-
has_sres
¶
-
initialize
()¶ Initialize the objective function. This function is used at the beginning of an analysis, e.g. optimization, and can e.g. reset the objective memory. By default does nothing.
-
static
output_to_dict
()¶ Convert output tuple to dict.
-
static
output_to_tuple
()¶ Return values as requested by the caller, since usually only a subset is demanded. One output is returned as-is, more than one output are returned as a tuple in order (fval, grad, hess).
-
update_from_problem
(dim_full: int, x_free_indices: List[int], x_fixed_indices: List[int], x_fixed_vals: List[int])¶ Handle fixed parameters. Later, the objective will be given parameter vectors x of dimension dim, which have to be filled up with fixed parameter values to form a vector of dimension dim_full >= dim. This vector is then used to compute function value and derivatives. The derivatives must later be reduced again to dimension dim.
This is so as to make the fixing of parameters transparent to the caller.
The methods preprocess, postprocess are overwritten for the above functionality, respectively.
Parameters: - dim_full – Dimension of the full vector including fixed parameters.
- x_free_indices – Vector containing the indices (zero-based) of free parameters (complimentary to x_fixed_indices).
- x_fixed_indices – Vector containing the indices (zero-based) of parameter components that are not to be optimized.
- x_fixed_vals – Vector of the same length as x_fixed_indices, containing the values of the fixed parameters.
- fun –
-
class
pypesto.objective.
OptimizerHistory
(history: pypesto.objective.history.History, x0: numpy.ndarray)¶ Bases:
pypesto.objective.history.HistoryBase
Objective call history. Also handles saving of intermediate results.
-
fval0, fval_min
Initial and best function value found.
-
x0, x_min
Initial and best parameters found.
-
__abstractmethods__
= frozenset()¶
-
__class__
¶ alias of
abc.ABCMeta
-
__delattr__
¶ Implement delattr(self, name).
-
__dict__
= mappingproxy({'__module__': 'pypesto.objective.history', '__doc__': '\n Objective call history. Also handles saving of intermediate results.\n\n Attributes\n ----------\n fval0, fval_min:\n Initial and best function value found.\n x0, x_min:\n Initial and best parameters found.\n ', '__init__': <function OptimizerHistory.__init__>, 'update': <function OptimizerHistory.update>, 'finalize': <function OptimizerHistory.finalize>, '_update_vals': <function OptimizerHistory._update_vals>, '__abstractmethods__': frozenset(), '_abc_registry': <_weakrefset.WeakSet object>, '_abc_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache_version': 48})¶
-
__dir__
() → list¶ default dir() implementation
-
__eq__
¶ Return self==value.
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__hash__
¶ Return hash(self).
-
__init__
(history: pypesto.objective.history.History, x0: numpy.ndarray) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__
()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__
¶ Return self<=value.
-
__lt__
¶ Return self<value.
-
__module__
= 'pypesto.objective.history'¶
-
__ne__
¶ Return self!=value.
-
__new__
()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__
()¶ helper for pickle
-
__reduce_ex__
()¶ helper for pickle
-
__repr__
¶ Return repr(self).
-
__setattr__
¶ Implement setattr(self, name, value).
-
__sizeof__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
__subclasshook__
()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__
¶ list of weak references to the object (if defined)
-
finalize
()¶ Finalize history. Called after a run.
-
get_chi2_trace
() → Sequence[numpy.ndarray]¶ Chi2 value trace.
-
get_fval_trace
() → Sequence[float]¶ Function value trace.
-
get_grad_trace
() → Sequence[numpy.ndarray]¶ Gradient trace.
-
get_hess_trace
() → Sequence[numpy.ndarray]¶ Hessian trace.
-
get_res_trace
() → Sequence[numpy.ndarray]¶ Residual trace.
-
get_schi2_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Chi2 value sensitivity trace.
-
get_sres_trace
() → Sequence[numpy.ndarray]¶ Residual sensitivity trace.
-
get_time_trace
(t: Optional[int] = None) → Sequence[numpy.ndarray]¶ Execution time trace.
-
get_x_trace
() → Sequence[numpy.ndarray]¶ Parameter trace.
-
n_fval
¶ Number of function evaluations.
-
n_grad
¶ Number of gradient evaluations.
-
n_hess
¶ Number of Hessian evaluations.
-
n_res
¶ Number of residual evaluations.
-
n_sres
¶ Number or residual sensitivity evaluations.
-
start_time
¶ Start time.
-
update
(x: numpy.ndarray, sensi_orders: Tuple[int], mode: str, result: Dict[str, Union[float, numpy.ndarray]]) → None¶ Update history and best found value.
-
-
pypesto.objective.
res_to_chi2
(res: numpy.ndarray)¶ We assume that the residuals res are related to an objective function value fval = chi2 via:
fval = 0.5 * sum(res**2)
which is the ‘Linear’ formulation in scipy.
-
pypesto.objective.
sres_to_schi2
(res: numpy.ndarray, sres: numpy.ndarray)¶ In line with the assumptions in res_to_chi2.