HARK.parallel¶
Early version of multithreading in HARK. To use most of this module, you should first install dill and joblib. Packages can be installed by typing “conda install dill” (etc) at a command prompt.

HARK.parallel.
loadNelderMeadData
(name)¶ Reads the progress of a parallel NelderMead search from a text file, as created by saveNelderMeadData().
Parameters: name (string) – Name of the txt file from which to read search progress. Returns:  simplex (np.array) – The current state of the simplex of parameter guesses.
 fvals (np.array) – The objective function value at each row of simplex.
 iters (int) – The number of completed NelderMead iterations.
 evals (int) – The cumulative number of function evaluations in the search process.

HARK.parallel.
multiThreadCommands
(agent_list, command_list, num_jobs=None)¶ Executes the list of commands in command_list for each AgentType in agent_list using a multithreaded system. Each command should be a method of that AgentType subclass.
Parameters: Returns: Return type:

HARK.parallel.
multiThreadCommandsFake
(agent_list, command_list, num_jobs=None)¶ Executes the list of commands in command_list for each AgentType in agent_list in an ordinary, singlethreaded loop. Each command should be a method of that AgentType subclass. This function exists so as to easily disable multithreading, as it uses the same syntax as multithreadCommands.
Parameters: Returns: Return type: none

HARK.parallel.
parallelNelderMead
(objFunc, guess, perturb=None, P=1, ftol=1e06, xtol=1e08, 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 NelderMead minimization algorithm, as described in Lee and Wiswall. For long optimization procedures, it can save progress between iterations and resume later.
Parameters:  objFunc (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 objFunc.
 perturb (np.array) – Perturbation vector for the simplex, of the same length as an input to objFunc. If perturb[j] is nonzero, a simplex point will be created that perturbs the jth element of guess by perturb[j]; if it is zero, then the jth parameter of objFunc 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 NelderMead iterations; reaching iters=maxiter is reported as an “unsuccessful” minimization.
 maxeval (int) – Maximum number of evaluations of objFunc (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 NelderMead 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 objFunc, as found by the minimization.
 fmin (float) – The minimum of objFunc; fmin = objFunc(min_point).

HARK.parallel.
parallelNelderMeadWorker
(objFunc, simplex, f_vals, j, P, opt_params)¶ A worker process for the parallel NelderMead algorithm. Updates one point in the simplex, returning its function value as well. Should basically never be called directly, only by parallelNelderMead().
Parameters:  objFunc (function) – The function to be minimized; takes a single 1D array as input.
 simplex (numpy.array) – The current simplex for minimization; simplex[k,:] is an input for objFunc.
 f_vals (numpy.array) – The values of the objective function at each point of the simplex: f_vals[k] = objFunc(simplex[k,:])
 j (int) – Index of the point in the simplex to update: simplex[j,:]
 P (int) – Degree of parallelization of the algorithm.
 opt_params (numpy.array) – Three element array with parameters for reflection, contraction, expansion.
Returns:  new_point (numpy.array) – An updated point for the simplex; might be the same as simplex[j,:].
 new_val (float) – The value of the objective function at the new point: objFunc(new_point).
 evals (int) – Number of evaluations of objFunc by this worker.

HARK.parallel.
runCommands
(agent, command_list)¶ Executes each command in command_list on a given AgentType. The commands should be methods of that AgentType’s subclass.
Parameters: Returns: agent – The same AgentType instance passed as input, after running the commands.
Return type:

HARK.parallel.
saveNelderMeadData
(name, simplex, fvals, iters, evals)¶ Stores the progress of a parallel NelderMead search in a text file so that it can be resumed later (after manual termination or a crash).
Parameters:  name (string) – Name of the txt file in which to store search progress.
 simplex (np.array) – The current state of the simplex of parameter guesses.
 fvals (np.array) – The objective function value at each row of simplex.
 iters (int) – The number of completed NelderMead iterations.
 evals (int) – The cumulative number of function evaluations in the search process.
Returns: Return type: