Default classes — Profile Likelihood documentation

# Default classes

## single_starting_point

class profile_likelihood.default.single_starting_point.single_starting_point(start0)

  Default class to get and process initial guesses used in the optimization.

  Parameters
    start0

      (Optional) Initial guess used when the optimization is done around the best-fit parameter.

  Attributes
    nguess

      (Required) Number of different initial guess.

    start0

      (Optional) Initial guess used when the optimization is done around the best-fit parameter.

    nparams

      (Optional) Number of parameters.

    start

      (Optional) Values of the starting points.

  Methods

  `get_points`(ii) | (Required) Return 2D array of starting points for optimizations corresponding to each fixed parameter value.
  `set_points_0`() | (Required) Reset the starting points to `self.start0`.
  `update`(results_opt, ii) | (Required) Update the initial guesses.

  get_points(ii)

    (Required) Return 2D array of starting points for optimizations corresponding to each fixed parameter value.

    Parameters
      ii: int

        Location of index of parameters held fixed in the list of index given.

    Returns
      `ndarray`

        Array of initial starting points used in the optimization when parameter idx is held fixed.

  set_points_0()

    (Required) Reset the starting points to `self.start0`. The profile likelihood computation will start from `best_fit` then moves to the left, and then it will go back to the `best_fit` and move to the right this time. This method is called when the computation move back to the `best_fit`.

  update(results_opt, ii)

    (Required) Update the initial guesses. This method will be called every time after an optimization for 1 fixed parameter value.

    Parameters
      results_opt:

        Output from `fit_class.optimize`.

      ii: int

        Location of index of parameters held fixed in the list of index given.

## fit_leastsq

class profile_likelihood.default.fit_leastsq.fit_leastsq(nreturned, **kwargs)

  The default fit class used to calculate the profile likelihood. The fitting/optimization uses `scipy.optimize.least_squares`.

  Parameters
    nreturned: int

      (Required) Number of things returned by the by the fitting class. This is translated as the number of columns of the array to store the results temporarily. This will be used to create the matrix to store the results temporarily. For this fit class, nreturned should be num_params + 2, since the error code and the cost are also stored in addition to the optimized parameters.

    **kwargs

      (Optional) Keyword arguments to pass on to optimization routine.

  Methods

  `callback`(opt_output, fixed_param, idx) | (Required) Process the results from `fit_class.optimize`.
  `optimize`(residuals, initial_guess, idx, …) | Do the optimization using scipy.optimize.least_squares.

  callback(opt_output, fixed_param, idx)

    (Required) Process the results from `fit_class.optimize`. It takes `(opt_output, fixed_param, idx)` as arguments. This method processes raw results from `fit_class.optimize` (`opt_output` parameter) to match the format used by `profile_likelihood` class. This method returns a 1D array, with element 0 be `error_code`, elements 1 to n be `opt_params`, and element n+1 be `cost`. The array can have more element to return, if user wishes to return more information. For reference, also see `_result_dict()` for the construction of the final results dictionary from the array returned by this method.

    Parameters
      opt_output:

        Output from `fit_class.optimize`.

      fixed_param: float

        Value of parameter that is held fixed.

      idx: int

        Index of fixed parameter. Together with `fixed_param`, this is used to insert the fixed parameter into the parameter result from the optimization.

    Returns
      1D `array`

        Array in the format `[error_code, *opt_params, *others, cost]`.

  optimize(residuals, initial_guess, idx, fixed_param)

    Do the optimization using scipy.optimize.least_squares. It takes arguments `residuals, initial_guess, idx, fixed_param`. This method contains the optimization routine to use.

    Parameters
      residuals: callable

        Function to be optimized. This will be a wrapper to `model.residuals` (see `_model_wrapper()`).

      initial_guess: 1D array

        Initial guess for the optimization. This will be a vector of length n-1, where n is the number of model’s parameters

      idx: int

        Index of parameter that is fixed. This is needed to insert `fixed_param` in to it’s proper location.

      fixed_param: float

        Value of parameter that is held fixed.

    Returns
      `Result` `of` `optimization` `in` `any` format. `Further` `processing`

        will be done by `return_class`.