Monte Carlo¶
Uncertainty and sensitivity analysis via Monte Carlo simulation. Wrap any motor parameter with MonteCarloParameter to assign a statistical distribution (normal or uniform) and spread. MonteCarloSimulation then generates N randomized scenarios, runs the internal ballistics for each, and provides statistical aggregates (mean, std, percentiles, skew, kurtosis) over the results.
Useful for characterizing thrust variability, pressure envelope, and impulse confidence intervals due to manufacturing tolerances and propellant batch variation.
machwave.montecarlo
¶
MonteCarloParameter
dataclass
¶
Bases: float
Float value annotated with a distribution and spread for sampling.
Source code in machwave/montecarlo/base.py
random_generator
property
¶
Return a generator that samples from this parameter's distribution.
__new__(value, *, spread=0.0, distribution='normal')
¶
Construct a parameter with a center value, spread, and distribution.
Source code in machwave/montecarlo/base.py
__repr__()
¶
Return a debugging representation of the parameter.
MonteCarloSimulation
¶
Monte Carlo driver that runs scenarios and stores their results.
Stores parameters and simulation type, executes the configured number of
scenarios, and delegates plotting to plot_service.py.
Source code in machwave/montecarlo/base.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
__init__(parameters, number_of_scenarios, simulation)
¶
Initialize a Monte Carlo driver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
list[Any]
|
Input parameters for a simulation class. |
required |
number_of_scenarios
|
int
|
Number of scenarios to simulate. |
required |
simulation
|
type[InternalBallisticsSimulation]
|
Simulation class reference. |
required |
Source code in machwave/montecarlo/base.py
generate_scenario()
¶
Generates a Monte Carlo scenario in the form of a list of parameters.
Source code in machwave/montecarlo/base.py
get_property_stats(property_name)
¶
Return descriptive statistics for a scalar property across results.
Metrics returned: mean, median, variance, std_dev, mode, skew (Fisher, unbiased), kurtosis (excess, unbiased), p5 (5th percentile), p95 (95th percentile).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name
|
str
|
Attribute name on the |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Mapping of metric name to value. |
Source code in machwave/montecarlo/base.py
plot_cdf(property_name, x_axes_title='x', **plotly_kwargs)
¶
Plot the empirical CDF of a scalar property across all results.
Source code in machwave/montecarlo/base.py
plot_histogram(property_name, x_axes_title='x', **plotly_kwargs)
¶
Plot a histogram of a scalar property across all results.
Source code in machwave/montecarlo/base.py
plot_histogram_with_kde(property_name, x_axes_title='x', nbins=30, kde_points=200, **plotly_kwargs)
¶
Plot a histogram of a scalar property with a KDE overlay.
Source code in machwave/montecarlo/base.py
plot_time_series_extremes(time_property, series_property, x_axes_title='time', title=None, **plotly_kwargs)
¶
Plot min and max envelopes of a time series across all results.
Source code in machwave/montecarlo/base.py
retrieve_values_from_result(property_name)
¶
Retrieve a scalar property across every Monte Carlo result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name
|
str
|
Attribute name on the |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of length |
Source code in machwave/montecarlo/base.py
run()
¶
Executes number_of_scenarios runs of the underlying Simulation.