Estimation#

Functions for estimating structural models, including optimization methods and bootstrapping tools.

HARK.estimation.minimize_nelder_mead(objective_func, parameter_guess, verbose=False, which_vars=None, **kwargs)#

Minimizes the objective function using the Nelder-Mead simplex algorithm, starting from an initial parameter guess.

Parameters:
  • objective_func (function) – The function to be minimized. It should take only a single argument, which should be a list representing the parameters to be estimated.

  • parameter_guess ([float]) – A starting point for the Nelder-Mead algorithm, which must be a valid input for objective_func.

  • which_vars (np.array or None) – Array of booleans indicating which parameters should be estimated. When not provided, estimation is performed on all parameters.

  • verbose (boolean) – A flag for the amount of output to print.

Returns:

xopt – The values that minimize objective_func.

Return type:

[float]

HARK.estimation.minimize_powell(objective_func, parameter_guess, verbose=False)#

Minimizes the objective function using a derivative-free Powell algorithm, starting from an initial parameter guess.

Parameters:
  • objective_func (function) – The function to be minimized. It should take only a single argument, which should be a list representing the parameters to be estimated.

  • parameter_guess ([float]) – A starting point for the Powell algorithm, which must be a valid input for objective_func.

  • verbose (boolean) – A flag for the amount of output to print.

Returns:

xopt – The values that minimize objective_func.

Return type:

[float]

HARK.estimation.bootstrap_sample_from_data(data, weights=None, seed=0)#

Samples rows from the input array of data, generating a new data array with an equal number of rows (records). Rows are drawn with equal probability by default, but probabilities can be specified with weights (must sum to 1).

Parameters:
  • data (np.array) – An array of data, with each row representing a record.

  • weights (np.array) – A weighting array with length equal to data.shape[0].

  • seed (int) – A seed for the random number generator.

Returns:

new_data – A resampled version of input data.

Return type:

np.array

HARK.estimation.parallelNelderMead(obj_func, guess, perturb=None, P=1, ftol=1e-06, xtol=1e-08, maxiter=inf, maxeval=inf, r_param=1.0, e_param=1.0, c_param=0.5, s_param=0.5, maxthreads=None, name=None, resume=False, savefreq=None, verbose=1)#

A parallel implementation of the Nelder-Mead minimization algorithm, as described in Lee and Wiswall. For long optimization procedures, it can save progress between iterations and resume later.

Parameters:
  • obj_func (function) – The objective function to be minimized. Takes a single 1D array as input.

  • guess (np.array) – Initial starting point for the simplex, representing an input for obj_func.

  • perturb (np.array) – Perturbation vector for the simplex, of the same length as an input to obj_func. If perturb[j] is non-zero, a simplex point will be created that perturbs the j-th element of guess by perturb[j]; if it is zero, then the j-th parameter of obj_func will not be optimized over. By default, perturb=None, indicating that all parameters should be optimized, with an initial perturbation of 0.1*guess.

  • P (int) – Degree of parallelization: the number of vertices of the simplex to try to update on each iteration of the process.

  • ftol (float) – Absolute tolerance of the objective function for convergence. If suc- cessive iterations return minimum function values that differ by less than ftol, the process terminates successfully.

  • xtol (float) – Absolute tolerance of the input values for convergence. If the maximum distance between the current minimum point and the worst point in the simplex is less than xtol, then the process terminates successfully.

  • maxiter (int) – Maximum number of Nelder-Mead iterations; reaching iters=maxiter is reported as an “unsuccessful” minimization.

  • maxeval (int) – Maximum number of evaluations of obj_func (across all processes); reaching evals=maxeval is reported as an “unsuccessful” minimization.

  • r_param (float) – Parameter indicating magnitude of the reflection point calculation.

  • e_param (float) – Parameter indicating magnitude of the expansion point calculation.

  • c_param (float) – Parameter indicating magnitude of the contraction point calculation.

  • s_param (float) – Parameter indicating magnitude of the shrink calculation.

  • maxthreads (int) – The maximum number of CPU cores that the optimization should use, regardless of the size of the problem.

  • name (string) – A filename for (optionally) saving the progress of the Nelder-Mead search, and for resuming a previous search (when resume=True). Useful for long searches that could potentially be interrupted by computer down time.

  • resume (boolean) – An indicator for whether the search should resume from earlier progress. When True, the process will load a progress file named in input name.

  • savefreq (int) – When not None, search progress will be saved to name.txt every savefreq iterations, to be loaded later with resume=True).

  • verbose (int) – Indicator for the verbosity of the optimization routine. Higher values generate more text output; verbose=0 produces no text output.

Returns:

  • min_point (np.array) – The input that minimizes obj_func, as found by the minimization.

  • fmin (float) – The minimum of obj_func; fmin = obj_func(min_point).