Sensitivity API¶
The sensitivity analysis, what it varies, the quantities of interest it reads from each run, and the base of its methods. Guide: Sensitivity analysis.
SensitivityAnalysis ¶
The forward questions of a model: how uncertainty in its inputs moves its outputs, and which inputs matter most.
A calibration asks which inputs fit the data; an analysis needs no data.
It holds the simulation, what varies (InputSpace), the replicates of a
stochastic engine and the seed of every random number, and every method
of one analysis reads the same inputs. The forward model is built in Rust
once, when the analysis is created: the values of the inputs reach the
engine as a calibration writes them.
Source code in commol/api/sensitivity.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
Attributes¶
rust_analysis
property
¶
The forward analysis built in Rust, for the runners of methods.
Returns:
| Type | Description |
|---|---|
ForwardAnalysisProtocol
|
The forward model and the inputs every method reads. |
seed
property
¶
The seed of the analysis' random numbers.
Returns:
| Type | Description |
|---|---|
int
|
The seed given, or the seed the engine drew when the analysis was built, which it logs. |
Methods:¶
__init__ ¶
__init__(simulation: Simulation, inputs: InputSpace, *, replicates: int | None = None, seed: int | None = None) -> None
Build the analysis of inputs on simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The model to analyse. |
required |
inputs
|
InputSpace
|
What varies. |
required |
replicates
|
int | None
|
For a stochastic engine, required, at least 1: how many replicates each point runs. A point of the design of PRCC, Morris, Sobol or polynomial chaos holds the mean of its replicates, on the same seeds at every point; a propagation keeps every replicate, each with a seed of its own. A deterministic engine does not use it, so the same analysis runs on every engine. |
None
|
seed
|
int | None
|
The seed of the designs and the replicates. Required with a
stochastic engine; otherwise None has the engine draw one, which
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If an input is not a value of the model, the replicates or the
seed do not fit the engine, |
Source code in commol/api/sensitivity.py
rust_predictive ¶
rust_predictive(sample: ParameterSample, positions: list[float]) -> PredictiveProtocol
The run of every draw of sample at positions, for a Predictive:
each replicate of a stochastic engine has a seed of its own, derived
from the seed of the analysis, as in a propagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
ParameterSample
|
The draws, in the order of the inputs. |
required |
positions
|
list[float]
|
Positions to report at, sorted and unique. |
required |
Returns:
| Type | Description |
|---|---|
PredictiveProtocol
|
The runs, computed in Rust. |
Source code in commol/api/sensitivity.py
with_model ¶
with_model(model: Model) -> SensitivityAnalysis
The same analysis on another model, with the same seed.
The draws of a predictive of the copy take the seeds they take here,
so Scenarios runs every scenario on common random numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The model, such as a copy of this one with other parameter values. |
required |
Returns:
| Type | Description |
|---|---|
SensitivityAnalysis
|
An analysis of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an input is not a value of |
Source code in commol/api/sensitivity.py
rust_observation_draws ¶
rust_observation_draws(sample: ParameterSample, observed_data: list[ObservedDataPoint], noise: ObservationNoise) -> ObservationDrawsProtocol
Every draw's value of observed_data, for a Predictive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
ParameterSample
|
The draws, in the order of the inputs. |
required |
observed_data
|
list[ObservedDataPoint]
|
The observations. |
required |
noise
|
NoNoise | ResidualNoise | DistributionNoise
|
The observation noise; only |
required |
Returns:
| Type | Description |
|---|---|
ObservationDrawsProtocol
|
The draws, computed in Rust. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the noise is not |
Source code in commol/api/sensitivity.py
rust_log_score ¶
rust_log_score(sample: ParameterSample, observed_data: list[ObservedDataPoint]) -> list[float]
Refuse the log score, which commol.scores.log_score asks for.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
ParameterSample
|
The draws. |
required |
observed_data
|
list[ObservedDataPoint]
|
The observations. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Always: the log score reads the observation models of a problem, and an analysis has no data. |
Source code in commol/api/sensitivity.py
run ¶
run(method: SensitivityMethod[ResultT]) -> ResultT
Run a sensitivity method on the inputs of this analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
SensitivityMethod[ResultT]
|
The configuration of the method; its type sets the result type. |
required |
Returns:
| Type | Description |
|---|---|
ResultT
|
The method's result. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If the method does not take these inputs, such as a method of independent inputs on inputs from a sample, or a setting, a quantity or the model does not fit the method; the message says why. |
RuntimeError
|
If a run of the design fails. |
InfeasibleStateError
|
If a point of the design leaves the values its model allows. |
Source code in commol/api/sensitivity.py
InputSpace ¶
Bases: BaseModel
What a sensitivity analysis varies.
Each input is a CalibrationParameter, a model parameter or an initial
condition with its bounds, as a calibration sets it. The inputs follow
independent distributions, one per input, truncated to its bounds, or
are the draws of a sample, with their weights; the inputs of a sample may
depend on each other, so only the methods that allow it take one. Build
it with independent, uniform_on_bounds or from_sample.
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
list[CalibrationParameter]
|
The inputs, in order. A factor or a noise parameter is not an input: both belong to observations, and an analysis has none. |
distributions |
dict[str, Distribution] | None
|
The distribution of each input, for independent inputs. |
sample |
ParameterSample | None
|
The draws of the inputs, for inputs from a sample. |
initial_condition_remainder |
str | None
|
The bin or compartment that takes what the initial conditions leave of the sum the model states, as in a calibration problem. |
Source code in commol/context/inference/global_sensitivity.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 | |
Attributes¶
Methods:¶
check_inputs ¶
Check the inputs against the distributions or the sample.
Source code in commol/context/inference/global_sensitivity.py
independent
classmethod
¶
independent(parameters: Sequence[CalibrationParameter], distributions: Mapping[str, Distribution], *, initial_condition_remainder: str | None = None) -> Self
Independent inputs, each with its distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Sequence[CalibrationParameter]
|
The inputs, in order. |
required |
distributions
|
Mapping[str, Distribution]
|
The distribution of each input, truncated to its bounds. |
required |
initial_condition_remainder
|
str | None
|
The bin or compartment that takes what the initial conditions leave. |
None
|
Returns:
| Type | Description |
|---|---|
InputSpace
|
The input space. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an input has no distribution or is a factor, a distribution names no input, or an id repeats. |
Source code in commol/context/inference/global_sensitivity.py
uniform_on_bounds
classmethod
¶
uniform_on_bounds(parameters: Sequence[CalibrationParameter], *, initial_condition_remainder: str | None = None) -> Self
Independent inputs, each uniform on its bounds; they must be finite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Sequence[CalibrationParameter]
|
The inputs, in order. |
required |
initial_condition_remainder
|
str | None
|
The bin or compartment that takes what the initial conditions leave. |
None
|
Returns:
| Type | Description |
|---|---|
InputSpace
|
The input space. |
Source code in commol/context/inference/global_sensitivity.py
from_sample
classmethod
¶
from_sample(sample: ParameterSample, parameters: Sequence[CalibrationParameter], *, initial_condition_remainder: str | None = None) -> Self
The draws of a sample, with their weights, such as a posterior.
Its inputs may depend on each other, so only PRCC and propagation take it. The parameters give the type of each value, which a sample does not hold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
ParameterSample
|
The draws. |
required |
parameters
|
Sequence[CalibrationParameter]
|
The inputs, in the order and with the bounds of the sample. |
required |
initial_condition_remainder
|
str | None
|
The bin or compartment that takes what the initial conditions leave. |
None
|
Returns:
| Type | Description |
|---|---|
InputSpace
|
The input space. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the sample's names or bounds are not the parameters'. |
Source code in commol/context/inference/global_sensitivity.py
rust_distributions ¶
The distributions as the Rust runners read them, or None.
Source code in commol/context/inference/global_sensitivity.py
SensitivityMethod ¶
Bases: InferenceMethod[ResultT], Generic[ResultT]
The configuration of a sensitivity method, whose result is ResultT.
SensitivityAnalysis.run(method) runs it on the inputs of the
analysis, with no data, and returns its result type.
Source code in commol/context/inference/method.py
Propagation ¶
Bases: SensitivityMethod[PropagationResult], RangeChecked
Monte Carlo propagation: run the draws of the inputs and reduce each run to the quantities.
With independent inputs the draws are a Latin hypercube of their distributions; with inputs from a sample, the sample is the design, with its weights.
Attributes:
| Name | Type | Description |
|---|---|---|
draws |
int | None
|
The number of points of the Latin hypercube; required with independent inputs, and left unset with inputs from a sample. |
quantities |
list[Quantity]
|
What each run is reduced to; none gives only the sample, for a
|
Source code in commol/context/inference/global_sensitivity.py
PropagationResult ¶
Bases: ResultModel
The draws of the inputs and what each run gives.
Its sample is a ParameterSample, so Predictive(analysis,
result.sample, positions) gives the bands, plots and reports of the
propagation, as for a calibration.
Attributes:
| Name | Type | Description |
|---|---|---|
sample |
ParameterSample
|
The draws of the inputs: a Latin hypercube of their distributions, or the sample of the input space itself. |
labels |
list[str]
|
The label of each quantity. |
values |
list[list[float]]
|
The quantities of each run, |
weights |
list[float]
|
The weight of each run; with a stochastic engine each replicate has an equal share of its draw's weight. They sum to 1. |
draw_seeds |
list[int]
|
The seed of each draw of |
A quantity that reads a NaN is NaN in `values`, and `summary` raises on |
|
|
it |
`where` keeps the runs a condition chooses, which conditions the
|
|
result on that condition. |
|
Source code in commol/context/inference/global_sensitivity.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
Attributes¶
effective_size
property
¶
Kish's effective size of the weights of the runs, (Σw)²/Σw²: the
number of equally weighted runs that carry as much information.
Methods:¶
where ¶
where(mask: ArrayLike) -> PropagationResult
The runs where mask is true, with their weights renormalised to sum
to 1.
A filter conditions the result: a summary of the runs it keeps is the
distribution of each quantity given the condition of the mask, such
as np.isfinite(values[:, i]) or a compartment above a threshold,
not the distribution over every run. effective_size says how many
runs the kept weights are worth. sample and draw_seeds stay those
of the draws of the inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
ArrayLike
|
One boolean per run, in the order of |
required |
Returns:
| Type | Description |
|---|---|
PropagationResult
|
The kept runs, their values and their renormalised weights. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in commol/context/inference/global_sensitivity.py
summary ¶
summary(confidence_level: float) -> list[QuantitySummary]
The weighted distribution of each quantity across the runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confidence_level
|
float
|
Strictly between 0 and 1. |
required |
Returns:
| Type | Description |
|---|---|
list[QuantitySummary]
|
One summary per quantity, in the order of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the confidence level is not strictly between 0 and 1, or a
quantity is NaN in a run: |
Source code in commol/context/inference/global_sensitivity.py
QuantitySummary ¶
Bases: ResultModel
The weighted distribution of one quantity across the runs of a propagation.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
The quantity. |
confidence_level |
float
|
The level of the central interval. |
mean |
float
|
The weighted mean. |
median |
float
|
The weighted median. |
lower |
float
|
The quantile |
upper |
float
|
The quantile |
Source code in commol/context/inference/global_sensitivity.py
PRCC ¶
Bases: SensitivityMethod[PRCCResult], RangeChecked
Latin hypercube sampling with partial rank correlation coefficients (Marino et al. 2008): how steadily each quantity rises or falls with each input.
With independent inputs the draws are a Latin hypercube of their
distributions; with inputs from a sample, the sample is the design, and
the ranks, the correlations and the test read its weights. A
Trajectory gives the coefficients over the axis.
Attributes:
| Name | Type | Description |
|---|---|---|
draws |
int | None
|
The number of points of the Latin hypercube; required with independent inputs, and left unset with inputs from a sample. |
quantities |
list[Quantity]
|
What each run is reduced to. |
Source code in commol/context/inference/global_sensitivity.py
PRCCResult ¶
Bases: ResultModel
The partial rank correlation of each input with each quantity.
A coefficient near 1 or −1 says the quantity rises or falls steadily with the input once the other inputs are accounted for; near 0, that it does not move steadily with it. The p-value tests the coefficient against 0 with Kish's effective size of the draws.
Attributes:
| Name | Type | Description |
|---|---|---|
sample |
ParameterSample
|
The draws the coefficients come from. |
inputs |
list[str]
|
The inputs, in order. |
labels |
list[str]
|
The label of each quantity. |
series |
list[str]
|
The series of each quantity: its label, or the name of its
|
positions |
list[float | None]
|
The position of each quantity of a |
coefficients |
list[list[float]]
|
The PRCC of each input for each quantity, |
p_values |
list[list[float]]
|
The two-sided p-value of each coefficient, |
effective_size |
float
|
Kish's effective size of the draws: their number with equal weights. |
Source code in commol/context/inference/global_sensitivity.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
Methods:¶
plot ¶
plot(output_file: str | None = None, config: PlotConfig | None = None, x_label: str = 'Step', axes: Figure | None = None) -> Figure
Draw the PRCC of each input: one panel per series.
A series of a Trajectory draws one line per input over its
positions; any other quantity draws one bar per input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_file
|
str | None
|
Path to save the figure to. If None, the figure is only returned. |
None
|
config
|
PlotConfig | None
|
Layout and style. If None, the defaults. |
None
|
x_label
|
str
|
The label of the x axis of a series over positions. |
'Step'
|
axes
|
Figure | None
|
A figure of commol to draw on: each panel is the |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The matplotlib figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ImportError
|
If matplotlib is not installed ( |
Source code in commol/context/inference/global_sensitivity.py
Morris ¶
Bases: SensitivityMethod[MorrisResult], RangeChecked
Morris screening (Morris 1991), with the μ* of Campolongo, Cariboni
and Saltelli (2007): which inputs matter, in few runs.
Each trajectory starts at a random level of every input and moves the inputs one at a time, by half the levels; the levels are the centres of strata of equal probability of each distribution. It needs independent inputs: a step that moves one input breaks the dependence of a sample.
Attributes:
| Name | Type | Description |
|---|---|---|
trajectories |
int
|
The number of trajectories; each runs one more point than there are inputs. |
levels |
int
|
The number of levels of each input; even, at least 2. |
quantities |
list[Quantity]
|
What each run is reduced to. |
Source code in commol/context/inference/global_sensitivity.py
MorrisResult ¶
Bases: ResultModel
The Morris indices of each input for each quantity.
The elementary effects are on the scale of probabilities: a step moves
an input by half the range of F(x), so the indices of inputs of
different units compare. Rank the inputs by mu_star; a sigma near or
above mu_star says the effect of the input depends on the other inputs
or is not linear.
Attributes:
| Name | Type | Description |
|---|---|---|
inputs |
list[str]
|
The inputs, in order. |
labels |
list[str]
|
The label of each quantity. |
mu |
list[list[float]]
|
The mean elementary effect, |
mu_star |
list[list[float]]
|
The mean absolute elementary effect, |
sigma |
list[list[float]]
|
The standard deviation of the elementary effects,
|
runs |
int
|
The number of points run: one more than the inputs per trajectory. |
Source code in commol/context/inference/global_sensitivity.py
Methods:¶
plot ¶
plot(output_file: str | None = None, config: PlotConfig | None = None, axes: Figure | None = None) -> Figure
Draw σ against μ* of each input: one panel per quantity,
one labelled point per input.
An input far to the right matters; one high up acts through interactions or a non-linear effect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_file
|
str | None
|
Path to save the figure to. If None, the figure is only returned. |
None
|
config
|
PlotConfig | None
|
Layout and style. If None, the defaults. |
None
|
axes
|
Figure | None
|
A figure of commol to draw on: each panel is the |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The matplotlib figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ImportError
|
If matplotlib is not installed ( |
Source code in commol/context/inference/global_sensitivity.py
Sobol ¶
Bases: SensitivityMethod[SobolResult], RangeChecked
Sobol indices on the design of Saltelli (2010): first-order indices by the estimator of Saltelli (2010) and total indices by the estimator of Jansen (1999), with intervals from a bootstrap of the rows.
The base matrices hold independent Monte Carlo draws, so the bootstrap intervals are valid. It needs independent inputs: with dependent inputs the indices lose their meaning and no longer add up; PRCC and propagation take a sample.
Attributes:
| Name | Type | Description |
|---|---|---|
draws |
int
|
The rows of each base matrix; the analysis runs
|
replicates |
int
|
The bootstrap replicates of the intervals, at least 2. |
confidence_level |
float
|
The level of the intervals, strictly between 0 and 1. |
quantities |
list[Quantity]
|
What each run is reduced to. |
Source code in commol/context/inference/global_sensitivity.py
SobolResult ¶
Bases: ResultModel
The Sobol indices of each input for each quantity, with their bootstrap intervals.
The first-order index is the share of the variance of the quantity the input explains alone; the total index adds every interaction the input takes part in. A total index near 0 says the input can be fixed; a total index well above the first-order one says the input acts through interactions.
Attributes:
| Name | Type | Description |
|---|---|---|
inputs |
list[str]
|
The inputs, in order. |
labels |
list[str]
|
The label of each quantity. |
confidence_level |
float
|
The level of the intervals. |
first, total |
list[list[float]]
|
The first-order and total indices, |
first_lower, first_upper |
list[list[float]]
|
The ends of the interval of each first-order index; NaN when a
bootstrap replicate of the rows has no variance, which more
|
total_lower, total_upper |
list[list[float]]
|
The ends of the interval of each total index. |
runs |
int
|
The number of points run: |
Source code in commol/context/inference/global_sensitivity.py
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
Methods:¶
plot ¶
plot(output_file: str | None = None, config: PlotConfig | None = None, axes: Figure | None = None) -> Figure
Draw the first-order and total Sobol indices: one panel per quantity, one pair of bars per input, with their intervals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_file
|
str | None
|
Path to save the figure to. If None, the figure is only returned. |
None
|
config
|
PlotConfig | None
|
Layout and style. If None, the defaults. |
None
|
axes
|
Figure | None
|
A figure of commol to draw on: each panel is the |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The matplotlib figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ImportError
|
If matplotlib is not installed ( |
Source code in commol/context/inference/global_sensitivity.py
PolynomialChaos ¶
Bases: SensitivityMethod[ChaosResult], RangeChecked
A polynomial chaos expansion (Sudret 2008): a polynomial surrogate of
each quantity, and the Sobol indices of its coefficients, in far fewer
runs than Sobol when the quantity is smooth.
Every input goes to u = F(x), uniform on [0, 1] through its
distribution, so one basis of orthonormal Legendre polynomials fits every
distribution, truncated ones included. The coefficients come from least
squares on a Latin hypercube; the leave-one-out error says how well the
expansion predicts the model. It needs independent inputs.
The basis keeps every term whose degrees α have
Σ α_i^q ≤ degree^q and that holds at most max_interaction
inputs. The defaults keep the total-degree basis, of
(k + degree)! / (k! degree!) terms in k inputs; a truncation
keeps the terms of low interaction order, so a basis of many inputs
needs far fewer terms and runs. The number of terms is known before any
run.
Attributes:
| Name | Type | Description |
|---|---|---|
degree |
int
|
The degree of the basis: the largest degree of an input in a term,
and the total degree of a term when |
q_norm |
float
|
The q of the hyperbolic truncation, in |
max_interaction |
int | None
|
The largest number of inputs of a term; None for no limit. |
draws |
int
|
The points of the Latin hypercube; more than the terms, and two or three times as many is the usual choice. |
quantities |
list[Quantity]
|
What each run is reduced to. |
Source code in commol/context/inference/global_sensitivity.py
ChaosResult ¶
Bases: ResultModel
A polynomial chaos expansion of each quantity, its accuracy and the Sobol indices of its coefficients.
The expansion is a surrogate of the model: predict gives the
quantities at any values of the inputs inside their bounds, at the cost
of a polynomial. Read
loo_error first: the indices are those of the expansion, and they are
those of the model only as far as the expansion predicts it.
Attributes:
| Name | Type | Description |
|---|---|---|
inputs |
list[str]
|
The inputs, in order. |
input_space |
InputSpace
|
The inputs and their distributions, which |
labels |
list[str]
|
The label of each quantity. |
degree |
int
|
The degree of the basis: the bound of the q-norm of every term. |
q_norm |
float
|
The q of the q-norm of the basis; 1 for the total-degree basis. |
max_interaction |
int | None
|
The largest number of inputs of a term; None for no limit. |
indices |
list[list[int]]
|
The degree of each input in each term, |
coefficients |
list[list[float]]
|
The coefficient of each term for each quantity, |
loo_error |
list[float]
|
The leave-one-out error of each quantity, relative to its variance; NaN for a quantity of no variance. |
mean, variance |
list[float]
|
The mean and the variance of each quantity under the expansion. |
first, total |
list[list[float]]
|
The first-order and total Sobol indices, |
runs |
int
|
The number of points run. |
Source code in commol/context/inference/global_sensitivity.py
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | |
Methods:¶
plot ¶
plot(output_file: str | None = None, config: PlotConfig | None = None, axes: Figure | None = None) -> Figure
Draw the first-order and total Sobol indices of the expansion: one panel per quantity, one pair of bars per input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_file
|
str | None
|
Path to save the figure to. If None, the figure is only returned. |
None
|
config
|
PlotConfig | None
|
Layout and style. If None, the defaults. |
None
|
axes
|
Figure | None
|
A figure of commol to draw on: each panel is the |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The matplotlib figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ImportError
|
If matplotlib is not installed ( |
Source code in commol/context/inference/global_sensitivity.py
predict ¶
The quantities the expansion gives at each set of input values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Sequence[Sequence[float]]
|
One value per input, in the order of |
required |
Returns:
| Type | Description |
|---|---|
list[list[float]]
|
The value of each quantity at each point, |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a point has not one value per input or a value outside the bounds of its input, the truncation is not valid, or the coefficients do not fit the basis. |
Source code in commol/context/inference/global_sensitivity.py
Level ¶
Bases: _Outputs
The level of some outputs: their sum at each position.
A quantity given a name or a list of names reads this series.
Attributes:
| Name | Type | Description |
|---|---|---|
outputs |
list[str]
|
The outputs summed; one name is a list of one. |
Source code in commol/context/inference/quantities.py
Increments ¶
Bases: _Outputs, RangeChecked
The increments of some outputs: at each end, the gain of their sum over
(end - window, end], as an observation with the window window
reads it.
The positions of a quantity of increments are window ends, each at
least window within the rounding of the window (window_start of
crates/commol-calibration/src/observation.rs), so no window starts
before 0.
Attributes:
| Name | Type | Description |
|---|---|---|
outputs |
list[str]
|
The outputs summed; one name is a list of one. |
window |
float
|
The width of each window, above 0. |
Source code in commol/context/inference/quantities.py
Attributes¶
Methods:¶
check_ends ¶
No window starts before 0, with the rule of the engine
(check_window_end of crates/commol-calibration/src/observation.rs).
Raises:
| Type | Description |
|---|---|
ValueError
|
With the message of the engine, if a window starts before 0. |
Source code in commol/context/inference/quantities.py
ValueAt ¶
Bases: _OfSeries, _OneScalar, RangeChecked
The value of a series at a position: the level of the outputs, or their gain over the window that ends there.
Attributes:
| Name | Type | Description |
|---|---|---|
series |
Level | Increments
|
The series read; a name or a list of names is their |
at |
float
|
The position; with |
label |
str | None
|
The name of the quantity in results and plots. If None, a name that says what the quantity reads. |
Source code in commol/context/inference/quantities.py
Gain ¶
Bases: _Outputs, _OneScalar, RangeChecked
The value at end minus the value at start: what entered a cumulative
output over (start, end], as an observation with the window
end - start that starts at exactly start reads it.
Attributes:
| Name | Type | Description |
|---|---|---|
outputs |
list[str]
|
The outputs summed; one name is a list of one. |
start |
float
|
The start of the window. |
end |
float
|
The end of the window, after |
label |
str | None
|
The name of the quantity in results and plots. If None, a name that says what the quantity reads. |
Source code in commol/context/inference/quantities.py
Peak ¶
Bases: _AtPositions, _OneScalar, RangeChecked
The largest value of a series at the positions.
The series decides what the peak is: the peak of Increments(acc,
window=7) at the ends 7, 14, ... is the largest gain of a window of 7,
while the peak of the level of an accumulator, which never falls, is
its value at the last position. A NaN at a position makes the peak NaN.
Attributes:
| Name | Type | Description |
|---|---|---|
series |
Level | Increments
|
The series read; a name or a list of names is their |
positions |
list[float]
|
The positions compared, ascending; with |
label |
str | None
|
The name of the quantity in results and plots. If None, a name that says what the quantity reads. |
Source code in commol/context/inference/quantities.py
PeakPosition ¶
Bases: _AtPositions, _OneScalar, RangeChecked
The first of the positions where the value of a series is largest; NaN when the value at a position is NaN.
Attributes:
| Name | Type | Description |
|---|---|---|
series |
Level | Increments
|
The series read; a name or a list of names is their |
positions |
list[float]
|
The positions compared, ascending; with |
label |
str | None
|
The name of the quantity in results and plots. If None, a name that says what the quantity reads. |
Source code in commol/context/inference/quantities.py
Trajectory ¶
Bases: _AtPositions, RangeChecked
The value of a series at each position: one scalar per position, for an analysis over the axis.
Attributes:
| Name | Type | Description |
|---|---|---|
series |
Level | Increments
|
The series read; a name or a list of names is their |
positions |
list[float]
|
The positions, ascending; with |
label |
str | None
|
The name of the series; each scalar is named after it and its position. |
Source code in commol/context/inference/quantities.py
Ratio ¶
Bases: _OneScalar
The ratio of two quantities of one value each, numerator N over denominator D.
The ratio of a run whose denominator is 0 is NaN, also when the
numerator is not 0, and follows the NaN rule of every method. A method
that reduces the points of a design (PRCC, Morris, Sobol,
PolynomialChaos) reads one value per point; with a stochastic engine,
replicate_rule says how the replicates of a point combine. A Propagation,
the Scenarios and the quantities of one run keep the ratio of each run.
Attributes:
| Name | Type | Description |
|---|---|---|
numerator |
ValueAt | Gain | Peak
|
The quantity divided. |
denominator |
ValueAt | Gain | Peak
|
The quantity it is divided by. |
replicate_rule |
{within, within_positive, pooled}
|
|
label |
str | None
|
The name of the quantity in results and plots. If None, a name that says what the quantity reads. |
Source code in commol/context/inference/quantities.py
Methods:¶
one_value
classmethod
¶
An operand gives one value per run.
Source code in commol/context/inference/quantities.py
default_label ¶
The numerator over the denominator.
rust_json ¶
The ratio as Rust reads it: its JSON, without the labels.
quantity_schedule ¶
The positions a run must report at for quantities to read it.
They are every position a quantity reads and the start of every window,
sorted, each once. A SimulationResults of
Simulation.run_at(quantity_schedule(quantities)) holds them all, so
SimulationResults.quantities reads it; a Propagation runs at the same
positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantities
|
Sequence[Quantity]
|
The quantities. |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
The positions, ascending. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there is no quantity. |