OCD_modeling

class OCD_modeling.ReducedWongWangND(a=270.0, b=108.0, d=0.154, I_0=0.3, J_N=0.2609, w=0.9, G=1.0, tau_S=100.0, gamma=0.000641, sigma=0.001, N=2, dt=0.01, C=None, S=None, x=None, *args, **kwargs)[source]

Bases: object

Reduced Wong Wang model (N-dimensional)

H(x)[source]

Average synaptic gating.

a: slope (n/C); default=270 b: offset (Hz); default=108 d: decay (s); default=0.154

__init__(a=270.0, b=108.0, d=0.154, I_0=0.3, J_N=0.2609, w=0.9, G=1.0, tau_S=100.0, gamma=0.000641, sigma=0.001, N=2, dt=0.01, C=None, S=None, x=None, *args, **kwargs)[source]
dS()[source]

ODE of firing rate.

tau_S: kinetic parameter of local population (ms); default=100 gamma: kinetic parameter of coupled population (ms); default=0.000641 sigma: noise amplitude (nA); default=0.001 v_i: gaussian noise (n/a); default=0

integrate()[source]

Euler(-Maruyama) integration of the ODE

load_C_param(par, vals)[source]

Special case for connectivity control parameters as it is an array

prepare_auxiliary_variables(rec_vars, n_rec)[source]

creates dtata structures to recorded supplementary variables

prepare_control_params()[source]

Prepare the control parameters to be updated during the simulation

record_auxiliary_variables(rec_vars, rec_idx)[source]

Record variables other than S

run(t_tot=1000, sf=100, t_rec=None, rec_vars=[])[source]

Runs the model.

Parameters:
  • t_tot (int) – Total simulation time (s).

  • sf (int) – Sampling frequency of the reccording (Hz).

  • t_rec (list) – Interval of recording (s) in the form [start, stop].

  • rec_vars (list) – Variables to records (note that S is always recorded).

set_control_params(params: dict)[source]

Set the parameters to be updated during the simulation (e.g. a slow control parameter).

Parameters:

params (dict) – Parameters to be udpated, keys of this dict must match parameters names of the model. values of the dictionary are list of tuple indicating times and values of the parameter to be updated, i.e.: params = {I_0: [ (t0,v0), (t1,v1), (t2,v2), ... ]}

Note that the update is linear monotonic between referenced points, and the update frequency used is the sampling frequency (SF). Control parameter can only be changed during recording period.

update_control_params(index)[source]

Update the control parameters during the simulation

v()[source]

Implementing the Gaussian white noise process.

class OCD_modeling.ReducedWongWangOU(N=4, sigma_C=[], eta_C=[], *args, **kwargs)[source]

Bases: ReducedWongWangND

Reduced Wong-Wang model with Ornsetin-Uhlenbeck process for coupling (n dimensions)

__init__(N=4, sigma_C=[], eta_C=[], *args, **kwargs)[source]
integrate()[source]

Euler(-Maruyama) integration of the ODE

record_auxiliary_variables(rec_vars, rec_idx)[source]

Record auxiliary variables other than S

OCD_modeling.cohen_d(x, y)[source]

Calculates effect size as cohen’s d

OCD_modeling.compute_distance_restore(df_sims, args)[source]

Compare base simulations (from OCD subjects and healthy controls) to simulated interventions by calculating distances in parallel.

Parameters:
  • df_sims (pandas.DataFrame) – Simulation outputs loaded from the database.

  • args (argparse.Namespace) – Extra arguments with options.

Returns:

df_restore – Copy of df_sims with efficacy measures (including cohorts first level statistics).

Return type:

pandas.DataFrame

OCD_modeling.compute_equilibrium_point_curve(model, fps, pdomain)[source]

Find equilibrium point curve(s) of the system, starting from each fixed point (if exist).

Parameters:
  • model (PyDSTool.Vode_ODEsystem) – Model object in PyDSTool.

  • fps (PyDSTool.Toolbox.phaseplane.fixedpoint_2D) – Fixed points of the system.

  • pdomain (dict) – Free variable (or order parameter) to perform the bifurcation analyis from.

Returns:

cont – PyDSTool Continuation Class object populated with equilibrium point curves.

Return type:

PyDSTool.ContClass

OCD_modeling.compute_kdes(histories, n_pts=100, args=None)[source]

Computes Kernel Density Estimates (KDEs) of the posterior distributions of parameters.

Parameters:
  • histories (dict) – Nested dictionnary of SQL alchemy history objects.

  • n_pts (int) – Number of points used to estimate the probability density functions (PDFs).

  • args (argparse.Namespace) – Extra options.

Returns:

  • kdes (dict) – Nested dictiorany of KDEs and associated PDFs.

  • cols (list) – List of parameters for which the KDEs were estimated.

OCD_modeling.compute_stats(histories, args=None)[source]

Computes the statistics of the optimization outcome, i.e. tests the posterior distributions (parameters) between controls and patients.

Parameters:
  • histories (list) – Controls and patient pyABC history objects.

  • args (argparse.Namespace) – Extra options

Returns:

df_stats – Statistics.

Return type:

pandas DataFrame

OCD_modeling.compute_trajectories(model, n, tdata=[0, 1000])[source]

Compute n trajectories from model, each with different initial conditions.

Parameters:
  • model (PyDSTool.Vode_ODEsystem) – PyDSTool model object.

  • n (int) – Number of trajectories to compute.

  • tdata (list) – Time interval of the saved trajectories.

OCD_modeling.create_model(params, args=None)[source]

Create the Dynamical System in PyDSTool

\[\dot{S_i} = - \cfrac{S_i}{\tau_S} + (1 - S_i) \gamma H(x_i) + \sigma v_i\]

with

\[H(x) = \cfrac{ax-b}{1-\exp{(-d(ax-b))}}\]

and

\[x_i = w J_N S_i + G J_N \sum_j{C_{ij} S_j} + I_0\]
Parameters:
  • params (dict) – Parameters of the model

  • args (Argparse.Namespace) – Optional arguments

Returns:

rww – PyDSTool object containing the dynamical system

Return type:

PyDSTool.Vode_ODEsystem

OCD_modeling.emd(u, v)[source]

computes the Wasserstein distance (i.e. earth mover’s distance) across pathways P between u and v

OCD_modeling.get_working_dir()[source]

get computer name to set working path

OCD_modeling.import_results(args)[source]

Read optimization results from DB

OCD_modeling.launch_sims_parallel(kdes, cols, test_param, args=None)[source]

Run batched simulations from posterior inference in parallel:

Parameters:
  • kdes (dict) – Kernel Density Estimates from optimization (structured as kdes[group][param])

  • cols (list) – Parameters (columns) which draw samples from KDEs (otherwise default values are used)

  • test_param (list) – Parameters for which the posterior is permuted for the virtual interventions.

  • args (argparse.Namespace) – Extra arguments with options.

Return type:

None. Output of the simulations are written into the local SQLite database.

OCD_modeling.multivariate_analysis(df_sim_pat, params=['C_12', 'C_13', 'C_24', 'C_31', 'C_34', 'C_42'], behavs=['YBOCS_Total', 'OCIR_Total', 'OBQ_Total', 'MADRS_Total', 'HAMA_Total', 'Anx_total', 'Dep_Total'], models={'Ridge': Ridge(alpha=0.01)}, null=False, args=None)[source]

Multivariate regression of parameters to predict behaviors

OCD_modeling.rmse(u, v)[source]

compute the root mean squared error of correlation accross pathways P between u and v as \(d = \sqrt{ \sum_{p \in P} (\mu_u^p - \mu_v^p)^2}\)

Parameters:

u,v

pandas DataFrames with only pathway columns

Returns:

d

Root Mean Squared Error

OCD_modeling.simulate_population_rww(params)[source]

Run a pool of simulations and score their outputs.

As a design choice, the number of simulations per pool and the number of processes used in parallel are hard coded here in a Argparse.Namespace object which is propagated to the launcher.

Parameters:

params (dict) – Set of parameters are used to instanciate model.

Returns:

RMSE – Root Mean Square Error between the simulated pool (i.e. a “population cohort”) and the real data (either “controls” or “patients”).

Return type:

dict

OCD_modeling.simulate_rww(params)[source]

instanciate model and simulate trace

OCD_modeling.stability_analysis(order_params, default_params, out_queue, args, pdomain={'C_12': [-0.5, 1.5]})[source]

Create model and analyse dynamics using PyDSTool.

Parameters:
  • order_params (dict) – Fixed parameters, for which to analyse the system using discretized values, for example {'C_21': np.linspace(0.2,0.8,4)}.

  • default_params (dict) – Default model’s parameters.

  • out_queue (Queue) – Queue to put results in (used for parallel computation) for each values of order parameter.

  • args (Argparse.Namespace) – Structure of necessary options. For example, must include args.compute_epc = True to compute equilibrium point curves.

  • pdomain (dict) – Free variable (or order parameter) to perform the bifurcation analyis from.

Returns:

A dict with model, nullclines (ncs), fixed points (fps), trajectories (trajs), and a pickled (dilled) continuation object (if equilibrium curves are asked in args), is appended to the queue.

Return type:

None