Skip to content

Additional parameters for "scipy.optimize.minimize" in ParametricRegressionFitter is not functioning correctly #1651

Description

@Yoonsung1203

Hello, I am currently using Python 3.7.12 with the lifelines module version 0.27.8.

While implementing a custom RegressionFitter using the SLSQP method, I encountered an issue where the bounds parameter in scipy.optimize.minimize does not function properly.

This issue arises because the relevant parameters in lifelines, namely _scipy_fit_options and fit_options, are both passed to the options parameter of the _minimize_slsqp function within scipy.optimize.minimize. Since _minimize_slsqp already accepts bounds as a keyword argument, this results in the error message:
_minimize_slsqp() got multiple values for argument 'bounds'.

To resolve this, the _fit_model function in lifelines should be modified so that the bounds parameter is added explicitly as a keyword argument rather than being included within options.

My modified code to fix this issue is as follows:

options = {**{"disp": show_progress}, **self._scipy_fit_options, **fit_options}
bounds = None if options.get("bounds") == None else options.pop("bounds")
results = minimize(
	# using value_and_grad is much faster (takes advantage of shared computations) than splitting.
	value_and_grad(self._neg_likelihood_with_penalty_function),
	_initial_point,
	method=self._scipy_fit_method,
	jac=True,
	args=(Ts, E, weights, entries, utils.DataframeSlicer(Xs)),
	bounds = bounds,
	options=options,
	callback=self._scipy_fit_callback,
)

Most users may not use this parameter frequently, but an update may be necessary in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions