Case`s can be accessed by case number, eg `sim[0], and InVar`s or
`OutVar`s can be accessed by name, eg `sim[‘Var1’].
Parameters:
name (str) – The name for the simulation.
ndraws (int) – The number of random draws to perform.
fcns (dict[monaco.mc_enums.SimFunctions, Callable] |) – monaco.mc_enums.SimulationFunctions
fcns is either a dict with keys ‘preprocess’, ‘run’, and ‘postprocess’
pointing to user-defined functions, or a SimulationFunctions object
containing the three functions.
firstcaseismedian (bool, default: False) – Whether the first case represents the median value.
seed (int, default: np.random.get_state(legacy=False)['state']['key'][0]) – The random number to seed the simulation.
singlethreaded (bool, default: False) – Whether to run single threaded. This takes precedence over usedask.
usedask (bool, default: False) – Whether to use dask for parallelization. If False and not
singlethreaded, will use multiprocessing.
ncores (int, default: None) – The number of cores to use for multiprocessing. If None, will use all
available cores. This will override the n_workers kwarg in daskkwargs
if provided.
multiprocessing_method (str, default: None) – The method to use for multiprocessing. If None, will use the method
specified by the multiprocessing.get_start_method() function.
Valid options are: ‘fork’, ‘spawn’, ‘forkserver’.
verbose (bool, default: True) – Whether to print out warning and status messages.
debug (bool, default: False) – If False, cases that fail while running will be skipped over. If True,
cases that fail will raise an exception.
keepsiminput (bool, default: False) – Whether to keep the siminput for each case after running.
keepsimrawoutput (bool, default: False) – Whether to keep the simrawoutput for each case after postprocessing.
savesimdata (bool, default: False) – Whether to automatically save the simulation data to disk as a .mcsim
file. This can be manually done with sim.saveSim().
savecasedata (bool, default: False) – Whether to automatically save the full output data for each case to
disk as separate .mccase files. This can be manually done with
sim.saveCases().
resultsdir (str | pathlib.Path) – The directory to save simulation and case data to. If None, then this
defaults to a directory named {name}_results.
If dist is provided, then the variable will be drawn from a
statistical distribution. If vals is provided, then the variable will
be set to the provided values. Must provide one or the other.
dist (scipy.stats.rv_discrete | scipy.stats.rv_continuous | None) – The statistical distribution to draw from. If None, must provide vals.
distkwargs (dict[str, Any] | None) – The keyword argument pairs for the statistical distribution
function.
nummap (dict[float, Any], default: None) – A dictionary mapping numbers to nonnumeric values.
vals (list[Any] | None, default: None) – Custom values to use instead of drawing from a distribution.
Length must match ncases.
pcts (list[float] | None, default: None) – Custom percentiles between 0 and 1 to use instead of random draws.
Length must match ncases, and the first percentile must be 0.5 if
firstcaseismedian is True.
seed (int | None) – The random seed for this variable. If None, a seed will be assigned
based on the order added.
datasource (str, default: None) – If the invals were imported from a file, this is the filepath. If
generated through monaco, then None.
Extend the non-scalar output variables with their last value, so that
they all have the same shape. Can be useful for plotting or calculating
variable statistics.
Parameters:
outvars (dict[str, OutVar], default: None) – The output variables to extend. If None, then extends all the
output variables.
Calculate the sensitivity indices for the specified outvars.
Parameters:
outvarnames (None | str | Iterable[str] (default: None)) – The outvar names to calculate sensitivity indices for. If None,
then calculates sensitivities for all scalar outvars.
cases (None | int | Iterable[int], default: None) – The cases to calculate sensitivities for. If None, then all cases
are used.
tol (float, default 1e-6) – The convergence tolerance for scipy’s minimize function acting on the
negative log likelihood function.
verbose (bool, default False) – Whether to print diagnostic information.
Generate a correlation matrix between all the scalar variables.
Returns:
(corcoeffs, covvarlist) – corrcoeffs is a correlation matrix between all the scalar input
and output variables.
covvarlist is a list of all the scalar input and output variables.
Generate a covariance matrix between all the scalar variables.
Returns:
(covs, covvarlist) – covs is a covariance matrix between all the scalar input and
output variables.
covvarlist is a list of all the scalar input and output variables.
Plot all the scalar variables against each other in a grid.
Parameters:
scalarvars (list[monaco.mc_var.InVar | monaco.mc_var.OutVar | str]) – The variables to plot. If None, then grabs all the input variables
and scalar output variables.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are plotted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
rug_plot (bool, default: False) – Whether to plot rug marks.
cov_plot (bool, default: False) – Whether to plot a covariance ellipse at a certain gaussian percentile
level.
cov_p (None | float | Iterable[float], default: None) – The gaussian percentiles for the covariance plot.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
fig (matplotlib.figure.Figure, default: None) – The figure handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, axes) – fig is the figure handle for the plot.
axes is a tuple of the axes handles for the plots.
Export the drawn nums for all the invars to file for use externally.
See monaco.Sim._exportVars docstring for csv and json formatting.
Parameters:
filename (Optional[str | pathlib.Path]) – The file to save to. Must be a csv or json.
If a str, then will save in the resultsdir.
If None, then will save to ‘{self.name}_invarnums.json’.
Export the nums for all the outvars to file for use externally.
See monaco.Sim._exportVars docstring for csv and json formatting.
Parameters:
filename (Optional[str | pathlib.Path]) – The file to save to. Must be a csv or json.
If a str, then will save in the resultsdir.
If None, then will save to ‘{self.name}_outvarnums.json’.
Import draws from an external file as InVals. For each of the keyword
arguments, they must be the same length as the number of invars.
See monaco.Sim._importVars docstring for csv and json formatting.
Parameters:
filepath (str | pathlib.Path) – The file to load from. Must be a csv or json.
dists (list[rv_discrete | rv_continuous], default: None) – A list of the distribution that was used for the draws. Needed if
it is desired to plot the analytical distribution or run a DVARS
sensitivity analysis. Note that for discrete distributions, the
calcuated percentiles will not likely match the original draws.
distskwargs (list[dict[str, Any]], default: None) – A list of the distribution kwargs that were used for the draws.
Must be matched with dists above.
nummaps (list[dict[Any, float]], default: None) – A list of nummap dicts mapping numbers to nonnumeric values.
Import results from an external file as OutVals, convert to OutVars.
See monaco.Sim._importVars docstring for csv and json formatting.
Parameters:
filepath (str | pathlib.Path) – The file to load from. Must be a csv or json.
nummaps (list[dict[float, Any]], default: None) – A list of nummap dicts mapping numbers to nonnumeric values. Note
that this is reversed from providing valmaps to OutVals.
If include_cases is False, the case data will not be saved. To do that,
use sim.saveCases().
Parameters:
filepath (str | pathlib.Path | None) – The file to save to. If None, save to the results directory.
include_cases (bool | None) – Whether to include the case data when saving the simulation. If
None, will use the opposite of the savecasedata attribute.
Object to hold all the data for a single Monte Carlo case.
InVal`s and `OutVal`s can be accessed by name, eg `case[‘Var1’].
Parameters:
ncase (int) – The number of this case.
ismedian (bool) – Whether this represents the median case.
invars (dict[str, monaco.mc_var.InVar]) – A dict pointing to all of the input variables.
constvals (dict[str, Any], default: None) – A dict of any constant values common to all cases.
keepsiminput (bool, default: True) – Whether to keep the siminput after running.
keepsimrawoutput (bool, default: True) – Whether to keep the simrawoutput after postprocessing.
seed (int, default: np.random.get_state(legacy=False)['state']['key'][0]) – The random seed to pass to the run function for this case. Not used in
as part of any Monte Carlo sampling.
statkwargs (dict[str, Any]) – Keyword arguments for the specified variable statistic.
cases (None | int | Iterable[int]) – The cases to use to calculate the statistic. If None, then all cases
are used.
bootstrap (bool (default: True)) – Whether to use bootstrapping to generate confidence intervals for
the statistic.
bootstrap_k (int (default: 10)) – The k’th order statistic to determine the number of bootstrap draws
for the given confidence level. Must be >= 1. Set higher for a
smoother bootstrap distribution.
If dist is provided, then the variable will be drawn from a
statistical distribution. If vals is provided, then the variable will
be set to the provided values. Must provide one or the other.
InVal`s can be accessed by case number, eg `invar[0].
Parameters:
name (str) – The name of this variable.
ndraws (int) – The number of random draws.
dist (scipy.stats.rv_discrete | scipy.stats.rv_continuous) – The statistical distribution to draw from.
distkwargs (dict) – The keyword argument pairs for the statistical distribution function.
nummap (dict[float, Any] | None, default: None) – A dictionary mapping numbers to nonnumeric values (the inverse of
valmap).
vals (list[Any] | None, default: None) – Custom values to use instead of drawing from a distribution.
Length must match ncases.
pcts (list[float] | None, default: None) – Custom percentiles between 0 and 1 to use instead of random draws.
Length must match ncases, and the first percentile must be 0.5 if
firstcaseismedian is True.
The values corresponding to the randomly drawn numbers. If valmap is
None, then vals == nums.tolist(). If custom values are provided, then
these are the custom values.
Perform the random draws based on the sampling method and the
statistical distribution, and map those draws to values.
Alternatively, use custom values if provided.
Parameters:
ninvar_max (int) – The total number of input variables for the simulation.
ncase (int) – The number of the case for this value.
pct (float) – The percentile of the value draw.
num (float) – The number corresponding to the statistical percentile draw.
dist (scipy.stats.rv_discrete | scipy.stats.rv_continuous) – The statistical distribution that num was drawn from.
nummap (dict[float, Any], default: None) – A dictionary mapping numbers to nonnumeric values.
valmap (dict[Any, float], default: None) – A dictionary mapping nonnumeric values to numbers. If None, then
will be generated from the nummap. Note that there is no checking
that the valmap is consistent with the nummap.
ismedian (bool, default: False) – Whether this case represents the median case.
datasource (str | None, default: None) – If the value was imported from a file, this is the filepath. If
generated through monaco, then None.
stat (monaco.mc_enums.VarStatType | Callable) – The statistic to generate. Can be custom. If custom, must be able to
accept an “axis” kwarg for bootstrap vectorization.
statkwargs (dict[str:Any]) – The keyword arguments for the variable statistic.
cases (None | int | Iterable[int], default: None) – The cases to use when calculating the statistic. If None, then all cases
are used.
bootstrap (bool (default: True)) – Whether to use bootstrapping to generate confidence intervals for the
statistic.
bootstrap_k (int (default: 10)) – The k’th order statistic to determine the number of bootstrap draws for
the given confidence level. Must be >= 1. Set higher for a smoother
bootstrap distribution.
conf (float (default: 0.95)) – The confidence level for the confidence interval.
seed (int (default: np.random.get_state(legacy=False)['state']['key'][0])) – The random seed to use for bootstrapping.
A wrapper function to allow using a bootstrap function that uses kwargs.
Relies on self.fcn and self.fcnkwargs already being set. Note that fcn
must accept an axis kwarg if bootstrapping.
Parameters:
x (Any) – The input for the function.
axis (int (default: None)) – The axis of x to calculate along.
The preprocess function must take in only a moncao.mc_case.Case object. It
then must return a tuple of the input arguments for the run function.
The run function will take in whatever inputs and return whatever outputs.
It it recommended to package the outputs into a tuple.
The postprocess function must take in as its first argument a
moncao.mc_case.Case object, followed by the outputs from the run function.
The simulation will attempt to unpack the run function outputs if they are
stored in a tuple.
For nummap and valmap, we need to use values as keys in a dictionary.
This function will return the string representation of a value if that
value is not hashable.
Parameters:
val (Any) – The value to hash.
Returns:
hashable_val – A hashable representation of the val.
ninvar (int) – For all but the ‘random’ method, must define which number input
variable is being sampled, ninvar >= 1. The ‘sobol’ and
‘sobol_random’ methods must have ninvar <= 21201
ninvar_max (int) – The total number of invars, ninvar_max >= ninvar. Used for caching.
seed (int, default: np.random.get_state(legacy=False)['state']['key'][0]) – The random seed. Not used in ‘sobol’ or ‘halton’ methods.
Returns:
pcts – The random samples. Each sample is 0 <= pct <= 1.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are plotted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
rug_plot (bool, default: True) – Whether to plot rug marks.
cov_plot (bool, default: False) – Whether to plot a covariance ellipse at a certain gaussian percentile
level.
cov_p (None | float | Iterable[float], default: None) – The gaussian percentiles for the covariance plot.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
ax (matplotlib.axes.Axes, default: None) – The axes handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, ax) – fig is the figure handle for the plot.
ax is the axes handle for the plot.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are plotted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
cumulative (bool, default: False) – Whether to plot the histograms as cumulative distribution functions.
orientation (monaco.mc_enums.PlotOrientation, default: 'vertical') – The orientation of the histogram. Either ‘vertical’ or ‘horizontal’.
rug_plot (bool, default: True) – Whether to plot rug marks.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
ax (matplotlib.axes.Axes, default: None) – The axes handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, ax) – fig is the figure handle for the plot.
ax is the axes handle for the plot.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are plotted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
orientation (monaco.mc_enums.PlotOrientation, default: 'vertical') – The orientation of the histogram. Either ‘vertical’ or ‘horizontal’.
rug_plot (bool, default: True) – Whether to plot rug marks.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
ax (matplotlib.axes.Axes, default: None) – The axes handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, ax) – fig is the figure handle for the plot.
ax is the axes handle for the plot.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are highlighted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
rug_plot (bool, default: True) – Whether to plot rug marks.
cov_plot (bool, default: False) – Whether to plot a covariance ellipse at a certain gaussian percentile
level.
cov_p (None | float | Iterable[float], default: None) – The gaussian percentiles for the covariance plot.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
ax (matplotlib.axes.Axes, default: None) – The axes handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, ax) – fig is the figure handle for the plot.
ax is the axes handle for the plot.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are highlighted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
ax (matplotlib.axes.Axes, default: None) – The axes handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, ax) – fig is the figure handle for the plot.
ax is the axes handle for the plot.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are highlighted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
ax (matplotlib.axes.Axes, default: None) – The axes handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, ax) – fig is the figure handle for the plot.
ax is the axes handle for the plot.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are highlighted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
ax (matplotlib.axes.Axes, default: None) – The axes handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, ax) – fig is the figure handle for the plot.
ax is the axes handle for the plot.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are highlighted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
ax (matplotlib.axes.Axes, default: None) – The axes handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, ax) – fig is the figure handle for the plot.
ax is the axes handle for the plot.
For a Monte Carlo integration where the reference value is known, plot the
running integration error along with error bounds for a given confidence
level.
Parameters:
outvar (monaco.mc_var.OutVar) – The variable representing the integration estimate.
dimension (int) – The number of dimensions over which the integration was performed.
volume (float) – The total integration volume.
refval (float) – The reference value for the integration.
cases (None | int | Iterable[int], default: None) – The cases to use for the integration error plot. If None, all cases
will be used.
conf (float, default: 0.95) – The confidence level for the error estimate. 0.95 corresponds to 95%.
samplemethod (monaco.mc_enums.SampleMethod) – The sample method used for integration. Either ‘random’ or ‘sobol’.
ax (matplotlib.axes.Axes, default: None) – The axes handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, ax) – fig is the figure handle for the plot.
ax is the axes handle for the plot.
For a Monte Carlo integration where the reference value is known, plot the
running integration error along with error bounds for a given confidence
level.
Parameters:
outvar (monaco.mc_var.OutVar) – The variable representing the integration estimate.
sensitivities (monaco.mc_enums.Sensitivities, default: 'ratios') – The sensitivities to plot. Either ‘ratios’ or ‘indices’.
sort (bool, default: True) – Whether to show the sensitivity indices sorted from greatest to least.
ax (matplotlib.axes.Axes, default: None) – The axes handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, ax) – fig is the figure handle for the plot.
ax is the axes handle for the plot.
Parse the invarspace input for plotting functions. If already an iterable
of the right length, passes through. If a single value, returns a list of
the invarspace of the right length.
Parameters:
invar_space (monaco.InVarSpace | Iterable[InVarSpace]) – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
nvars (int) – The length of the list to generate.
Returns:
invar_space_list – A list of length nvars for the desired InVarSpace’s.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are plotted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
rug_plot (bool, default: False) – Whether to plot rug marks.
cov_plot (bool, default: False) – Whether to plot a covariance ellipse at a certain gaussian percentile
level.
cov_p (None | float | Iterable[float], default: None) – The gaussian percentiles for the covariance plot.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
fig (matplotlib.figure.Figure, default: None) – The figure handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, axes) – fig is the figure handle for the plot.
axes is a tuple of the axes handles for the plots.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are plotted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
rug_plot (bool, default: False) – Whether to plot rug marks.
cov_plot (bool, default: False) – Whether to plot a covariance ellipse at a certain gaussian percentile
level.
cov_p (None | float | Iterable[float], default: None) – The gaussian percentiles for the covariance plot.
cumulative (bool, default: False) – Whether to plot the histograms as cumulative distribution functions.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
fig (matplotlib.figure.Figure, default: None) – The figure handle to plot in. If None, a new figure is created.
(matplotlib.axes.Axes, matplotlib.axes.Axes, matplotlib.axes.Axes)) – fig is the figure handle for the plot.
(ax1, ax2, ax3) are the axes handles for the central, y-axis, and
x-axis plots, respectively.
Plot multiple variables against each other in a triangular grid. The
off-diagonal grid locations show scatterplots of the two corresponding
variables. The plots along the diagonal show histograms for the
corresponding variables.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are plotted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
rug_plot (bool, default: False) – Whether to plot rug marks.
cov_plot (bool, default: False) – Whether to plot a covariance ellipse at a certain gaussian percentile
level.
cov_p (None | float | Iterable[float], default: None) – The gaussian percentiles for the covariance plot.
cumulative (bool, default: False) – Whether to plot the histograms as cumulative distribution functions.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
fig (matplotlib.figure.Figure, default: None) – The figure handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, axes) – fig is the figure handle for the plot.
axes is a tuple of the axes handles for the plots, starting from
the top-left corner and working left-to-right, then top-to-bottom.
Plot multiple variables against each other in a rectangual grid. The
left column and bottom row show histograms for each variable, and the middle
grid locations show the scatter plots between each pari of variables.
cases (None | int | Iterable[int], default: None) – The cases to plot. If None, then all cases are plotted.
highlight_cases (None | int | Iterable[int], default: []) – The cases to highlight. If [], then no cases are highlighted.
rug_plot (bool, default: False) – Whether to plot rug marks.
cov_plot (bool, default: False) – Whether to plot a covariance ellipse at a certain gaussian percentile
level.
cov_p (None | float | Iterable[float], default: None) – The gaussian percentiles for the covariance plot.
cumulative (bool, default: False) – Whether to plot the histograms as cumulative distribution functions.
invar_space (monaco.InVarSpace | Iterable[InVarSpace], default: 'nums') – The space to plot invars in, either ‘nums’ or ‘pcts’. If an iterable,
specifies this individually for each of varx, vary, and varz.
fig (matplotlib.figure.Figure, default: None) – The figure handle to plot in. If None, a new figure is created.
title (str, default: '') – The figure title.
Returns:
(fig, axes) – fig is the figure handle for the plot.
axes is a tuple of the axes handles for the plots, starting from
the top-left corner and working left-to-right, then top-to-bottom.
Converts a percentile to a gaussian sigma value (1-sided), or to the
sigma value for which the range (-sigma, +sigma) bounds that percent of
the normal distribution (2-sided).
Converts a percentile to a sigma value which bounds a df-dimensional
gaussian distribution, used in generating confidence ellipsoids. Note
that in the 1-D case, np.sqrt(scipy.stats.chi2.ppf(p, df=1)) is
equivalent to pct2sig(p >= 0.5, bound = ‘2-sided’) ==
scipy.stats.norm.ppf(1-(1-p)/2)
Parameters:
p (float) – The percentile to convert, 0 < p < 1.
df (int) – The degrees of freedom, df > 0.
Returns:
sig – The gaussian sigma value for the input percentile.
Converts a sigma value which bounds a df-dimensional gaussian distribution,
to a percentil used in generating confidence ellipsoids. Note that in the
1-D case, scipy.stats.chi2.cdf(sig**2, df=1) is equivalent to
sig2pct(sig > 0, bound=’2-sided) == 1-(1-scipy.stats.norm.cdf(sig))*2
Parameters:
sig (float) – The gaussian sigma value to convert, sig > 0.
For an Order Statistic Tolerance Interval, find the minimum n from k, p,
and c
Notes
This function returns the number of cases n necessary to say that the true
result of a measurement x will be bounded by the k’th order statistic with
a probability p and confidence c. Variables l and u below indicate lower
and upper indices of the order statistic.
For example, if I want to use my 2nd highest measurement as a bound on 99%
of all future samples with 90% confidence:
The 388th value of x when sorted from low to high, or sorted(x)[-2], will
bound the upper end of the measurement with P99/90.
‘2-sided’ gives the result for the measurement lying between the k’th lowest
and k’th highest measurements. If we run the above function with
bound=’2-sided’, then n = 668, and we can say that the true measurement lies
between sorted(x)[1] and sorted(x)[-2] with P99/90.
See chapter 5 of Reference [1] for statistical background.
Parameters:
k (int) – The k’th order statistic.
p (float (0 < p < 1)) – The percent covered by the tolerance interval.
c (float (0 < c < 1)) – The confidence of the interval bound.
nmax (int, default: 1e7) – The maximum number of draws. Hard limit of 2**1000.
bound (monaco.mc_enums.StatBound, default: '2-sided') – The statistical bound, either ‘1-sided’ or ‘2-sided’.
Returns:
n – The number of samples necessary to meet the constraints.
Order Statistic Percentile, find minimum n from k, P, and c.
Notes
This function returns the number of cases n necessary to say that the true
Pth percentile located at or between indices iPl and iPu of a measurement x
will be bounded by the k’th order statistic with confidence c.
For example, if I want to use my 5th nearest measurement as a bound on the
50th Percentile with 90% confidence:
The 19-5 = 14th and 20+5= 25th values of x when sorted from low to high, or
[sorted(x)[13], sorted(x)[24]] will bound the 50th percentile with 90%
confidence.
‘2-sided’ gives the upper and lower bounds. ‘1-sided lower’ and
‘1-sided upper’ give the respective lower or upper bound of the Pth
percentile over the entire rest of the distribution.
See chapter 5 of Reference [2] for statistical background.
Parameters:
k (int) – The k’th order statistic.
P (float (0 < P < 1)) – The target percentile.
c (float (0 < c < 1)) – The confidence of the interval bound.
nmax (int, default: 1e7) – The maximum number of draws. Hard limit of 2**1000.
bound (monaco.mc_enums.StatBound, default: '2-sided') – The statistical bound, ‘1-sided upper’, ‘1-sided lower’, or ‘2-sided’.
Returns:
n – The number of samples necessary to meet the constraints.
Returns the bounding integration error for an input array of numbers. This
error can be a float point estimate if runningerror == False, or a numpy
array showing running error over the samples, to demonstrate convergence.
If volume == 1, the error returned is a percent error. Otherwise, the error
is absolute over the integration volume.
Parameters:
nums (list[float]) – A list of the integration point estimates across the volume.
dimension (int) – The number of dimensions in the integration volume, dimension > 0.
volume (float) – The integration volume, > 0. If volume == 1 (default), then the error
returned is a percentage of the true integration volume.
conf (float) – Confidence level of the calculated error. This must be 0 < conf < 1,
and should be 0.5 < conf < 1.
samplemethod (monaco.mc_enums.SampleMethod) – Monte Carlo sample method. Either ‘random’ (default and bounding), or
‘sobol’. If using a different sample method, use ‘random’ here.
runningerror (bool) – If False, returns a point estimate. If True, returns an array
containing the running error over all of the integration estimates.
Returns:
error – Either a point estimate of the error if runningerror == False, or an
array of the running error if runningerror is True.
Returns the bounding integration error for an input array of numbers. This
error can be a float point estimate if runningerror == False, or a numpy
array showing running error over the samples, to demonstrate convergence.
If volume == 1, the error returned is a percent error. Otherwise, the error
is absolute over the integration volume.
We generally do not know a priori what the standard deviation will be, so
best practice is to set to the max range of values on the interval, and
then calculate a better stdev on a lower number of cases, which can then
be subsituted in here to bootleg a more efficient computation.
For sobol sampling, remember to round n to the next power of 2 for balance.
monaco.helper_functions.next_power_of_2(n) can help with this.
Parameters:
error (float) – The target error.
dimension (int) – The number of dimensions in the integration volume, dimension > 0.
volume (float) – The integration volume, > 0. If volume == 1 (default), then the target
error is a percentage of the true integration volume.
stdev (float) – The standard deviation of the integration estimates, stdev > 0. We
generally do not know this a priori, so use
monaco.integration_statistics.max_stdev to calculate this in that
instance. Or, do a limited number of cases to estimate this before
performing the full run.
conf (float) – Confidence level of the calculated error. This must be 0 < conf < 1,
and should be 0.5 < conf < 1.
samplemethod (monaco.mc_enums.SampleMethod) – Monte Carlo sample method. Either ‘random’ (default and bounding), or
‘sobol’. If using a different sample method, use ‘random’ here.
Returns:
n – The number of sample points required to meet the target integration
error.