bayesim.model.
Model
(**argv)[source]¶Bases: object
The main workhorse class of bayesim. Stores the modeled and observed data as well as a Pmf object which maintains the current probability distribution and grid subdivisions.
Attributes: [update this]
attach_fit_params
(params)[source]¶Attach list of parameters to fit.
Parameters: | param_list – list of Fit_param objects |
---|
attach_model
(**argv)[source]¶Attach the model for the data, either by feeding in a file of precomputed data or a function that does the computing.
Parameters: |
|
---|
attach_observations
(**argv)[source]¶Attach measured dataset.
Parameters: |
|
---|
calc_indices
()[source]¶Compute starting and ending indices in self.model_data for each point in self.probs.
calc_model_unc
(**argv)[source]¶Calculates largest difference in modeled output along any parameter direction for each experimental condition, to be used for uncertainty in calculating likelihoods. Currently only works if data is on a grid.
(also assumes it’s sorted by param names and then EC’s)
Parameters: |
|
---|
Note
If both min_unc_frac and min_unc_val are specified, the uncertainty will be set to the larger of the two in each case
check_data_columns
(**argv)[source]¶Make sure the columns in imported data make sense.
Parameters: |
|
---|
check_ecs
(**argv)[source]¶Check that all experimental conditions are present at each parameter point in modeled data.
Parameters: |
|
---|
comparison_plot
(**argv)[source]¶Plot observed data vs. highest-probability modeled data.
Parameters: |
|
---|
list_model_pts_to_run
(fpath, **argv)[source]¶Generate full list of model points that need to be run (not just parameter points but also all experimental conditions). Saves to HDF5 at fpath.
Note that this could be very slow if used on the initial grid (i.e. for potentially millions of points) - it’s better for after a subdivide call.
Parameters: |
|
---|
run
(**argv)[source]¶Do Bayes! Will stop iterating through observations if/when >= th_pm of probability mass is concentrated in <= th_pv of boxes and decide it’s time to subdivide. (completely arbitrary thresholding for now)
Parameters: |
|
---|
save_state
(filename='bayesim_state.h5')[source]¶Save the entire state of this model object to an HDF5 file so that work can be resumed later.
set_param_info
(param_name, **argv)[source]¶Set additional info for parameter param_name (any type).
Parameters: |
---|
subdivide
(**argv)[source]¶Subdivide the probability distribution and save the list of new sims to run to a file.
Parameters: |
|
---|
top_probs
(num)[source]¶Return a DataFrame with the ‘num’ most probable points and some of the less interesting columns hidden.
bayesim.params.
Fit_param
(**argv)[source]¶Bases: bayesim.params.Param
A bayesim fitting parameter. Because they will be initialized on a grid, each fitting parameter stores its full list of values as well as some other information such as the spacing between them and the minimum width of a box (used during grid subdivisions).
bayesim.params.
Measured_param
(**argv)[source]¶Bases: bayesim.params.Param
A bayesim measured parameter. Can be experimental input or output.
bayesim.params.
Param
(**argv)[source]¶Bases: object
A parameter in a bayesim analysis. Can be a fitting parameter or an experimental condition.
bayesim.params.
Param_list
(**argv)[source]¶Bases: object
Small class to facilitate listing and comparison of bayesim parameters.
add_ec
(**argv)[source]¶Add an experimental condition.
Parameters: |
|
---|
add_fit_param
(**argv)[source]¶Add a fitting parameter to the list.
Parameters: |
|
---|
find_param
(name)[source]¶Return the Param object with the given name.
Parameters: | name (str) – name to search for |
---|
param_names
(param_type=None)[source]¶Return a list of parameter names. If no arguments provided, output will be a dict, if a type is provided, output will be a list of just the parameter names of that type.
bayesim.pmf.
Pmf
(**argv)[source]¶Bases: object
Class that stores a PMF capable of nested sampling / “adaptive mesh refinement”.
Stores probabilities in a DataFrame which associates regions of parameter space with probability values.
likelihood
(**argv)[source]¶Compute likelihood over this Pmf’s parameter space given modeled data at the given EC’s for every parameter space point and a measurement at the same EC’s.
Parameters: |
|
---|
make_points_list
(params, total_prob=1.0)[source]¶Helper function for Pmf.__init__ as well as Pmf.subdivide. Given names and values for parameters, generate DataFrame listing values, bounds, and probabilities.
Parameters: |
|
---|---|
Returns: | obj:DataFrame with columns for each parameter’s value, min, and max as well as a probability associated with that point in parameter space |
multiply
(other_pmf, **argv)[source]¶Compute and store renormalized product of this Pmf with other_pmf.
Parameters: | other_pmf (Pmf ) – PMF to multiply by |
---|
populate_dense_grid
(**argv)[source]¶Populate a grid such as the one created by make_dense_grid.
Parameters: |
|
---|---|
Returns: | a dict with keys for each thing requested |
project_1D
(param, dense_grid=[])[source]¶Project down to a one-dimensional PMF over the given parameter. Used by the visualize() method.
Parameters: | param (Fit_param ) – one of self.params |
---|---|
Returns: | bin edges for plotting with matplotlib.pyplot.hist (has length one more than next return list)
probs (list of float ): probability values for histogram-style plot - note that these technically have units of the inverse of whatever the parameter being plotted is (that is, they’re probability densities)
dense_grid (matrix): optionally, pass precomputed dense grid to save time |
Return type: | bins (list of float ) |
project_2D
(x_param, y_param, no_probs=False, dense_grid=[])[source]¶Project down to two dimensions over the two parameters. This one doesn’t actually need to sum, it just draws a bunch of (potentially overlapping) rectangles with transparencies according to their probability densities (as a fraction of the normalized area). Used by the visualize() method.
Parameters: |
|
---|---|
Returns: | patches for plotting the 2D joint probability distribution |
Return type: | ( |
subdivide
(threshold_prob, include_neighbors=True, **argv)[source]¶Subdivide all boxes with P > threshold_prob and assign “locally uniform” probabilities within each box. If include_neighbors is true, also subdivide all boxes neighboring those boxes.
Boxes with P < threshold_prob are deleted.
Parameters: |
|
---|
uniformize
()[source]¶Keep PMF shape and subdivisions but make every probability equal. Useful for rerunning whole inference after subdividing.
Note that because subdivisions are not uniform that this is NOT a uniform prior anymore.
visualize
(**argv)[source]¶Make histogram matrix to visualize the PMF.
Parameters: |
|
---|
bayesim.utils.
calc_deltas
(grp, inds, param_lengths, model_data, fit_param_names, probs, output_var, take_average)[source]¶bayesim.utils.
visualize_PMF_sequence
(statefile_list, **argv)[source]¶Create plot akin to that produced by pmf.visualize() but with data from multiple PMF’s overlaid. All should have the same set of fitting parameters. For now assumes that first statefile has the largest axes bounds, will add automated check later.
Parameters: |
|
---|