pynumerics 2.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pynumerics/__init__.py +73 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.LICENSE.txt +27 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.dll +0 -0
- pynumerics/_bin/Numerics.dll +0 -0
- pynumerics/_bin/pynumerics.runtimeconfig.json +15 -0
- pynumerics/_coverage.py +3825 -0
- pynumerics/_util.py +237 -0
- pynumerics/_version.py +40 -0
- pynumerics/bootstrap.py +593 -0
- pynumerics/callbacks.py +791 -0
- pynumerics/copulas.py +910 -0
- pynumerics/data.py +2233 -0
- pynumerics/differentiation.py +348 -0
- pynumerics/distributions.py +4043 -0
- pynumerics/download.py +623 -0
- pynumerics/enums.py +119 -0
- pynumerics/errors.py +245 -0
- pynumerics/functions.py +1142 -0
- pynumerics/goodness_of_fit.py +699 -0
- pynumerics/graphs.py +556 -0
- pynumerics/hypothesis_tests.py +445 -0
- pynumerics/identity.py +144 -0
- pynumerics/integration.py +677 -0
- pynumerics/linalg.py +1408 -0
- pynumerics/machine_learning.py +1335 -0
- pynumerics/marshal.py +733 -0
- pynumerics/mathematics.py +1053 -0
- pynumerics/mcmc.py +1406 -0
- pynumerics/multivariate.py +1539 -0
- pynumerics/ode.py +156 -0
- pynumerics/optimization.py +1736 -0
- pynumerics/probability.py +966 -0
- pynumerics/py.typed +0 -0
- pynumerics/regional.py +522 -0
- pynumerics/roots.py +274 -0
- pynumerics/runtime.py +384 -0
- pynumerics/sampling.py +1758 -0
- pynumerics/special.py +1079 -0
- pynumerics/statistics.py +1958 -0
- pynumerics/timeseries.py +1326 -0
- pynumerics-2.3.0.dist-info/METADATA +142 -0
- pynumerics-2.3.0.dist-info/RECORD +46 -0
- pynumerics-2.3.0.dist-info/WHEEL +5 -0
- pynumerics-2.3.0.dist-info/licenses/LICENSE +10 -0
- pynumerics-2.3.0.dist-info/top_level.txt +1 -0
pynumerics/bootstrap.py
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
"""Uncertainty analysis from ``Numerics.Distributions``: ensembles and the parametric bootstrap.
|
|
2
|
+
|
|
3
|
+
:class:`UncertaintyAnalysisResults` wraps the ensemble summaries (Type-7 percentile
|
|
4
|
+
bands, the expected-probability curve, the mode curve); :class:`BootstrapAnalysis`
|
|
5
|
+
wraps the parametric resample-and-refit bootstrap of one distribution.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Sequence
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
|
|
15
|
+
from pynumerics._util import _nd, net_enum
|
|
16
|
+
from pynumerics.distributions import UnivariateDistribution, _net_property, _parse_xml, wrap
|
|
17
|
+
from pynumerics.enums import EstimationMethod
|
|
18
|
+
from pynumerics.errors import translate_public
|
|
19
|
+
from pynumerics.marshal import _parameter_set_arrays, to_net_doubles, to_numpy_doubles, to_numpy_matrix
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _members(distributions: Any) -> Any:
|
|
23
|
+
"""Build a ``UnivariateDistributionBase[]``; None entries stay null (Numerics treats them as missing).
|
|
24
|
+
|
|
25
|
+
A .NET array (for example from ``UnivariateDistribution.parameter_set_distributions``) is passed
|
|
26
|
+
through unchanged.
|
|
27
|
+
"""
|
|
28
|
+
nd = _nd()
|
|
29
|
+
import clr # noqa: PLC0415
|
|
30
|
+
import System # noqa: PLC0415
|
|
31
|
+
|
|
32
|
+
if isinstance(distributions, System.Array) and clr.GetClrType(nd.UnivariateDistributionBase).IsAssignableFrom(
|
|
33
|
+
distributions.GetType().GetElementType()):
|
|
34
|
+
return distributions
|
|
35
|
+
return System.Array[nd.UnivariateDistributionBase]([None if d is None else d.net for d in distributions])
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class UncertaintyAnalysisResults:
|
|
39
|
+
"""Ensemble summaries (``Numerics.Distributions.UncertaintyAnalysisResults``).
|
|
40
|
+
|
|
41
|
+
Construct empty and call the ``process_*`` members, or use :meth:`from_ensemble`
|
|
42
|
+
for the full constructor. Probabilities are non-exceedance probabilities.
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
net : Numerics.Distributions.UncertaintyAnalysisResults, optional
|
|
47
|
+
An existing .NET results object to wrap; None, the default, creates an empty one.
|
|
48
|
+
|
|
49
|
+
Attributes
|
|
50
|
+
----------
|
|
51
|
+
net : Numerics.Distributions.UncertaintyAnalysisResults
|
|
52
|
+
The wrapped .NET object.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def __init__(self, net: Any = None) -> None:
|
|
56
|
+
self.net = _nd().UncertaintyAnalysisResults() if net is None else net
|
|
57
|
+
|
|
58
|
+
@classmethod
|
|
59
|
+
def from_ensemble(cls, parent: UnivariateDistribution, sampled: Sequence[UnivariateDistribution | None],
|
|
60
|
+
probabilities: Any, alpha: float = 0.1, min_probability: float = 0.001,
|
|
61
|
+
max_probability: float = 1 - 1e-9,
|
|
62
|
+
record_parameter_sets: bool = False) -> UncertaintyAnalysisResults:
|
|
63
|
+
"""Run the full constructor: mode curve, confidence intervals and mean curve.
|
|
64
|
+
|
|
65
|
+
Parameters
|
|
66
|
+
----------
|
|
67
|
+
parent : UnivariateDistribution
|
|
68
|
+
The point-estimate distribution (mode curve).
|
|
69
|
+
sampled : sequence of UnivariateDistribution or System.Array
|
|
70
|
+
Ensemble members; None (null) members are missing.
|
|
71
|
+
probabilities : array_like
|
|
72
|
+
Non-exceedance probabilities at which to summarize.
|
|
73
|
+
alpha : float, optional
|
|
74
|
+
Two-sided band level; the band is [α/2, 1 − α/2]; default 0.1.
|
|
75
|
+
min_probability, max_probability : float, optional
|
|
76
|
+
Range of the mean-curve value grid.
|
|
77
|
+
record_parameter_sets : bool, optional
|
|
78
|
+
Store the members' parameter sets; default False.
|
|
79
|
+
|
|
80
|
+
Returns
|
|
81
|
+
-------
|
|
82
|
+
UncertaintyAnalysisResults
|
|
83
|
+
The populated results.
|
|
84
|
+
"""
|
|
85
|
+
net = _nd().UncertaintyAnalysisResults(parent.net, _members(sampled), to_net_doubles(probabilities),
|
|
86
|
+
float(alpha), float(min_probability), float(max_probability),
|
|
87
|
+
bool(record_parameter_sets))
|
|
88
|
+
return cls(net)
|
|
89
|
+
|
|
90
|
+
def process_mode_curve(self, parent: UnivariateDistribution, probabilities: Any) -> np.ndarray:
|
|
91
|
+
"""Compute the mode curve ``parent.InverseCDF(probabilities)`` (``ProcessModeCurve``).
|
|
92
|
+
|
|
93
|
+
Parameters
|
|
94
|
+
----------
|
|
95
|
+
parent : UnivariateDistribution
|
|
96
|
+
The point-estimate distribution.
|
|
97
|
+
probabilities : array_like
|
|
98
|
+
Non-exceedance probabilities.
|
|
99
|
+
|
|
100
|
+
Returns
|
|
101
|
+
-------
|
|
102
|
+
numpy.ndarray
|
|
103
|
+
The mode curve.
|
|
104
|
+
"""
|
|
105
|
+
self.net.ProcessModeCurve(parent.net, to_net_doubles(probabilities))
|
|
106
|
+
return self.mode_curve
|
|
107
|
+
|
|
108
|
+
def process_confidence_intervals(self, sampled: Sequence[UnivariateDistribution | None], probabilities: Any,
|
|
109
|
+
alpha: float = 0.1) -> np.ndarray:
|
|
110
|
+
"""Compute the Type-7 percentile band of member quantiles (``ProcessConfidenceIntervals``).
|
|
111
|
+
|
|
112
|
+
Non-finite member quantiles are dropped before the percentiles.
|
|
113
|
+
|
|
114
|
+
Parameters
|
|
115
|
+
----------
|
|
116
|
+
sampled : sequence of UnivariateDistribution or System.Array
|
|
117
|
+
Ensemble members; None (null) members are missing.
|
|
118
|
+
probabilities : array_like
|
|
119
|
+
Non-exceedance probabilities.
|
|
120
|
+
alpha : float, optional
|
|
121
|
+
Two-sided band level; default 0.1.
|
|
122
|
+
|
|
123
|
+
Returns
|
|
124
|
+
-------
|
|
125
|
+
numpy.ndarray
|
|
126
|
+
Array of shape ``(len(probabilities), 2)``: lower and upper limits.
|
|
127
|
+
"""
|
|
128
|
+
self.net.ProcessConfidenceIntervals(_members(sampled), to_net_doubles(probabilities), float(alpha))
|
|
129
|
+
return self.confidence_intervals
|
|
130
|
+
|
|
131
|
+
def process_mean_curve(self, sampled: Sequence[UnivariateDistribution | None], probabilities: Any,
|
|
132
|
+
min_probability: float = 0.001, max_probability: float = 1 - 1e-9,
|
|
133
|
+
weights: Any = None) -> np.ndarray:
|
|
134
|
+
"""Compute the expected-probability curve E[F] (``ProcessMeanCurve``).
|
|
135
|
+
|
|
136
|
+
Parameters
|
|
137
|
+
----------
|
|
138
|
+
sampled : sequence of UnivariateDistribution or System.Array
|
|
139
|
+
Ensemble members; None (null) members are missing.
|
|
140
|
+
probabilities : array_like
|
|
141
|
+
Non-exceedance probabilities at which the curve is read.
|
|
142
|
+
min_probability, max_probability : float, optional
|
|
143
|
+
Range of the value grid.
|
|
144
|
+
weights : array_like, optional
|
|
145
|
+
Non-negative member weights (for example logic-tree branch weights), one per
|
|
146
|
+
member; the weighted overload averages ``sum(w F) / sum(w)``. Equal weights give
|
|
147
|
+
bitwise the unweighted curve. Default None, the unweighted mean.
|
|
148
|
+
|
|
149
|
+
Returns
|
|
150
|
+
-------
|
|
151
|
+
numpy.ndarray
|
|
152
|
+
The mean curve.
|
|
153
|
+
"""
|
|
154
|
+
if weights is None:
|
|
155
|
+
self.net.ProcessMeanCurve(_members(sampled), to_net_doubles(probabilities), float(min_probability),
|
|
156
|
+
float(max_probability))
|
|
157
|
+
else:
|
|
158
|
+
self.net.ProcessMeanCurve(_members(sampled), to_net_doubles(probabilities), to_net_doubles(weights),
|
|
159
|
+
float(min_probability), float(max_probability))
|
|
160
|
+
return self.mean_curve
|
|
161
|
+
|
|
162
|
+
@property
|
|
163
|
+
def confidence_intervals(self) -> np.ndarray | None:
|
|
164
|
+
"""The band, shape ``(n, 2)``."""
|
|
165
|
+
ci = self.net.ConfidenceIntervals
|
|
166
|
+
return None if ci is None else to_numpy_matrix(ci)
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def mean_curve(self) -> np.ndarray | None:
|
|
170
|
+
"""The expected-probability curve."""
|
|
171
|
+
curve = self.net.MeanCurve
|
|
172
|
+
return None if curve is None else to_numpy_doubles(curve)
|
|
173
|
+
|
|
174
|
+
@property
|
|
175
|
+
def mode_curve(self) -> np.ndarray | None:
|
|
176
|
+
"""The mode curve."""
|
|
177
|
+
curve = self.net.ModeCurve
|
|
178
|
+
return None if curve is None else to_numpy_doubles(curve)
|
|
179
|
+
|
|
180
|
+
aic = _net_property("AIC", "The Akaike information criterion of the parent fit (``AIC``); settable.")
|
|
181
|
+
bic = _net_property("BIC", "The Bayesian information criterion of the parent fit (``BIC``); settable.")
|
|
182
|
+
dic = _net_property("DIC", "The deviance information criterion (``DIC``); settable.")
|
|
183
|
+
rmse = _net_property("RMSE", "The root mean square error of the parent fit (``RMSE``); settable.")
|
|
184
|
+
erl = _net_property("ERL", "The effective record length (``ERL``); settable.")
|
|
185
|
+
|
|
186
|
+
@property
|
|
187
|
+
def parent_distribution(self) -> UnivariateDistribution | None:
|
|
188
|
+
"""The point-estimate distribution, wrapped (``ParentDistribution``); settable."""
|
|
189
|
+
parent = self.net.ParentDistribution
|
|
190
|
+
return None if parent is None else wrap(parent)
|
|
191
|
+
|
|
192
|
+
@parent_distribution.setter
|
|
193
|
+
def parent_distribution(self, value: UnivariateDistribution | None) -> None:
|
|
194
|
+
self.net.ParentDistribution = None if value is None else value.net
|
|
195
|
+
|
|
196
|
+
@property
|
|
197
|
+
def parameter_sets(self) -> tuple[np.ndarray, np.ndarray, np.ndarray] | None:
|
|
198
|
+
"""The recorded member parameter sets as ``(values, fitness, weight)`` (``ParameterSets``), or None.
|
|
199
|
+
|
|
200
|
+
``values`` has one row per member (NaN for a missing member); ``fitness`` and ``weight`` hold
|
|
201
|
+
one entry per member.
|
|
202
|
+
"""
|
|
203
|
+
sets = self.net.ParameterSets
|
|
204
|
+
return None if sets is None else _parameter_set_arrays(sets)
|
|
205
|
+
|
|
206
|
+
def process_parameter_sets(self, sampled: Sequence[UnivariateDistribution | None]) -> None:
|
|
207
|
+
"""Record the members' parameter sets (``ProcessParameterSets``).
|
|
208
|
+
|
|
209
|
+
Parameters
|
|
210
|
+
----------
|
|
211
|
+
sampled : sequence of UnivariateDistribution or System.Array
|
|
212
|
+
Ensemble members; None (null) members are recorded as NaN rows.
|
|
213
|
+
"""
|
|
214
|
+
self.net.ProcessParameterSets(_members(sampled))
|
|
215
|
+
|
|
216
|
+
def to_bytes(self) -> bytes:
|
|
217
|
+
"""Serialize the results as Numerics does (``ToByteArray``, UTF-8 JSON).
|
|
218
|
+
|
|
219
|
+
Returns
|
|
220
|
+
-------
|
|
221
|
+
bytes
|
|
222
|
+
The serialized results; :meth:`from_bytes` reads them back.
|
|
223
|
+
"""
|
|
224
|
+
return bytes(_nd().UncertaintyAnalysisResults.ToByteArray(self.net))
|
|
225
|
+
|
|
226
|
+
@classmethod
|
|
227
|
+
def from_bytes(cls, data: bytes) -> UncertaintyAnalysisResults:
|
|
228
|
+
"""Read results serialized by :meth:`to_bytes` (``FromByteArray``).
|
|
229
|
+
|
|
230
|
+
Parameters
|
|
231
|
+
----------
|
|
232
|
+
data : bytes
|
|
233
|
+
The serialized results.
|
|
234
|
+
|
|
235
|
+
Returns
|
|
236
|
+
-------
|
|
237
|
+
UncertaintyAnalysisResults
|
|
238
|
+
The results.
|
|
239
|
+
"""
|
|
240
|
+
nd = _nd()
|
|
241
|
+
import System # noqa: PLC0415 - the runtime is running (_nd started it)
|
|
242
|
+
|
|
243
|
+
return cls(nd.UncertaintyAnalysisResults.FromByteArray(System.Array[System.Byte](bytes(data))))
|
|
244
|
+
|
|
245
|
+
def to_xml(self) -> str:
|
|
246
|
+
"""Return the results as XML text (``ToXElement``).
|
|
247
|
+
|
|
248
|
+
Returns
|
|
249
|
+
-------
|
|
250
|
+
str
|
|
251
|
+
The element as .NET writes it.
|
|
252
|
+
"""
|
|
253
|
+
return str(self.net.ToXElement().ToString())
|
|
254
|
+
|
|
255
|
+
@classmethod
|
|
256
|
+
def from_xml(cls, xml: str) -> UncertaintyAnalysisResults:
|
|
257
|
+
"""Read results written by :meth:`to_xml` (``FromXElement``).
|
|
258
|
+
|
|
259
|
+
Parameters
|
|
260
|
+
----------
|
|
261
|
+
xml : str
|
|
262
|
+
The element as text.
|
|
263
|
+
|
|
264
|
+
Returns
|
|
265
|
+
-------
|
|
266
|
+
UncertaintyAnalysisResults
|
|
267
|
+
The results.
|
|
268
|
+
"""
|
|
269
|
+
return cls(_nd().UncertaintyAnalysisResults.FromXElement(_parse_xml(xml)))
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
class BootstrapAnalysis:
|
|
273
|
+
"""Parametric bootstrap of one distribution (``Numerics.Distributions.BootstrapAnalysis``).
|
|
274
|
+
|
|
275
|
+
Parameters
|
|
276
|
+
----------
|
|
277
|
+
distribution : UnivariateDistribution
|
|
278
|
+
The parent distribution; it must support bootstrapping (``IBootstrappable``).
|
|
279
|
+
method : EstimationMethod or str
|
|
280
|
+
Refit method for each replicate.
|
|
281
|
+
sample_size : int
|
|
282
|
+
Size of each resampled data set.
|
|
283
|
+
replications : int, optional
|
|
284
|
+
Number of replicates; default 10,000.
|
|
285
|
+
seed : int, optional
|
|
286
|
+
Seed; default 12345.
|
|
287
|
+
|
|
288
|
+
Attributes
|
|
289
|
+
----------
|
|
290
|
+
net : Numerics.Distributions.BootstrapAnalysis
|
|
291
|
+
The wrapped .NET object.
|
|
292
|
+
"""
|
|
293
|
+
|
|
294
|
+
def __init__(self, distribution: UnivariateDistribution, method: EstimationMethod | str, sample_size: int,
|
|
295
|
+
replications: int = 10000, seed: int = 12345) -> None:
|
|
296
|
+
nd = _nd()
|
|
297
|
+
self.net = nd.BootstrapAnalysis(distribution.net, net_enum(nd.ParameterEstimationMethod, method),
|
|
298
|
+
int(sample_size), int(replications), int(seed))
|
|
299
|
+
self._distributions: Any = None
|
|
300
|
+
|
|
301
|
+
@property
|
|
302
|
+
def failed_replications(self) -> int:
|
|
303
|
+
"""Replicates whose refit failed (set after :meth:`distributions`)."""
|
|
304
|
+
return int(self.net.FailedReplications)
|
|
305
|
+
|
|
306
|
+
def _net_distributions(self) -> Any:
|
|
307
|
+
"""Return the cached .NET replicate array, computing it once."""
|
|
308
|
+
if self._distributions is None:
|
|
309
|
+
self._distributions = self.net.Distributions()
|
|
310
|
+
return self._distributions
|
|
311
|
+
|
|
312
|
+
def members(self) -> Any:
|
|
313
|
+
"""Run (once) and return the replicates as a ``UnivariateDistributionBase[]`` with nulls for failures.
|
|
314
|
+
|
|
315
|
+
The array stays on the .NET side, ready for the members that take one (for example
|
|
316
|
+
``UncertaintyAnalysisResults.from_ensemble``), so a large ensemble is never wrapped
|
|
317
|
+
replicate by replicate in Python.
|
|
318
|
+
|
|
319
|
+
Returns
|
|
320
|
+
-------
|
|
321
|
+
System.Array[Numerics.Distributions.UnivariateDistributionBase]
|
|
322
|
+
One fitted replicate per replication; null where the refit failed.
|
|
323
|
+
"""
|
|
324
|
+
nd = _nd()
|
|
325
|
+
import System # noqa: PLC0415
|
|
326
|
+
|
|
327
|
+
replicates = self._net_distributions()
|
|
328
|
+
members = System.Array.CreateInstance(nd.UnivariateDistributionBase, len(replicates))
|
|
329
|
+
for index, replicate in enumerate(replicates):
|
|
330
|
+
if replicate is not None:
|
|
331
|
+
members[index] = getattr(replicate, "__implementation__", replicate)
|
|
332
|
+
return members
|
|
333
|
+
|
|
334
|
+
def parameters(self) -> np.ndarray:
|
|
335
|
+
"""Run (once) and return the replicates' parameters (``Parameters``), NaN rows for failures.
|
|
336
|
+
|
|
337
|
+
Returns
|
|
338
|
+
-------
|
|
339
|
+
numpy.ndarray
|
|
340
|
+
Array of shape ``(replications, number_of_parameters)``.
|
|
341
|
+
"""
|
|
342
|
+
return to_numpy_matrix(self.net.Parameters(self._net_distributions()))
|
|
343
|
+
|
|
344
|
+
def distributions(self) -> list[UnivariateDistribution | None]:
|
|
345
|
+
"""Run (once) and return the bootstrap replicate distributions (``Distributions``).
|
|
346
|
+
|
|
347
|
+
Returns
|
|
348
|
+
-------
|
|
349
|
+
list of UnivariateDistribution or None
|
|
350
|
+
One fitted distribution per replicate; None where the refit failed.
|
|
351
|
+
"""
|
|
352
|
+
return [None if d is None else wrap(d) for d in self._net_distributions()]
|
|
353
|
+
|
|
354
|
+
def quantiles(self, probabilities: Any) -> np.ndarray:
|
|
355
|
+
"""Return replicate quantiles (``Quantiles``).
|
|
356
|
+
|
|
357
|
+
Parameters
|
|
358
|
+
----------
|
|
359
|
+
probabilities : array_like
|
|
360
|
+
Non-exceedance probabilities.
|
|
361
|
+
|
|
362
|
+
Returns
|
|
363
|
+
-------
|
|
364
|
+
numpy.ndarray
|
|
365
|
+
Array of shape ``(replications, len(probabilities))``.
|
|
366
|
+
"""
|
|
367
|
+
return to_numpy_matrix(self.net.Quantiles(to_net_doubles(probabilities), self._net_distributions()))
|
|
368
|
+
|
|
369
|
+
def percentile_quantile_ci(self, probabilities: Any, alpha: float = 0.1) -> np.ndarray:
|
|
370
|
+
"""Return percentile confidence intervals of quantiles (``PercentileQuantileCI``).
|
|
371
|
+
|
|
372
|
+
Parameters
|
|
373
|
+
----------
|
|
374
|
+
probabilities : array_like
|
|
375
|
+
Non-exceedance probabilities.
|
|
376
|
+
alpha : float, optional
|
|
377
|
+
Two-sided level; default 0.1.
|
|
378
|
+
|
|
379
|
+
Returns
|
|
380
|
+
-------
|
|
381
|
+
numpy.ndarray
|
|
382
|
+
Array of shape ``(len(probabilities), 2)``.
|
|
383
|
+
"""
|
|
384
|
+
return to_numpy_matrix(self.net.PercentileQuantileCI(to_net_doubles(probabilities), float(alpha),
|
|
385
|
+
self._net_distributions()))
|
|
386
|
+
|
|
387
|
+
def expected_probabilities(self, quantiles: Any) -> np.ndarray:
|
|
388
|
+
"""Return the mean replicate CDF at given values (``ExpectedProbabilities``).
|
|
389
|
+
|
|
390
|
+
Parameters
|
|
391
|
+
----------
|
|
392
|
+
quantiles : array_like
|
|
393
|
+
Values at which the replicate CDFs are averaged.
|
|
394
|
+
|
|
395
|
+
Returns
|
|
396
|
+
-------
|
|
397
|
+
numpy.ndarray
|
|
398
|
+
Expected non-exceedance probabilities.
|
|
399
|
+
"""
|
|
400
|
+
return to_numpy_doubles(self.net.ExpectedProbabilities(to_net_doubles(quantiles), self._net_distributions()))
|
|
401
|
+
|
|
402
|
+
@property
|
|
403
|
+
def distribution(self) -> UnivariateDistribution:
|
|
404
|
+
"""The parent distribution, wrapped (``Distribution``)."""
|
|
405
|
+
return wrap(self.net.Distribution)
|
|
406
|
+
|
|
407
|
+
@property
|
|
408
|
+
def estimation_method(self) -> str:
|
|
409
|
+
"""The refit method name (``EstimationMethod``)."""
|
|
410
|
+
return str(self.net.EstimationMethod)
|
|
411
|
+
|
|
412
|
+
@property
|
|
413
|
+
def sample_size(self) -> int:
|
|
414
|
+
"""The size of each resampled data set (``SampleSize``)."""
|
|
415
|
+
return int(self.net.SampleSize)
|
|
416
|
+
|
|
417
|
+
@property
|
|
418
|
+
def replications(self) -> int:
|
|
419
|
+
"""The number of replicates (``Replications``)."""
|
|
420
|
+
return int(self.net.Replications)
|
|
421
|
+
|
|
422
|
+
@property
|
|
423
|
+
def prng_seed(self) -> int:
|
|
424
|
+
"""The seed of the replicate seeds (``PRNGSeed``)."""
|
|
425
|
+
return int(self.net.PRNGSeed)
|
|
426
|
+
|
|
427
|
+
def parameter_sets(self) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
|
428
|
+
"""Run (once) and return the replicate parameter sets as ``(values, fitness, weight)`` (``ParameterSets``).
|
|
429
|
+
|
|
430
|
+
Returns
|
|
431
|
+
-------
|
|
432
|
+
values : numpy.ndarray
|
|
433
|
+
Array of shape ``(replications, number_of_parameters)``; NaN rows for failed refits.
|
|
434
|
+
fitness : numpy.ndarray
|
|
435
|
+
One entry per replicate (NaN: the bootstrap records none).
|
|
436
|
+
weight : numpy.ndarray
|
|
437
|
+
One entry per replicate.
|
|
438
|
+
"""
|
|
439
|
+
return _parameter_set_arrays(self.net.ParameterSets(self._net_distributions()))
|
|
440
|
+
|
|
441
|
+
def product_moments(self) -> np.ndarray:
|
|
442
|
+
"""Return the product moments of every resampled data set (``ProductMoments``).
|
|
443
|
+
|
|
444
|
+
Returns
|
|
445
|
+
-------
|
|
446
|
+
numpy.ndarray
|
|
447
|
+
Array of shape ``(replications, 4)``: mean, standard deviation, skewness, kurtosis.
|
|
448
|
+
"""
|
|
449
|
+
return to_numpy_matrix(self.net.ProductMoments())
|
|
450
|
+
|
|
451
|
+
def linear_moments(self) -> np.ndarray:
|
|
452
|
+
"""Return the L-moments of every resampled data set (``LinearMoments``).
|
|
453
|
+
|
|
454
|
+
Returns
|
|
455
|
+
-------
|
|
456
|
+
numpy.ndarray
|
|
457
|
+
Array of shape ``(replications, 4)``: λ1, λ2, τ3, τ4.
|
|
458
|
+
"""
|
|
459
|
+
return to_numpy_matrix(self.net.LinearMoments())
|
|
460
|
+
|
|
461
|
+
def probabilities(self, quantiles: Any) -> np.ndarray:
|
|
462
|
+
"""Return every replicate CDF at given values (``Probabilities``).
|
|
463
|
+
|
|
464
|
+
Parameters
|
|
465
|
+
----------
|
|
466
|
+
quantiles : array_like
|
|
467
|
+
Values at which the replicate CDFs are evaluated.
|
|
468
|
+
|
|
469
|
+
Returns
|
|
470
|
+
-------
|
|
471
|
+
numpy.ndarray
|
|
472
|
+
Array of shape ``(replications, len(quantiles))``.
|
|
473
|
+
"""
|
|
474
|
+
return to_numpy_matrix(self.net.Probabilities(to_net_doubles(quantiles), self._net_distributions()))
|
|
475
|
+
|
|
476
|
+
def compute_min_max_quantiles(self, min_probability: float, max_probability: float) -> tuple[float, float]:
|
|
477
|
+
"""Return the smallest and largest replicate quantiles at two probabilities (``ComputeMinMaxQuantiles``).
|
|
478
|
+
|
|
479
|
+
Parameters
|
|
480
|
+
----------
|
|
481
|
+
min_probability : float
|
|
482
|
+
The probability of the lower quantile.
|
|
483
|
+
max_probability : float
|
|
484
|
+
The probability of the upper quantile.
|
|
485
|
+
|
|
486
|
+
Returns
|
|
487
|
+
-------
|
|
488
|
+
tuple of float
|
|
489
|
+
The minimum over replicates of ``InverseCDF(min_probability)`` and the maximum of
|
|
490
|
+
``InverseCDF(max_probability)``.
|
|
491
|
+
"""
|
|
492
|
+
values = self.net.ComputeMinMaxQuantiles(float(min_probability), float(max_probability),
|
|
493
|
+
self._net_distributions())
|
|
494
|
+
return float(values[0]), float(values[1])
|
|
495
|
+
|
|
496
|
+
def bias_corrected_quantile_ci(self, probabilities: Any, alpha: float = 0.1) -> np.ndarray:
|
|
497
|
+
"""Return bias-corrected percentile confidence intervals of quantiles (``BiasCorrectedQuantileCI``).
|
|
498
|
+
|
|
499
|
+
Parameters
|
|
500
|
+
----------
|
|
501
|
+
probabilities : array_like
|
|
502
|
+
Non-exceedance probabilities.
|
|
503
|
+
alpha : float, optional
|
|
504
|
+
Two-sided level; default 0.1.
|
|
505
|
+
|
|
506
|
+
Returns
|
|
507
|
+
-------
|
|
508
|
+
numpy.ndarray
|
|
509
|
+
Array of shape ``(len(probabilities), 2)``.
|
|
510
|
+
"""
|
|
511
|
+
return to_numpy_matrix(self.net.BiasCorrectedQuantileCI(to_net_doubles(probabilities), float(alpha),
|
|
512
|
+
self._net_distributions()))
|
|
513
|
+
|
|
514
|
+
def normal_quantile_ci(self, probabilities: Any, alpha: float = 0.1) -> np.ndarray:
|
|
515
|
+
"""Return normal-approximation confidence intervals of quantiles (``NormalQuantileCI``).
|
|
516
|
+
|
|
517
|
+
Parameters
|
|
518
|
+
----------
|
|
519
|
+
probabilities : array_like
|
|
520
|
+
Non-exceedance probabilities.
|
|
521
|
+
alpha : float, optional
|
|
522
|
+
Two-sided level; default 0.1.
|
|
523
|
+
|
|
524
|
+
Returns
|
|
525
|
+
-------
|
|
526
|
+
numpy.ndarray
|
|
527
|
+
Array of shape ``(len(probabilities), 2)``.
|
|
528
|
+
"""
|
|
529
|
+
return to_numpy_matrix(self.net.NormalQuantileCI(to_net_doubles(probabilities), float(alpha),
|
|
530
|
+
self._net_distributions()))
|
|
531
|
+
|
|
532
|
+
def bca_quantile_ci(self, sample: Any, probabilities: Any, alpha: float = 0.1) -> np.ndarray:
|
|
533
|
+
"""Return bias-corrected and accelerated confidence intervals of quantiles (``BCaQuantileCI``).
|
|
534
|
+
|
|
535
|
+
Parameters
|
|
536
|
+
----------
|
|
537
|
+
sample : array_like
|
|
538
|
+
The observed data (for the jackknife acceleration).
|
|
539
|
+
probabilities : array_like
|
|
540
|
+
Non-exceedance probabilities.
|
|
541
|
+
alpha : float, optional
|
|
542
|
+
Two-sided level; default 0.1.
|
|
543
|
+
|
|
544
|
+
Returns
|
|
545
|
+
-------
|
|
546
|
+
numpy.ndarray
|
|
547
|
+
Array of shape ``(len(probabilities), 2)``.
|
|
548
|
+
"""
|
|
549
|
+
return to_numpy_matrix(self.net.BCaQuantileCI(to_net_doubles(sample), to_net_doubles(probabilities),
|
|
550
|
+
float(alpha)))
|
|
551
|
+
|
|
552
|
+
def bootstrap_t_quantile_ci(self, probabilities: Any, alpha: float = 0.1) -> np.ndarray:
|
|
553
|
+
"""Return bootstrap-t confidence intervals of quantiles (``BootstrapTQuantileCI``).
|
|
554
|
+
|
|
555
|
+
Parameters
|
|
556
|
+
----------
|
|
557
|
+
probabilities : array_like
|
|
558
|
+
Non-exceedance probabilities.
|
|
559
|
+
alpha : float, optional
|
|
560
|
+
Two-sided level; default 0.1.
|
|
561
|
+
|
|
562
|
+
Returns
|
|
563
|
+
-------
|
|
564
|
+
numpy.ndarray
|
|
565
|
+
Array of shape ``(len(probabilities), 2)``.
|
|
566
|
+
"""
|
|
567
|
+
return to_numpy_matrix(self.net.BootstrapTQuantileCI(to_net_doubles(probabilities), float(alpha)))
|
|
568
|
+
|
|
569
|
+
def estimate(self, probabilities: Any, alpha: float = 0.1,
|
|
570
|
+
record_parameter_sets: bool = True) -> UncertaintyAnalysisResults:
|
|
571
|
+
"""Summarize the bootstrap ensemble (``Estimate``).
|
|
572
|
+
|
|
573
|
+
Parameters
|
|
574
|
+
----------
|
|
575
|
+
probabilities : array_like
|
|
576
|
+
Non-exceedance probabilities.
|
|
577
|
+
alpha : float, optional
|
|
578
|
+
Two-sided level; default 0.1.
|
|
579
|
+
record_parameter_sets : bool, optional
|
|
580
|
+
Store the replicate parameter sets; default True.
|
|
581
|
+
|
|
582
|
+
Returns
|
|
583
|
+
-------
|
|
584
|
+
UncertaintyAnalysisResults
|
|
585
|
+
Mode curve, band and mean curve.
|
|
586
|
+
"""
|
|
587
|
+
return UncertaintyAnalysisResults(self.net.Estimate(to_net_doubles(probabilities), float(alpha),
|
|
588
|
+
self._net_distributions(), bool(record_parameter_sets)))
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
__all__ = ["BootstrapAnalysis", "UncertaintyAnalysisResults"]
|
|
592
|
+
|
|
593
|
+
translate_public(globals())
|