Utilities¶

ddm.functions.
models_close
(m1, m2, tol=0.1)[source]¶ Determines whether two models are similar.
This compares the parameters of models m1 and m2 and checks to make sure that each of the parameters in model m1 is within a distance of tol of m2. Return True if this is the case, otherwise False.

ddm.functions.
evolution_strategy
(fitness, x_0, mu=1, lmbda=3, copyparents=True, mutate_var=0.002, mutate_prob=0.5, evals=100, seed=None)[source]¶ Optimize using the Evolution Strategy (ES) heuristic method.
Evolution Strategy is an optimization method specified in the form (lambda + mu) or (lambda, mu), for some integer value of lambda and mu. The algorithm will generate an intial population of lambda individuals. Each individual will have an equal number of offspring, so that there is a total of mu organisms in the next generation. In the case of the (lambda + mu) algorithm, the parents are also copied into the next generation. Then, the lambda best organisms in this population are selected to reproduce.
The starting population includes x_0 and lmbda1 other individuals generated by mutating x_0. Mutations occur by perturbing x_0 by a Gaussiandistributed variable (socalled “Gaussian convolution”) with variance mutate_var. Each element is changed with a probability mutate_prob. The number of function evaluations will be approximately evals, as this algorithm will iterate evals/lmbda times.
lmbda is the lambda parameter (note the spelling difference) and mu is the mu parameter for the ES. If copyparents is True, use (lmbda + mu), and if it is False, use (lmbda, mu).
seed allows optional seed values to be used during random number generation during evolutiondriven optimization. If set to None, random number generation is subject to unseeded behavior. If convergence is difficult, setting seed=None may result in different solutions between runs.
The purpose of this is if you already have a good model, but you want to test the local space to see if you can make it better.

ddm.functions.
solve_partial_conditions
(model, sample=None, conditions=None, method=None)[source]¶ Solve a model without specifying the value of all conditions
This function solves model according to the ratio of trials in sample. For example, suppose sample has 100 trials with high coherence and 50 with low coherence. This will then return a solution with 2/3*(PDF high coherence) + 1/3*(PDF low coherence). This is especially useful when comparing a model to a sample which may have many different conditions.
Alternatively, if no sample is available, it will solve all conditions passed in conditions in equal ratios.
The advantage to this function over Model.solve() is that the former can only handle a single value for each condition, whereas this function accepts can do it lists for condition values as well.
The conditions variable limits the solution to a subset of sample which satisfy conditions. The elements of the dictionary conditions should be specified either as values or as a list of values.
Optionally, method describes the solver to use. It can be “analytical”, “numerical”, “cn” (CrankNicolson), “implicit” (backward Euler), “explicit” (forward Euler), or None (autodetect method).
This function will automatically parallelize if set_N_cpus() has been called.

ddm.functions.
hit_boundary
(model)[source]¶ Returns True if any Fitted objects are close to their min/max value

ddm.functions.
dependence_hit_boundary
(pv)[source]¶ Returns True if a Fitted instance has hit the boundary.
Fitted instances may have minimum or maximum values attached to them. If it does, and if it has gotten close to this min/max while fitting, return True. Otherwise, or if the value is not a Fitted object, return False.

ddm.functions.
display_model
(model, print_output=True)[source]¶ A readable way to display models.
model should be any Model object. Prints a description of the model, and does not return anything.

ddm.functions.
get_model_loss
(model, sample, lossfunction=<class 'pyddm.models.loss.LossLikelihood'>, method=None)[source]¶ A shortcut to compusing the loss of a model.
A shortcut method to compute the loss (under loss function lossfunction) of Model model with respect to Sample sample. Optionaly, specificy the numerical method method to use (e.g. analytical, numerical, implicit, etc.)
Note that this should not be used when performing model fits, as it is faster to use the optimizations implemented in fit_adjust_model.