BMSS.icanalysis
- BMSS.icanalysis.calculate_ic(data, models, params, priors={}, ictype='AIC', alpha=0.2)
Calculates ic of model calculating posterior and than applying ic formula. Returns a DataFrame of the ic Values.
- Parameters
data (dict) – Curve-fitting data.
models (dict) – The models used for curve-fitting.
params (pandas.DataFrame) – The parameters with which to integrate the models with.
priors (dict, optional) – Priors if any. The default is {}.
ictype ({'AIC', 'BIC', 'CAIC'}) – The information criterion used.
alpha (float, optional) – Controls the ratio of AIC/BIC when using CAIC. Ignored when ictype is not ‘CAIC’. The default is 0.2.
- Returns
table – A DataFrame with ic values.
- Return type
pandas.DataFrame
- BMSS.icanalysis.normalize_ic(ic_values)
Accepts a list-like array of ic values and returns a normalized array where the lowest value is zero.
- BMSS.icanalysis.rank_ic(ic_dataframe, ic_column_name='ic value', inplace=True)
Accepts a dataframe where each row corresponds to one model ic_dataframe cannot have any columns named ‘Evidence’.
BMSS.curvefitting
- BMSS.curvefitting.get_SSE_data(data, models, params={}, t_indices={}, params_array=numpy.array, params_index={})
Calculates SSE for data against models and returns the negative of the SSE.
- For testing/single calls:
Supply the parameters as a dict. Ignore all other optional arguments.
- For iterative calls:
Ignore the params argument.
Provide a numpy array of parameters instead.
Use the function get_liklihood_args to set up the other arguments.
- Parameters
data (dict) – Experimental data.
models (dict) – Dictionary of model data structures.
params (dict, optional) – For backend use only. The default is {}.
t_indices (dict, optional) – For backend use only. The default is {}.
params_array (nupy.array, optional) – An array of parameter values. The default is np.array([]).
params_index (dict, optional) – Required to work with the params_array. The default is {}.
- Returns
The negative of the SSE.
- Return type
float
- BMSS.curvefitting.get_params_for_model(models, trace, model_num, row_index)
Extracts the parameters for a particular model using the .loc method for pandas.DataFrame.
- Parameters
models (dict) – Dictionary of model data structures.
trace (pandas.DataFrame) – The accepted samples.
model_num (int) – The number of the model you are interested in.
row_index (int) – The row in the trace you want.
- Returns
The parameters for the model.
- Return type
pandas.Series or pandas.DataFrame
- BMSS.curvefitting.make_AX(plot_index={}, data={})
Generates a dictionary of axes objects using either plot_index OR data.
- BMSS.curvefitting.plot(posterior={}, guess={}, models={}, data={}, data_sd={}, plot_index={}, titles={}, labels={}, legend_args={}, figs=[], AX={}, palette='color', line_args={'linewidth': 1.5}, guess_palette='white')
Wrapper for plotting function for data, guess and posterior in one function call.
- BMSS.curvefitting.plot_data(data, data_sd={}, plot_index={}, titles={}, labels={}, legend_args={}, palette='color', figs=[], AX={}, marker='+')
Plots the experimental data.
- Parameters
data (dict) – Experimental data.
data_sd (dict, optional) – Standard deviation of experimental data. The default is {}.
plot_index (dict) – A dictionary of states and extra variables to plot.
titles (dict, optional) – A dictionary of axes titles. The default is {}.
labels (TYPE, optional) – A dictionary of line labels. The default is {}.
figs (list of matplotlib.Figure, optional) – A list of Figure objects that will be maximized after plotting. The default is ().
AX (dict of matplotlib.Axes, optional) – A dictionary of Axes objects for plotting. If {}, the Axes will be automatically generated. The default is {}.
palette (dict, optional) – A dictionary that controls the color of the plots. The default is {}.
line_args (dict, optional) – Keyword arguments for the plot method of the Axes class. The default is {}.
legend_args (dict, optional) – Keyword arguments for controlling the appearance of the legend. The default is The default is {‘linewidth’: 1.5}.
marker (TYPE, optional) – DESCRIPTION. The default is ‘+’.
- Returns
figs (list) – A list of Figure objects.
AX (dict) – A dict of Axes objects.
- BMSS.curvefitting.plot_model(models, params, plot_index={}, titles=[], labels={}, legend_args={}, palette='color', figs=[], AX={}, line_args={'linewidth': 1.5})
Plots the models.
- Parameters
models (dict) – A dictionary of model data structures.
params (pandas.DataFrame) – A DataFrame of parameter values for integration.
plot_index (dict) – A dictionary of states and extra variables to plot.
titles (dict, optional) – A dictionary of axes titles. The default is {}.
labels (TYPE, optional) – A dictionary of line labels. The default is {}.
figs (list of matplotlib.Figure, optional) – A list of Figure objects that will be maximized after plotting. The default is ().
AX (dict of matplotlib.Axes, optional) – A dictionary of Axes objects for plotting. If {}, the Axes will be automatically generated. The default is {}.
palette (dict, optional) – A dictionary that controls the color of the plots. The default is {}.
line_args (dict, optional) – Keyword arguments for the plot method of the Axes class. The default is {}.
legend_args (dict, optional) – Keyword arguments for controlling the appearance of the legend. The default is The default is {‘linewidth’: 1.5}..
- Returns
figs (list) – A list of Figure objects.
AX (dict) – A dict of Axes objects.
- BMSS.curvefitting.scipy_basinhopping(data, models, guess, priors, step_size=0.1, bounds={}, step_size_is_ratio=True, fixed_parameters=[], likelihood_function=<function get_SSE_data>, scipy_args={}, **kwargs)
Wrapper for scipy’s basin-hopping algorithm.
- Parameters
data (dict) – Experimental data.
models (dict) – Dictionary of model data structures.
guess (dict) – The initial guess. The default is {}.
priors (dict, optional) – Priors if any. The default is {}.
step_size (float or dict, optional) – Step size.
step_size_is_ratio (bool, optional) – If True, step size is a proportion of the initial guess. If False, absolute values are used.
bounds (dict, optional) – A dictionary mapping parameter names to tuples (lower, upper). The default is {}.
fixed_parameters (list, optional) – A list of parameters that will be fixed. The default is [].
likelihood_function (function, optional) – The likelihood function to be calculated. Do not change unless you know what you are doing.
- Returns
result –
- A dictionary with the following mapping:
”a” : The accepted samples “r” : The rejected samples
- Return type
dict
- BMSS.curvefitting.scipy_differential_evolution(data, models, guess, priors, fixed_parameters, bounds, likelihood_function=<function get_SSE_data>, scipy_args={})
Wrapper for scipy’s differential evolution algorithm.
- Parameters
data (dict) – Experimental data.
models (dict) – Dictionary of model data structures.
guess (dict, optional) – The initial guess. The default is {}.
priors (dict, optional) – Priors if any. The default is {}.
bounds (dict, optional) – A dictionary mapping parameter names to tuples (lower, upper). The default is {}.
fixed_parameters (list, optional) – A list of parameters that will be fixed. The default is [].
likelihood_function (function, optional) – The likelihood function to be calculated. Do not change unless you know what you are doing.
- Returns
result –
- A dictionary with the following mapping:
”a” : The accepted samples
- Return type
dict
- BMSS.curvefitting.scipy_dual_annealing(data, models, guess, priors, bounds={}, fixed_parameters=[], likelihood_function=<function get_SSE_data>, scipy_args={}, **kwargs)
Wrapper for scipy’s dual annealing algorithm.
- Parameters
data (dict) – Experimental data.
models (dict) – Dictionary of model data structures.
guess (dict) – The initial guess. The default is {}.
priors (dict, optional) – Priors if any. The default is {}.
bounds (dict, optional) – A dictionary mapping parameter names to tuples (lower, upper). The default is {}.
fixed_parameters (list, optional) – A list of parameters that will be fixed. The default is [].
likelihood_function (function, optional) – The likelihood function to be calculated. Do not change unless you know what you are doing.
- Returns
result –
- A dictionary with the following mapping:
”a” : The accepted samples “r” : The rejected samples
- Return type
dict
- BMSS.curvefitting.scipy_optimize(data, models, guess, priors, bounds={}, fixed_parameters=[], likelihood_function=<function get_SSE_data>, scipy_args={}, **kwargs)
Wrapper for scipy’s dual annealing algorithm.
- Parameters
data (dict) – Experimental data.
models (dict) – Dictionary of model data structures.
guess (dict) – The initial guess. The default is {}.
priors (dict, optional) – Priors if any. The default is {}.
bounds (dict, optional) – A dictionary mapping parameter names to tuples (lower, upper). The default is {}.
fixed_parameters (list, optional) – A list of parameters that will be fixed. The default is [].
likelihood_function (function, optional) – The likelihood function to be calculated. Do not change unless you know what you are doing.
- Returns
result –
- A dictionary with the following mapping:
”a” : The accepted samples “r” : The rejected samples
- Return type
dict
- BMSS.curvefitting.simulated_annealing(data, models, guess, priors, step_size, trials=10000, bounds={}, blocks=[], SA=True, fixed_parameters=[], likelihood_function=<function get_SSE_data>, **kwargs)
BMSS2’s primary curve-fitting algorithm.
- Parameters
data (dict) – Experimental data.
models (dict) – Dictionary of model data structures.
guess (dict) – The initial guess. The default is {}.
priors (dict, optional) – Priors if any. The default is {}.
step_size (dict, optional) – A dictionary mapping parameter names to median step-size during the stochastic transition step.
trials (int, optional) – The number of iterations. The default is 10000.
bounds (dict, optional) – A dictionary mapping parameter names to tuples (lower, upper). The default is {}.
blocks (list of lists, optional) – A list of lists grouping parameter names into blocks for blocked Gibbs sampling
SA (bool, optional) – True if you want to apply the temperature criterion. False if you want to use a constant cutoff criterion. The default is True.
fixed_parameters (list, optional) – A list of parameters that will be fixed. The default is [].
likelihood_function (function, optional) – The likelihood function to be calculated. Do not change unless you know what you are doing.
- Returns
result –
- A dictionary with the following mapping:
”a” : The accepted samples “r” : The rejected samples
- Return type
dict
BMSS.sensitivityanalysis
- BMSS.sensitivityanalysis.analyze(params, models, fixed_parameters, objective, parameter_bounds={}, mode='np', analysis_type='sobol', N=256, multiply=False)
Main algorithm for sensitivity analysis. Wraps analyze_sensitivty and sample_and_integrate.
- BMSS.sensitivityanalysis.integrate_samples(models, samples, objective, args=(), multiply=False)
Integrates the samples and evaluates the objective function for each.
- Parameters
models (dict) – A dictionary of model data structures.
samples (dict) – A dictionary of parameter values for sampling.
objective (dict) – A dictionary of objective functions to evaluate indexed by model_num.
args (tuple, optional) – Additional arguments for integration. The default is ().
multiply (bool, False) – Set this to True if you want multiplicative simulations. The default is False.
- Returns
e_models – The objective function values.
- Return type
dict
- BMSS.sensitivityanalysis.make_samples(models, params, fixed_parameters, parameter_bounds, analysis_type='sobol', N=256)
Generates samples for each model.
- BMSS.sensitivityanalysis.plot_first_order(analysis_result, problems={}, titles={}, analysis_type='sobol', figs=None, AX=None, analysis_keys=(), **heatmap_args)
If analysis_type is neither sobol, fast nor delta, use analysis_keys to specify which keys/columns to use.
- BMSS.sensitivityanalysis.plot_second_order(analysis_result, problems={}, titles={}, analysis_type='sobol', figs=None, AX=None, analysis_keys=(), **heatmap_args)
If analysis_type is not sobol, use analysis_keys to specify which keys/columns to use.
BMSS.simulation
- BMSS.simulation.export_simulation_results(y, e, prefix='', directory=None)
Save the simulation results in csv format.
- Parameters
y (dict) – The simulation results returned by integrate_models.
e (dict) – The simulation results for the extra variabes returned by integrate_models.
prefix (str, optional) – A prefix for each file generated. The default is ‘’.
directory (TYPE, optional) – The directory for storing the exported files. The default is None.
- Returns
results – Names of files generated.
- Return type
list
- BMSS.simulation.integrate_models(models, params, *extra_variables, args=(), mode='np', overlap=True, multiply=False)
Integrates models with params
- Parameters
models (dict) – A dictionary of model data structures.
params (pandas.DataFrame) – A DataFrame of parameter values for integration.
*extra_variables (function) – Additional functions for evaluating the integrated results.
args (tuple, optional) – Additional arguments for the functions to be integrated. The default is ().
mode ({'np', 'df'}, optional) – Use ‘np’ if the functions in extra_variables are meant to work with numpy arrays and ‘pd’ if functions are meant to work with DataFrames. The default is ‘np’.
overlap (TYPE, optional) – Whether or not to include the overlapping points between time segments. The default is True.
multiply (bool, optional) – Permutes parameters and scenarios if True and vice versa. The default is True.
- Returns
dict – A dictionary of the integrated results.
dict – A dictionary of the calculated extra variables.
- BMSS.simulation.make_AX(plot_index={}, data={})
Generates a dictionary of axes objects using either plot_index OR data.
- BMSS.simulation.piecewise_integrate(function, init, tspan, params, model_num, scenario_num, modify_init=None, modify_params=None, solver_args={}, solver=scipy.integrate.odeint, overlap=True, args=())
Piecewise integration function with scipy.integrate.odeint as default. Can be changed using the solver argument.
- Parameters
function (function) – A function for numerical integration that takes in the form f(states, time, params, args). states, params and args are numpy arrays while time is a float or numpy float. Will be integrated using scipy.integrate.odeint
init (numpy.array) – Initial values of states for numerical integration.
tspan (list of numpy.array) – Segments for piecewise integration where each segment is a numpy array of time points in ascending order.
params (numpy.array) – An array of parameter values.
model_num (int) – Number of the model.
scenario_num (int) – Number of the scenario.
modify_init (function, optional) – Function for modifying initial values before integrating over a time segment. The default is None.
modify_params (function, optional) – Function for modifying parameter values before integrating over a time segment. The default is None.
solver_args (dict, optional) – Dictionary of keyword arguments for scipy.integrate.odeint. The default is {}.
solver (scipy.integrate.odeint, optional) – The integrating function. The default is odeint. Do not touch unless you know what you are doing.
overlap (bool, optional) – Avoids double counting between segments. In general, False is required only for plotting. The default is True.
args (tuple, optional) – A tuple of arguments. The default is ().
- Returns
y_model (numpy.array) – An array of values from numerical integration.
t_model (numpy.array) – An array of time points.
- BMSS.simulation.plot_model(plot_index, y, e={}, titles={}, labels={}, figs=(), AX={}, palette={}, line_args={}, legend_args={})
Plots the integrated results.
- Parameters
plot_index (dict) – A dictionary of states and extra variables to plot.
y (dict) – The values of the integrated results from integrate_models.
e (dict, optional) – The values of the integrated results from integrate_models. The default is {}.
titles (dict, optional) – A dictionary of axes titles. The default is {}.
labels (TYPE, optional) – A dictionary of line labels. The default is {}.
figs (list of matplotlib.Figure, optional) – A list of Figure objects that will be maximized after plotting. The default is ().
AX (dict of matplotlib.Axes, optional) – A dictionary of Axes objects for plotting. If {}, the Axes will be automatically generated. The default is {}.
palette (dict, optional) – A dictionary that controls the color of the plots. The default is {}.
line_args (dict, optional) – Keyword arguments for the plot method of the Axes class. The default is {}.
legend_args (dict, optional) – Keyword arguments for controlling the appearance of the legend. The default is {}.
- Returns
figs (list) – A list of Figure objects.
AX (dict) – A dict of Axes objects.
BMSS.strike_goldd_simplified
- BMSS.strike_goldd_simplified.analyze_sg_args(sg_args, dst={})
Accepts a dictionary of arguments and runs the STRIKE-GOLDD algorithm.
BMSS.traceanalysis
- BMSS.traceanalysis.calculate_rhat(traces, skip=None)
Calculates R-hat which the ratio between the variance within a chain against the variance between chains.
- Parameters
traces – A dict of traces.
skip – A list of parameters to not calculate R-hat for.
- Return rhat
A Series of R-hat values.
- BMSS.traceanalysis.check_kurtosis(traces, output='df')
Calculates kurtosis of distribution of sampled parameters
- Parameters
traces – A dict of traces.
output – Causes the return value to be formatted as DataFrame.
- Return result
A DataFrame if output is “df” and a dict otherwise.
- BMSS.traceanalysis.check_skewness(traces, output='df')
Calculates skewness of distribution of sampled parameters
- Parameters
traces – A dict of traces.
output – Causes the return value to be formatted as DataFrame.
- Return result
A DataFrame if output is “df” and a dict otherwise.
- BMSS.traceanalysis.import_trace(files, keys=[], **pd_args)
Used for traces that have been saved to csv files.
- Parameters
files – A list of file names.
keys – A list of keys to index the traces.
pd_args – Keyword arguments for pandas.read_csv.
- Return traces
Returns a dict of traces.
- BMSS.traceanalysis.pairplot_kde(traces, pairs, figs=[], AX={}, palette={}, legend_args={}, plot_args={})
Generates a pair plot between two parameters in kde form.
- BMSS.traceanalysis.pairplot_steps(traces, pairs, figs=[], AX={}, gradient=5, palette={}, legend_args={}, plot_args={'linewidth': 0, 'marker': '+'}, palette_type='light')
Generates a pair plot between two parameters.
- BMSS.traceanalysis.plot_hist(traces, skip=[], figs=[], AX={}, palette={}, legend_args={}, plot_args={})
Generates histogram plot for parameters.
- Parameters
traces – A dict of traces.
skip – A list of parameters to not plot.
figs – A list of figures for containing the plots. Default is None.
AX – A dict of param - Axes object pairs. Default is None.
palette – A dict of colors. Default is None.
legend_args – A dict of arguments for the legend. Default is None.
plot_args – A dict of arguments for plotting such as marker.
- Return result
Figure and Axes objects.
- BMSS.traceanalysis.plot_kde(traces, skip=[], figs=[], AX={}, palette={}, legend_args={}, plot_args={'linewidth': 3})
Generates kde plot for parameters.
- Parameters
traces – A dict of traces.
skip – A list of parameters to not plot.
figs – A list of figures for containing the plots. Default is None.
AX – A dict of param - Axes object pairs. Default is None.
palette – A dict of colors. Default is None.
legend_args – A dict of arguments for the legend. Default is None.
plot_args – A dict of arguments for plotting such as marker.
- Return result
Figure and Axes objects.
- BMSS.traceanalysis.plot_steps(traces, skip=[], figs=None, AX=None, palette=None, legend_args={}, plot_args={'linewidth': 0, 'marker': '+'})
Generates trace plot for parameters.
- Parameters
traces – A dict of traces.
skip – A list of parameters to not plot.
figs – A list of figures for containing the plots. Default is None.
AX – A dict of param - Axes object pairs. Default is None.
palette – A dict of colors. Default is None.
legend_args – A dict of arguments for the legend. Default is None.
plot_args – A dict of arguments for plotting such as marker.
- Return result
Figure and Axes objects.