hddm package
Subpackages
- hddm.models package
- Submodules
- hddm.models.base module
- hddm.models.hddm_info module
- hddm.models.hddm_nn module
- hddm.models.hddm_nn_regression module
- hddm.models.hddm_nn_rl module
- hddm.models.hddm_nn_rl_regression module
- hddm.models.hddm_nn_stimcoding module
- hddm.models.hddm_regression module
- hddm.models.hddm_rl module
- hddm.models.hddm_rl_regression module
- hddm.models.hddm_stimcoding module
- hddm.models.hddm_transformed module
- hddm.models.hddm_truncated module
- hddm.models.rl module
- Module contents
- hddm.simulators package
- hddm.torch package
Submodules
hddm.generate module
- hddm.generate.add_outliers(data, n_fast, n_slow, seed=None)
Add outliers to data, outliers are distrbuted randomly across conditions.
- Arguments:
- data: pd.DataFrame
Reaction time and choice data
- n_fast: float
Probability of fast outliers
- n_slow: float
Probability of slow outliers
- seed: int <default=None>
Seed for random number generation
- hddm.generate.gen_rand_data(params=None, n_fast_outliers=0, n_slow_outliers=0, **kwargs)
Generate simulated RTs with random parameters.
- Optional:
- paramsdict <default=generate randomly>
Either dictionary mapping param names to values.
Or dictionary mapping condition name to parameter dictionary (see example below).
If not supplied, takes random values.
- n_fast_outliersint <default=0>
How many fast outliers to add (outlier_RT < ter)
- n_slow_outliersint <default=0>
How many late outliers to add.
The rest of the arguments are forwarded to kabuki.generate.gen_rand_data
- Returns:
data array with RTs parameter values
- Example:
# Generate random data set
>>> data, params = hddm.generate.gen_rand_data({'v':0, 'a':2, 't':.3}, size=100, subjs=5)
# Generate 2 conditions
>>> data, params = hddm.generate.gen_rand_data({'cond1': {'v':0, 'a':2, 't':.3}, 'cond2': {'v':1, 'a':2, 't':.3}})
- Notes:
Wrapper function for kabuki.generate.gen_rand_data. See the help doc of that function for more options.
- hddm.generate.gen_rand_params(include=(), cond_dict=None, seed=None)
Returns a dict of DDM parameters with random values.
- Optional:
- includetuple
Which optional parameters include. Can be any combination of:
‘z’ (bias, default=0.5)
‘sv’ (inter-trial drift variability)
‘sz’ (inter-trial bias variability)
‘st’ (inter-trial non-decision time variability)
Special arguments are: * ‘all’: include all of the above * ‘all_inter’: include all of the above except ‘z’
- cond_dictdictionary
cond_dict is used when multiple conditions are desired. the dictionary has the form of {param1: [value_1, … , value_n], param2: [value_1, … , value_n]} and the function will output n sets of parameters. each set with values from the appropriate place in the dictionary for instance if cond_dict={‘v’: [0, 0.5, 1]} then 3 parameters set will be created. the first with v=0 the second with v=0.5 and the third with v=1.
- seed: float
random seed
- Output:
- if conditions is None:
- params: dictionary
A dictionary holding the parameters values
- else:
- cond_params:
A dictionary holding the parameters for each one of the conditions, that has the form {‘c1’: params1, ‘c2’: params2, …} it can be used directly as an argument in gen_rand_data.
- merged_params:
A dictionary of parameters that can be used to validate the optimization and learning algorithms.
- hddm.generate.gen_rand_rl_data(scaler, alpha, size=1, p_upper=1, p_lower=0, z=0.5, q_init=0.5, pos_alpha=nan, subjs=1, split_by=0, mu_upper=1, mu_lower=0, sd_upper=0.1, sd_lower=0.1, binary_outcome=True)
- hddm.generate.gen_rand_rlddm_data(a, t, scaler, alpha, size=1, p_upper=1, p_lower=0, z=0.5, q_init=0.5, pos_alpha=nan, subjs=1, split_by=0, mu_upper=1, mu_lower=0, sd_upper=0.1, sd_lower=0.1, binary_outcome=True, uncertainty=False)
- hddm.generate.gen_rand_rlddm_onestep_data(a, t, scaler, alpha, data, z=0.5, pos_alpha=nan)
- hddm.generate.gen_rand_rlssm_data_MAB_RWupdate(model, ssm_param, rl_param, dual=False, size=1, p_upper=1, p_lower=0, q_init=0.5, subjs=1, split_by=0, mu_upper=1, mu_lower=0, sd_upper=0.1, sd_lower=0.1, binary_outcome=True, uncertainty=False)
Generate RLSSM datasets on 2-armed bandit task.
- Arguments:
- model: str
String that determines which sequential sampling model to use.
- ssm_param: list
List of sequential sampling model parameters (in the order of what you define in model_config).
- rl_param: list
List of reinforcement learning parameters (in the order of what you define in model_config_rl).
- dual: bool <default=False>
Flag to denote if use of separate learning rates for positive and negative RPEs.
- size: int <default=1>
Number of trials to simulate.
- p_upper: float <default=1>
Probability of reward for the upper action/choice.
- p_lower: float <default=0>
Probability of reward for the lower action/choice.
- q_init: int <default=0.5>
Initial q-values.
- subjs: int <default=1>
Number of subjects to simulate.
- split_by: int <default=0>
Denotes the condition number/index in the experiment.
- mu_upper: float <default=1>
Mean of the (normal) reward distribution for the upper action/choice.
- mu_lower: float <default=0>
Mean of the (normal) reward distribution for the lower action/choice.
- sd_upper: float <default=0.1>
Std. dev. of the (normal) reward distribution for the upper action/choice.
- sd_lower: float <default=0.1>
Std. dev. of the (normal) reward distribution for the lower action/choice.
- binary_outcome: bool <default=True>
Denotes if the reward scheme is binary (as opposed to non-binary). Non-binary rewards are sampled from normal distributions.
- Returns:
- all_data: Pandas.Dataframe
Pandas DataFrame containing all the simulated data.
- hddm.generate.gen_rand_rlssm_reg_data_MAB_RWupdate(model, ssm_param, rl_param, neural, dual=False, size=1, p_upper=1, p_lower=0, q_init=0.5, subjs=1, split_by=0, mu_upper=1, mu_lower=0, sd_upper=0.1, sd_lower=0.1, binary_outcome=True, uncertainty=False)
Generate RLSSM regression datasets on 2-armed bandit task.
- Arguments:
- model: str
String that determines which sequential sampling model to use.
- ssm_param: list
List of sequential sampling model parameters (in the order of what you define in model_config).
- rl_param: list
List of reinforcement learning parameters (in the order of what you define in model_config_rl).
- neural: float
(Linear) coefficient for regression function on ‘a’.
- dual: bool <default=False>
Flag to denote if use of separate learning rates for positive and negative RPEs.
- size: int <default=1>
Number of trials to simulate.
- p_upper: float <default=1>
Probability of reward for the upper action/choice.
- p_lower: float <default=0>
Probability of reward for the lower action/choice.
- q_init: int <default=0.5>
Initial q-values.
- subjs: int <default=1>
Number of subjects to simulate.
- split_by: int <default=0>
Denotes the condition number/index in the experiment.
- mu_upper: float <default=1>
Mean of the (normal) reward distribution for the upper action/choice.
- mu_lower: float <default=0>
Mean of the (normal) reward distribution for the lower action/choice.
- sd_upper: float <default=0.1>
Std. dev. of the (normal) reward distribution for the upper action/choice.
- sd_lower: float <default=0.1>
Std. dev. of the (normal) reward distribution for the lower action/choice.
- binary_outcome: bool <default=True>
Denotes if the reward scheme is binary (as opposed to non-binary). Non-binary rewards are sampled from normal distributions.
- Returns:
- all_data: Pandas.Dataframe
Pandas DataFrame containing all the simulated data.
- hddm.generate.gen_rts(size=1000, range_=(-6, 6), dt=0.001, intra_sv=1.0, structured=True, subj_idx=None, method='cdf', **params)
A private function used by gen_rand_data Returns a DataFrame of randomly simulated RTs from the DDM.
- Arguments:
- paramsdict
Parameter names and values to use for simulation.
- Optional:
- sizeint
Number of RTs to simulate.
- range_tuple
Minimum (negative) and maximum (positve) RTs.
- dtfloat
Number of steps/sec.
- intra_svfloat
Intra-trial variability.
- structuredbool
Return a structured array with fields ‘RT’ and ‘response’.
- subj_idxint
If set, append column ‘subj_idx’ with value subj_idx.
- methodstr
- Which method to use to simulate the RTs:
‘cdf’: fast, uses the inverse of cumulative density function to sample, dt can be 1e-2.
‘drift’: slow, simulates each complete drift process, dt should be 1e-4.
- hddm.generate.gen_single_params_set(include=())
Returns a dict of DDM parameters with random values for a singel conditin the function is used by gen_rand_params.
- Optional:
- includetuple
Which optional parameters include. Can be any combination of:
‘z’ (bias, default=0.5)
‘sv’ (inter-trial drift variability)
‘sz’ (inter-trial bias variability)
‘st’ (inter-trial non-decision time variability)
Special arguments are: * ‘all’: include all of the above * ‘all_inter’: include all of the above except ‘z’
- hddm.generate.pdf_with_params(rt, params)
Helper function that calls full_pdf and gets the parameters from the dict params.
- hddm.generate.rand(d0, d1, ..., dn)
Random values in a given shape.
Note
This is a convenience function for users porting code from Matlab, and wraps random_sample. That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like numpy.zeros and numpy.ones.
Create an array of the given shape and populate it with random samples from a uniform distribution over
[0, 1)
.- Parameters:
d0 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
d1 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
... (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
dn (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
- Returns:
out – Random values.
- Return type:
ndarray, shape
(d0, d1, ..., dn)
See also
random
Examples
>>> np.random.rand(3,2) array([[ 0.14022471, 0.96360618], #random [ 0.37601032, 0.25528411], #random [ 0.49313049, 0.94909878]]) #random
hddm.likelihoods module
- hddm.likelihoods.add_quantiles_functions_to_pymc_class(pymc_class)
add quantiles methods to a pymc class.
- Input:
pymc_class: class
- hddm.likelihoods.general_WienerCont(err=0.0001, n_st=2, n_sz=2, use_adaptive=1, simps_err=0.001)
- hddm.likelihoods.generate_wfpt_stochastic_class(wiener_params=None, sampling_method='cssm', cdf_range=(-5, 5), sampling_dt=0.0001)
create a wfpt stochastic class by creating a pymc nodes and then adding quantile functions.
- Arguments:
- wiener_params: dict <default=None>
dictonary of wiener_params for wfpt likelihoods
- sampling_method: str <default=’cssm’>
an argument used by hddm.generate.gen_rts
- cdf_range: sequence <default=(-5,5)>
an argument used by hddm.generate.gen_rts
- sampling_dt: float <default=1e-4>
an argument used by hddm.generate.gen_rts
- Output:
- wfpt: class
the wfpt stochastic
- hddm.likelihoods.wiener_like_contaminant(value, cont_x, v, sv, a, z, sz, t, st, t_min, t_max, err, n_st, n_sz, use_adaptive, simps_err)
Log-likelihood for the simple DDM including contaminants
hddm.likelihoods_mlp module
- hddm.likelihoods_mlp.make_mlp_likelihood(model=None, model_config=None, wiener_params=None, **kwargs)
Defines the likelihoods for the MLP networks.
- Arguments:
- model: str <default=’ddm’>
String that determines which model you would like to fit your data to. Currently available models are: ‘ddm’, ‘full_ddm’, ‘angle’, ‘weibull’, ‘ornstein’, ‘levy’
- model_config: dict <default=None>
Model config supplied via the calling HDDM class. Necessary for construction of likelihood. Should have the structure of model_configs in the hddm.model_config.model_config dictionary.
- kwargs: dict
Dictionary of additional keyword arguments. Importantly here, this carries the preloaded CNN.
- Returns:
Returns a pymc.object stochastic object as defined by PyMC2
- hddm.likelihoods_mlp.make_mlp_likelihood_reg(model=None, model_config=None, wiener_params=None, **kwargs)
Defines the regressor likelihoods for the MLP networks.
- Arguments:
- model: str <default=’ddm’>
String that determines which model you would like to fit your data to. Currently available models are: ‘ddm’, ‘full_ddm’, ‘angle’, ‘weibull’, ‘ornstein’, ‘levy’
- model_config: dict <default=None>
Model config supplied via the calling HDDM class. Necessary for construction of likelihood. Should have the structure of model_configs in the hddm.model_config.model_config dictionary.
- kwargs: dict
Dictionary of additional keyword arguments. Importantly here, this carries the preloaded CNN.
- Returns:
Returns a pymc.object stochastic object as defined by PyMC2
- hddm.likelihoods_mlp.make_mlp_likelihood_reg_nn_rl(model=None, model_config=None, model_config_rl=None, wiener_params=None, **kwargs)
Defines the regressor likelihoods for the LAN-based RLSSM class.
- Arguments:
- model: str <default=’ddm’>
String that determines which model you would like to fit your data to. Currently available models are: ‘ddm’, ‘full_ddm’, ‘angle’, ‘weibull’, ‘ornstein’, ‘levy’
- model_config: dict <default=None>
Config dictionary for the sequential sampling model, necessary for construction of likelihood. In the style of what you find under hddm.model_config.
- model_config_rl: dict <default=None>
Config dictionary for the reinforcement learning model, necessary for construction of likelihood. In the style of what you find under hddm.model_config_rl.
- kwargs: dict
Dictionary of additional keyword arguments. Importantly here, this carries the preloaded CNN.
- Returns:
Returns a pymc.object stochastic object as defined by PyMC2
- hddm.likelihoods_mlp.make_mlp_likelihood_rlssm(model=None, model_config=None, model_config_rl=None, wiener_params=None, **kwargs)
Defines the likelihoods for the MLP networks for RLSSMs.
- Arguments:
- model: str <default=’ddm’>
String that determines which model you would like to fit your data to. Currently available models are: ‘ddm’, ‘full_ddm’, ‘angle’, ‘weibull’, ‘ornstein’, ‘levy’
- model_config: dict <default=None>
Config dictionary for the sequential sampling model, necessary for construction of likelihood. In the style of what you find under hddm.model_config.
- model_config_rl: dict <default=None>
Config dictionary for the reinforcement learning model, necessary for construction of likelihood. In the style of what you find under hddm.model_config_rl.
- kwargs: dict
Dictionary of additional keyword arguments. Importantly here, this carries the preloaded CNN.
- Returns:
Returns a pymc.object stochastic object as defined by PyMC2
hddm.model_config module
hddm.model_config_rl module
hddm.network_inspectors module
- hddm.network_inspectors.get_torch_mlp(model='angle', nbin=512)
Returns the torch network which is the basis of the TORCH_MLP likelihoods
- Arguments:
model: str <default=’angle’> Specifies the models you would like to load
- Returns:
Returns a function that gives you access to a forward pass through the MLP. This in turn expects as input a 2d np.array of datatype np.float32. Each row is filled with model parameters trailed by a reaction time and a choice. (e.g. input dims for a ddm MLP could be (3, 6), 3 datapoints and 4 parameters + reaction time and choice). Predict on batch then returns for each row of the input the log likelihood of the respective parameter vector and datapoint.
- Example:
>>> forward = hddm.network_inspectors.get_mlp(model = 'ddm') >>> data = np.array([[0.5, 1.5, 0.5, 0.5, 1.0, -1.0], [0.5, 1.5, 0.5, 0.5, 1.0, -1.0]], dtype = np.float32) >>> forward(data)
- hddm.network_inspectors.kde_vs_lan_likelihoods(parameter_df=None, model=None, n_samples=10, n_reps=10, alpha=0.1, cols=3, save=False, show=True, font_scale=1.5, figsize=(10, 10))
Function creates a plot that compares kernel density estimates from simulation data with mlp output.
- Arguments:
- parameter_df: pandas.core.frame.DataFrame
DataFrame hold a parameter vector in each row. (Parameter vector has to be compatible with the model string supplied to the ‘model’ argument)
- model: str <default=None>
String that specifies the model which should be used for the graph (find allowed models listed under hddm.model_config.model_config).
- n_samples: int <default=10>
How many model samples to base kernel density estimates on.
- n_reps: int <default=10>
How many kernel density estimates to include in a given subplot.
- cols: int <default=3>
How many columns to use when creating subplots.
- save: bool <default=False>
Whether to save the plot.
- show: bool <default=True>
Wheter to show the plot.
- font_scale: float <default=1.5>
Seaborn setting, exposed here to be adjusted by user, since it is not always obvious which value is best.
- Returns:
empty
- hddm.network_inspectors.lan_manifold(parameter_df=None, vary_dict={'v': [-1.0, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1.0]}, model='ddm', n_rt_steps=200, max_rt=5, fig_scale=1.0, save=False, show=True)
Plots lan likelihoods in a 3d-plot.
- Arguments:
- parameter_df: pandas.core.frame.DataFrame <default=None>
DataFrame that holds a parameter vector and has parameter names as keys.
- vary_dict: dict <default={‘v’: [-1.0, -0.75, -.5, -0.25, 0, 0.25, 0.5, 0.75, 1.0]}>
Dictionary where key is a valid parameter name, and value is either a list of numpy.ndarray() of values of the respective parameter that you want to plot.
- model: str <default=’ddm’>
String that specifies the model to be used to plotting. (The plot loads the corresponding LAN)
- n_rt_steps: int <default=200>
Numer of rt steps to include (x-axis)
- max_rt: numeric <default=5.0>
The n_rt_steps argument splits the reaction time axis in to n_rt_step from 0 to max_rt.
- fig_scale: numeric <default=1.0>
Basic handle to scale the figure.
- save: bool <default=False>
Whether to save the plot.
- show: bool <default=True>
Whether to show the plot.
- Returns:
empty
- class hddm.network_inspectors.logkde(simulator_data, bandwidth_type='silverman', auto_bandwidth=True)
Bases:
object
Class that takes in simulator data and constructs a kernel density estimator from it.
- Arguments:
- simulator_data: tuple
Output of a call to hddm.simulators.simulator
- bandwidth_type: str <default=’silverman’>
At this point only ‘silverman’ is allowed.
- auto_bandwidth: bool <default=True>
At this point only true is allowed. Kernel Bandwidth is going to be determined automatically.
- attach_data_from_simulator(simulator_data=([0, 2, 4], [-1, 1, -1]))
- compute_bandwidths(type='silverman')
- generate_base_kdes(auto_bandwidth=True, bandwidth_type='silverman')
- kde_eval(data=([], []), log_eval=True)
- kde_sample(n_samples=2000, use_empirical_choice_p=True, alternate_choice_p=0)
hddm.plotting module
- hddm.plotting.gen_ppc_rlssm(model_ssm, config_ssm, model_rl, config_rl, data, traces, nsamples, p_lower, p_upper, save_data=False, save_name=None, save_path=None)
Generates data (for posterior predictives) using samples from the given trace as parameters.
- Parameters:
model_ssm – str Name of the sequential sampling model used.
config_ssm – dict Config dictionary for the specified sequential sampling model.
model_rl – str Name of the reinforcement learning model used.
config_rl – dict Config dictionary for the specified reinforcement learning model.
data – pandas.DataFrame Pandas DataFrame for the observed data.
traces – pandas.DataFrame Pandas DataFrame containing the traces.
nsamples – int Number of posterior samples to draw for each subject.
p_lower – dict Dictionary of conditions containing the probability of reward for the lower choice/action in the 2-armed bandit task.
p_upper – dict Dictionary of conditions containing the probability of reward for the upper choice/action in the 2-armed bandit task.
save_data – bool <default=False> Boolean denoting whether to save the data as csv.
save_name – str <default=None> Specifies filename to save the data.
save_path – str <default=None> Specifies path to save the data.
- Returns:
- pandas.DataFrame
Pandas DataFrame containing the simulated data (for posterior predictives).
- Return type:
ppc_sdata
- hddm.plotting.get_mean_correct_responses_rlssm(trials, nbins, data)
Gets the mean proportion of correct responses condition-wise.
- Parameters:
trials – int Number of initial trials to consider for computing proportion of correct responses.
nbins – int Number of bins to put the trials into (Num. of trials per bin = trials/nbin).
data – pandas.DataFrame Pandas DataFrame for the observed or simulated data.
- Returns:
- dict
Dictionary of conditions containing proportion of mean correct responses (for each bin).
- up_err: dict
Dictionary of conditions containing upper intervals of HDI of mean correct responses (for each bin).
- low_err: dict
Dictionary of conditions containing lower intervals of HDI of mean correct responses (for each bin).
- Return type:
mean_correct_responses
- hddm.plotting.plot_caterpillar(hddm_model=None, ground_truth_parameter_dict=None, drop_sd=True, keep_key=None, figsize=(10, 10), columns=3, save=False, path=None, format='png', y_tick_size=10, x_tick_size=10)
An alternative posterior predictive plot. Works for all models listed in hddm (e.g. ‘ddm’, ‘angle’, ‘weibull’, ‘levy’, ‘ornstein’)
- Parameters:
hddm_model – hddm model object <default=None> If you supply a ground truth model, the data you supplied to the hddm model should include trial by trial parameters.
ground_truth_parameter_dict – dict <default=None> Parameter dictionary (for example coming out of the function simulator_h_c()) that provides ground truth values for the parameters fit in the hddm_model.
drop_sd – bool <default=True> Whether or not to drop group level standard deviations from the caterpillar plot. This is sometimes useful because scales can be off if included.
figsize – tuple <default=(10, 15)> Size of initial figure.
keep_key – list <default=None> If you want to keep only a specific list of parameters in the caterpillar plot, supply those here as a list. All other parameters for which you supply traces in the posterior samples are going to be ignored.
save – bool <default=False> Whether to save the plot
format – str <default=’png’> File format in which to save the figure.
path – str <default=None> Path in which to save the figure.
Return: plot object
- hddm.plotting.plot_from_data(df, generative_model='ddm_hddm_base', plot_func=None, columns=None, save=False, save_name=None, make_transparent=False, show=True, path=None, groupby='subj_idx', figsize=(8, 6), format='png', keep_frame=True, keep_title=True, **kwargs)
Plot data from a hddm ready DataFrame.
- Parameters:
df – pd.DataFrame HDDM ready dataframe.
value_range – numpy.ndarray Array to evaluate the likelihood over.
- Optional:
- columnsint <default=3>
How many columns to use for plotting the subjects.
- binsint <default=100>
How many bins to compute the data histogram over.
figsize : (int, int) <default=(8, 6)>
- savebool <default=False>
Whether to save the figure to a file.
- pathstr <default=None>
Save figure into directory prefix
- formatstr or list of strings
Save figure to a image file of type ‘format’. If more then one format is given, multiple files are created
- plot_funcfunction <default=_plot_func_posterior_pdf_node_nn>
Plotting function to use for each observed node (see default function for an example).
Note
This function changes the current value and logp of the nodes.
- hddm.plotting.plot_posterior_pair(model, plot_func=None, save=False, path=None, figsize=(8, 6), format='png', samples=100, parameter_recovery_mode=False, **kwargs)
Generate posterior pair plots for each observed node.
- Parameters:
model – kabuki.Hierarchical The (constructed and sampled) kabuki hierarchical model to create the posterior preditive from.
Optional:
- samples: int <default=10>
How many posterior samples to use.
- columns: int <default=3>
How many columns to use for plotting the subjects.
- bins: int <default=100>
How many bins to compute the data histogram over.
figsize: (int, int) <default=(8, 6)>
- save: bool <default=False>
Whether to save the figure to a file.
- path: str <default=None>
Save figure into directory prefix
- format: str or list of strings <default=’png’>
Save figure to a image file of type ‘format’. If more then one format is given, multiple files are created
- parameter_recovery_mode: bool <default=False>
If the data attached to the model supplied under the model argument has the format expected of the simulator_h_c() function from the simulators.hddm_dataset_generators module, then parameter_recovery_mode = True can be use to supply ground truth parameterizations to the plot_func argument describes below.
- plot_func: function <default=_plot_posterior_pdf_node>
Plotting function to use for each observed node (see default function for an example).
Note
This function changes the current value and logp of the nodes.
- hddm.plotting.plot_posterior_pairs_rlssm(tracefile, param_list, save_fig=False, save_name=None, save_path=None, **kwargs)
Plot posterior pairs.
- Parameters:
tracefile – dict Dictionary containing the traces.
param_list – list List of model parameters to be included in the posterior pair plots.
save_fig – bool <default=False> Boolean denoting whether to save the plot.
save_name – str <default=None> Specifies filename to save the figure.
save_path – str <default=None> Specifies path to save the figure.
- Returns:
- matplotlib.Figure
plot object
- Return type:
fig
- hddm.plotting.plot_posterior_predictive(model, plot_func=None, required_method='pdf', columns=None, save=False, path=None, figsize=(8, 6), format='png', num_subjs=None, parameter_recovery_mode=False, subplots_adjust={'hspace': 0.4, 'top': 0.85, 'wspace': 0.3}, **kwargs)
Plot the posterior predictive distribution of a kabuki hierarchical model.
- Parameters:
model – kabuki.Hierarchical The (constructed and sampled) kabuki hierarchical model to create the posterior preditive from.
value_range – numpy.ndarray Array to evaluate the likelihood over.
Optional:
- samplesint <default=10>
How many posterior samples to generate the posterior predictive over.
- columnsint <default=3>
How many columns to use for plotting the subjects.
- binsint <default=100>
How many bins to compute the data histogram over.
figsize : (int, int) <default=(8, 6)>
- savebool <default=False>
Whether to save the figure to a file.
- pathstr <default=None>
Save figure into directory prefix
- formatstr or list of strings
Save figure to a image file of type ‘format’. If more then one format is given, multiple files are created
- subplots_adjustdict <default={‘top’: 0.85, ‘hspace’: 0.4, ‘wspace’: 0.3}>
Spacing rules for subplot organization. See Matplotlib documentation for details.
- parameter_recovery_mode: bool <default=False>
If the data attached to the model supplied under the model argument has the format expected of the simulator_h_c() function from the simulators.hddm_dataset_generators module, then parameter_recovery_mode = True can be use to supply ground truth parameterizations to the plot_func argument describes below.
- plot_funcfunction <default=_plot_func_posterior_pdf_node_nn>
Plotting function to use for each observed node (see default function for an example).
Note
This function changes the current value and logp of the nodes.
- hddm.plotting.plot_ppc_choice_rlssm(obs_data, sim_data, trials, nbins, save_fig=False, save_name=None, save_path=None)
Plot posterior preditive plot for choice data.
- Parameters:
obs_data – pandas.DataFrame Pandas DataFrame for the observed data.
sim_data – pandas.DataFrame Pandas DataFrame for the simulated data.
trials – int Number of initial trials to consider for computing proportion of correct responses.
nbins – int Number of bins to put the trials into (Num. of trials per bin = trials/nbin).
save_fig – bool <default=False> Boolean denoting whether to save the plot.
save_name – str <default=None> Specifies filename to save the figure.
save_path – str <default=None> Specifies path to save the figure.
- Returns:
- matplotlib.Figure
plot object
- Return type:
fig
- hddm.plotting.plot_ppc_rt_rlssm(obs_data, sim_data, trials, bw=0.1, save_fig=False, save_name=None, save_path=None)
Plot posterior preditive plot for reaction time data.
- Parameters:
obs_data – pandas.DataFrame Pandas DataFrame for the observed data.
sim_data – pandas.DataFrame Pandas DataFrame for the simulated data.
trials – int Number of initial trials to consider for computing proportion of correct responses.
bw – float <default=0.1> Bandwidth parameter for kernel-density estimates.
save_fig – bool <default=False> Boolean denoting whether to save the plot.
save_name – str <default=None> Specifies filename to save the figure.
save_path – str <default=None> Specifies path to save the figure.
- Returns:
- matplotlib.Figure
plot object
- Return type:
fig
- hddm.plotting.prettier_tag(tag)
- hddm.plotting.rand(d0, d1, ..., dn)
Random values in a given shape.
Note
This is a convenience function for users porting code from Matlab, and wraps random_sample. That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like numpy.zeros and numpy.ones.
Create an array of the given shape and populate it with random samples from a uniform distribution over
[0, 1)
.- Parameters:
d0 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
d1 (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
... (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
dn (int, optional) – The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
- Returns:
out – Random values.
- Return type:
ndarray, shape
(d0, d1, ..., dn)
See also
random
Examples
>>> np.random.rand(3,2) array([[ 0.14022471, 0.96360618], #random [ 0.37601032, 0.25528411], #random [ 0.49313049, 0.94909878]]) #random
hddm.utils module
- hddm.utils.EZ(pc, vrt, mrt, s=1)
Calculate Wagenmaker’s EZ-diffusion statistics.
- Parameters:
- pcfloat
probability correct.
- vrtfloat
variance of response time for correct decisions (only!).
- mrtfloat
mean response time for correct decisions (only!).
- sfloat
scaling parameter. Default s=1.
- Returns:
- (v, a, ter)tuple
drift-rate, threshold and non-decision time
The error RT distribution is assumed identical to the correct RT distrib.
Edge corrections are required for cases with Pc=0 or Pc=1. (Pc=.5 is OK)
- Assumptions:
The error RT distribution is identical to the correct RT distrib.
z=.5 – starting point is equidistant from the response boundaries
sv=0 – across-trial variability in drift rate is negligible
sz=0 – across-trial variability in starting point is negligible
st=0 – across-trial range in nondecision time is negligible
- Reference:
Wagenmakers, E.-J., van der Maas, H. Li. J., & Grasman, R. (2007).
An EZ-diffusion model for response time and accuracy. Psychonomic Bulletin & Review, 14 (1), 3-22.
- Example:
>>> EZ(.802, .112, .723, s=.1) (0.099938526231301769, 0.13997020267583737, 0.30002997230248141)
- See Also:
EZ_data
- hddm.utils.EZ_data(data, s=1)
Calculate Wagenmaker’s EZ-diffusion statistics on data.
- Arguments:
- datanumpy.array
Data array with reaction time data. Correct RTs are positive, incorrect RTs are negative.
- sfloat
Scaling parameter (default=1)
- Returns:
- (v, a, ter)tuple
drift-rate, threshold and non-decision time
- See Also:
EZ
- hddm.utils.EZ_param_ranges(data, range_=1.0)
- hddm.utils.EZ_subjs(data)
- hddm.utils.bin_rts_pointwise(data, max_rt=10.0, nbins=512)
- hddm.utils.check_params_valid(**params)
- hddm.utils.create_test_model(samples=5000, burn=1000, subjs=1, size=100)
- hddm.utils.data_plot(model, bins=50, nrows=3)
- hddm.utils.data_quantiles(data, quantiles=(0.1, 0.3, 0.5, 0.7, 0.9))
compute the quantiles of 2AFC data
- Output:
q_lower - lower boundary quantiles q_upper - upper_boundary_quantiles p_upper - probability of hitting the upper boundary
- hddm.utils.flip_errors(data)
Flip sign for lower boundary responses.
- Arguments:
- datanumpy.recarray
Input array with at least one column named ‘RT’ and one named ‘response’
- Returns:
- datanumpy.recarray
Input array with RTs sign flipped where ‘response’ == 0
- hddm.utils.flip_errors_nn(data)
Flip sign for lower boundary responses in case they were supplied ready for standard hddm.
- Arguments:
- datanumpy.recarray
Input array with at least one column named ‘RT’ and one named ‘response’
- Returns:
- datanumpy.recarray
Input array with RTs sign flipped where ‘response’ < 0
- hddm.utils.gen_ppc_stats(quantiles=(10, 30, 50, 70, 90))
Generate default statistics for posterior predictive check on RT data.
- Returns:
OrderedDict mapping statistic name -> function
- hddm.utils.get_dataset_as_dataframe_rlssm(dataset)
Get dataset as pandas DataFrame from dict format.
- Parameters:
dataset – dict Dictionary containing the dataset.
- Returns:
- pandas.DataFrame
Pandas DataFrame containing the dataset.
- Return type:
PR_data
- hddm.utils.get_traces_rlssm(tracefile)
Get traces as pandas DataFrame from dict format.
- Parameters:
tracefile – dict Dictionary containing the trace data.
- Returns:
- pandas.DataFrame
Pandas DataFrame containing the trace data.
- Return type:
traces
- hddm.utils.hddm_parents_trace(model, obs_node, idx)
Return the parents’ value of an wfpt node in index ‘idx’ (the function is used by ppd_test)
- hddm.utils.make_likelihood_str_mlp(config=None, wiener_params=None, fun_name='custom_likelihood')
Define string for a likelihood function that can be used as an mlp-likelihood in the HDDMnn and HDDMnnStimCoding classes Useful if you want to supply a custom LAN.
- Arguments:
- configdict <default = None>
Config dictionary for the model for which you would like to construct a custom likelihood. In the style of what you find under hddm.model_config.
- Returns:
- str:
A string that holds the code to define a likelihood function as needed by HDDM to pass to PyMC2. (Serves as a wrapper around the LAN forward pass)
- hddm.utils.make_likelihood_str_mlp_info(config=None, wiener_params=None, fun_name='custom_likelihood')
Define string for a likelihood function that can be used as an mlp-likelihood in the HDDMnn and HDDMnnStimCoding classes Useful if you want to supply a custom LAN.
- Arguments:
- configdict <default = None>
Config dictionary for the model for which you would like to construct a custom likelihood. In the style of what you find under hddm.model_config.
- Returns:
- str:
A string that holds the code to define a likelihood function as needed by HDDM to pass to PyMC2. (Serves as a wrapper around the LAN forward pass)
- hddm.utils.make_likelihood_str_mlp_rlssm(model, config=None, config_rl=None, wiener_params=None, fun_name='custom_likelihood')
Define string for a likelihood function for RLSSMs. This can be used as an mlp-likelihood in the HDDMnnRL class. Also useful if you want to supply a custom LAN.
- Arguments:
- modelstr
Name of the sequential sampling model used.
- configdict <default = None>
Config dictionary for the sequential sampling model for which you would like to construct a custom likelihood. In the style of what you find under hddm.model_config.
- config_rldict <default = None>
Config dictionary for the reinforcement learning model for which you would like to construct a custom likelihood. In the style of what you find under hddm.model_config_rl.
- Returns:
- str:
A string that holds the code to define a likelihood function as needed by HDDM to pass to PyMC2. (Serves as a wrapper around the LAN forward pass)
- hddm.utils.make_reg_likelihood_str_mlp(config=None, wiener_params=None, param_links=None, param_links_betas=None, fun_name='custom_likelihood_reg')
Define string for a likelihood function that can be used as a mlp-likelihood in the HDDMnnRegressor class. Useful if you want to supply a custom LAN.
- Arguments:
- configdict <default = None>
Config dictionary for the model for which you would like to construct a custom likelihood. In the style of what you find under hddm.model_config.
- Returns:
- str:
A string that holds the code to define a likelihood function as needed by HDDM to pass to PyMC2. (Serves as a wrapper around the LAN forward pass)
- hddm.utils.make_reg_likelihood_str_mlp_basic(config=None, wiener_params=None, fun_name='custom_likelihood_reg')
Define string for a likelihood function that can be used as a mlp-likelihood in the HDDMnnRegressor class. Useful if you want to supply a custom LAN.
- Arguments:
- configdict <default = None>
Config dictionary for the model for which you would like to construct a custom likelihood. In the style of what you find under hddm.model_config.
- Returns:
- str:
A string that holds the code to define a likelihood function as needed by HDDM to pass to PyMC2. (Serves as a wrapper around the LAN forward pass)
- hddm.utils.make_reg_likelihood_str_mlp_basic_nn_rl(model=None, config=None, config_rl=None, wiener_params=None, fun_name='custom_likelihood_reg')
Define string for a likelihood function that can be used as a mlp-likelihood in the HDDMnnRLRegressor class. Useful if you want to supply a custom LAN.
- Arguments:
- modelstr
Name of the sequential sampling model used.
- configdict <default = None>
Config dictionary for the sequential sampling model for which you would like to construct a custom likelihood. In the style of what you find under hddm.model_config.
- config_rldict <default = None>
Config dictionary for the reinforcement learning model for which you would like to construct a custom likelihood. In the style of what you find under hddm.model_config.
- Returns:
- str:
A string that holds the code to define a likelihood function as needed by HDDM to pass to PyMC2. (Serves as a wrapper around the LAN forward pass)
- hddm.utils.plot_posterior_quantiles(model, **kwargs)
Plot posterior predictive quantiles.
- Arguments:
model : HDDM model
- Optional:
- value_rangenumpy.ndarray
Range over which to evaluate the CDF.
- samplesint (default=10)
Number of posterior samples to use.
- alphafloat (default=.75)
Alpha (transparency) of posterior quantiles.
- hexbinbool (default=False)
Whether to plot posterior quantile density using hexbin.
- data_plot_kwargsdict (default=None)
Forwarded to data plotting function call.
- predictive_plot_kwargsdict (default=None)
Forwareded to predictive plotting function call.
- columnsint (default=3)
How many columns to use for plotting the subjects.
- savebool (default=False)
Whether to save the figure to a file.
- pathstr (default=None)
Save figure into directory prefix
- hddm.utils.plot_posteriors(model, **kwargs)
Generate posterior plots for each parameter.
This is a wrapper for pymc.Matplot.plot()
- hddm.utils.post_pred_stats(data, sim_datasets, **kwargs)
Calculate a set of summary statistics over posterior predictives.
- Arguments:
data : pandas.DataFrame
sim_data : pandas.DataFrame
- Optional:
- binsint
How many bins to use for computing the histogram.
- evalsdict
User-defined evaluations of the statistics (by default 95 percentile and SEM). :Example: {‘percentile’: scoreatpercentile}
- plotbool
Whether to plot the posterior predictive distributions.
- progress_barbool
Display progress bar while sampling.
- Returns:
Hierarchical pandas.DataFrame with the different statistics.
- hddm.utils.pretty_tag(tag)
- hddm.utils.qp_plot(x, groupby=None, quantiles=(0.1, 0.3, 0.5, 0.7, 0.9), ncols=None, draw_lines=True, ax=None)
qp plot
- Arguments:
x: either a HDDM model or data
- grouby: list
a list of conditions to group the data. if x is a model then groupby is ignored.
- quantiles: sequence
sequence of quantiles
- ncols: int
number of columns in output figure
- draw_lines: bool <default=True>
draw lines to connect the same quantiles across conditions