stats-arrays 0.7.dev8__tar.gz → 0.8__tar.gz

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.
Files changed (59) hide show
  1. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/CHANGES.md +6 -0
  2. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/PKG-INFO +6 -3
  3. stats_arrays-0.8/docs/distributions/beta_pert.rst +9 -0
  4. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/index.rst +4 -1
  5. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/pyproject.toml +7 -2
  6. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/__init__.py +7 -5
  7. stats_arrays-0.8/src/stats_arrays/distributions/__init__.py +32 -0
  8. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/base.py +2 -2
  9. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/bernoulli.py +1 -1
  10. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/beta.py +39 -31
  11. stats_arrays-0.8/src/stats_arrays/distributions/beta_pert.py +114 -0
  12. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/discrete_uniform.py +3 -3
  13. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/extreme.py +2 -2
  14. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/gamma.py +2 -2
  15. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/geometric.py +3 -3
  16. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/lognormal.py +3 -3
  17. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/normal.py +3 -3
  18. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/student.py +2 -2
  19. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/undefined.py +2 -2
  20. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/distributions/weibull.py +2 -2
  21. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/random.py +2 -2
  22. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/uncertainty_choices.py +1 -1
  23. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/utils.py +1 -1
  24. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays.egg-info/PKG-INFO +6 -3
  25. stats_arrays-0.8/src/stats_arrays.egg-info/SOURCES.txt +55 -0
  26. stats_arrays-0.7.dev8/stats_arrays/distributions/__init__.py +0 -30
  27. stats_arrays-0.7.dev8/stats_arrays.egg-info/SOURCES.txt +0 -53
  28. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/CODE_OF_CONDUCT.md +0 -0
  29. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/CONTRIBUTING.md +0 -0
  30. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/LICENSE +0 -0
  31. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/MANIFEST.in +0 -0
  32. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/README.md +0 -0
  33. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/base.rst +0 -0
  34. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/bernoulli.rst +0 -0
  35. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/beta.rst +0 -0
  36. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/discrete-uniform.rst +0 -0
  37. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/extreme.rst +0 -0
  38. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/gamma.rst +0 -0
  39. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/lognormal.rst +0 -0
  40. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/normal.rst +0 -0
  41. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/student.rst +0 -0
  42. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/triangular.rst +0 -0
  43. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/uniform.rst +0 -0
  44. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/distributions/weibull.rst +0 -0
  45. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/lhc.rst +0 -0
  46. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/mcrng.rst +0 -0
  47. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/docs/rng.rst +0 -0
  48. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/setup.cfg +0 -0
  49. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/dataset_statistics.py +0 -0
  50. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays/errors.py +0 -0
  51. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays.egg-info/dependency_links.txt +0 -0
  52. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays.egg-info/requires.txt +0 -0
  53. {stats_arrays-0.7.dev8 → stats_arrays-0.8/src}/stats_arrays.egg-info/top_level.txt +0 -0
  54. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/tests/test_base.py +0 -0
  55. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/tests/test_choices.py +0 -0
  56. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/tests/test_conversions.py +0 -0
  57. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/tests/test_lhc.py +0 -0
  58. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/tests/test_mc.py +0 -0
  59. {stats_arrays-0.7.dev8 → stats_arrays-0.8}/tests/test_rng.py +0 -0
@@ -1,5 +1,11 @@
1
1
  # stats_arrays Changelog
2
2
 
3
+ # 0.8 (2025-10-23)
4
+
5
+ * [#19: Add Beta PERT distribution](https://github.com/brightway-lca/stats_arrays/pull/19).
6
+ * Moved to a `src` layout.
7
+ * Switch to absolute imports
8
+
3
9
  # 0.7 (2024-08-19)
4
10
 
5
11
  * Moved to `pyproject.toml` packaging and `pytest` tests
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: stats_arrays
3
- Version: 0.7.dev8
3
+ Version: 0.8
4
4
  Summary: Standard NumPy array interface for defining uncertain parameters
5
5
  Author-email: Chris Mutel <cmutel@gmail.com>
6
6
  Maintainer-email: Chris Mutel <cmutel@gmail.com>
@@ -14,10 +14,12 @@ Classifier: Programming Language :: Python :: 3.9
14
14
  Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
17
19
  Classifier: Natural Language :: English
18
20
  Classifier: Operating System :: OS Independent
19
21
  Classifier: Topic :: Scientific/Engineering
20
- Requires-Python: >=3.6
22
+ Requires-Python: >=3.9
21
23
  Description-Content-Type: text/markdown
22
24
  License-File: LICENSE
23
25
  Requires-Dist: numpy>=1.6.0
@@ -35,6 +37,7 @@ Requires-Dist: pytest; extra == "dev"
35
37
  Requires-Dist: pytest-cov; extra == "dev"
36
38
  Requires-Dist: pytest-randomly; extra == "dev"
37
39
  Requires-Dist: setuptools; extra == "dev"
40
+ Dynamic: license-file
38
41
 
39
42
  The `stats_arrays` package provides a standard NumPy array interface for defining uncertain parameters used in models, and classes for Monte Carlo sampling. It also plays well with others.
40
43
 
@@ -0,0 +1,9 @@
1
+ .. _beta_pert:
2
+
3
+ Beta PERT
4
+ *********
5
+
6
+ .. autoclass:: stats_arrays.BetaPERTUncertainty
7
+ :members:
8
+ :inherited-members:
9
+ :show-inheritance:
@@ -125,6 +125,7 @@ No uncertainty 1 **static value**
125
125
  :ref:`beta` [#]_ 10 :math:`\boldsymbol{\alpha}` :math:`\boldsymbol{\beta}` *lower bound* *upper bound*
126
126
  :ref:`extreme` [#]_ 11 :math:`\boldsymbol{\mu}` :math:`\boldsymbol{\sigma}` :math:`\boldsymbol{\xi}`
127
127
  :ref:`students` [#]_ 12 *median* *scale* :math:`\boldsymbol{\nu}`
128
+ :ref:`beta_pert` [#]_ 13 **mean** *lambda* **minimum** **maximum**
128
129
  ======================= === =========================== ============================= =========================== =============== ===============
129
130
 
130
131
  Items in **bold** are required, items in *italics* are optional.
@@ -147,12 +148,13 @@ Items in **bold** are required, items in *italics* are optional.
147
148
  .. [#] `Beta distribution <https://en.wikipedia.org/wiki/Beta_distribution>`_
148
149
  .. [#] `Extreme value distribution <https://en.wikipedia.org/wiki/Generalized_extreme_value_distribution>`_
149
150
  .. [#] `Student's T distribution <https://en.wikipedia.org/wiki/Student%27s_t-distribution>`_
151
+ .. [#] `Beta PERT distribution <https://en.wikipedia.org/wiki/PERT_distribution>`_
150
152
 
151
153
  Unused columns can be given any value, but it is recommended that they are set to ``np.nan``.
152
154
 
153
155
  .. warning::
154
156
 
155
- Unused optional columns **must** be set to ``np.nan`` to avoid unexpected behaviour!
157
+ Optional columns without data **must** be set to ``np.nan`` to avoid unexpected behaviour!
156
158
 
157
159
  Extending parameter arrays
158
160
  --------------------------
@@ -180,6 +182,7 @@ Probability distributions
180
182
  distributions/student
181
183
  distributions/gamma
182
184
  distributions/weibull
185
+ distributions/beta_pert
183
186
 
184
187
  Random number generators
185
188
  ------------------------
@@ -23,11 +23,13 @@ classifiers = [
23
23
  "Programming Language :: Python :: 3.10",
24
24
  "Programming Language :: Python :: 3.11",
25
25
  "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Programming Language :: Python :: 3.14",
26
28
  "Natural Language :: English",
27
29
  "Operating System :: OS Independent",
28
30
  "Topic :: Scientific/Engineering"
29
31
  ]
30
- requires-python = ">=3.6"
32
+ requires-python = ">=3.9"
31
33
  dependencies = [
32
34
  # dependencies as strings with quotes, e.g. "foo"
33
35
  # You can add version requirements like "foo>2.0"
@@ -62,6 +64,7 @@ dev = [
62
64
  [tool.setuptools]
63
65
  license-files = ["LICENSE"]
64
66
  include-package-data = true
67
+ package-dir = {"" = "src"}
65
68
  packages = [
66
69
  "stats_arrays",
67
70
  "stats_arrays.distributions",
@@ -77,7 +80,8 @@ norecursedirs = [
77
80
  "build",
78
81
  ".tox"
79
82
  ]
80
- testpaths = ["tests/*.py", "tests/distributions/*.py"]
83
+ testpaths = ["tests"]
84
+ pythonpath = ["src"]
81
85
 
82
86
  [tool.flake8]
83
87
  # Some sane defaults for the code style checker flake8
@@ -91,6 +95,7 @@ exclude = [
91
95
  "dist",
92
96
  ".eggs",
93
97
  "docs/conf.py",
98
+ "src/stats_arrays/__pycache__",
94
99
  ]
95
100
 
96
101
  [tool.black]
@@ -1,8 +1,9 @@
1
- __version__ = "0.7.dev8"
1
+ __version__ = "0.8"
2
2
 
3
3
  __all__ = (
4
4
  "BernoulliUncertainty",
5
5
  "BetaUncertainty",
6
+ "BetaPERTUncertainty",
6
7
  "BoundedUncertaintyBase",
7
8
  "DiscreteUniform",
8
9
  "GammaUncertainty",
@@ -30,9 +31,10 @@ __all__ = (
30
31
  "WeibullUncertainty",
31
32
  )
32
33
 
33
- from .distributions import (
34
+ from stats_arrays.distributions import (
34
35
  BernoulliUncertainty,
35
36
  BetaUncertainty,
37
+ BetaPERTUncertainty,
36
38
  BoundedUncertaintyBase,
37
39
  DiscreteUniform,
38
40
  GammaUncertainty,
@@ -47,7 +49,7 @@ from .distributions import (
47
49
  UniformUncertainty,
48
50
  WeibullUncertainty,
49
51
  )
50
- from .errors import (
52
+ from stats_arrays.errors import (
51
53
  ImproperBoundsError,
52
54
  InvalidParamsError,
53
55
  MaximumIterationsError,
@@ -57,5 +59,5 @@ from .errors import (
57
59
  UnknownUncertaintyType,
58
60
  UnreasonableBoundsError,
59
61
  )
60
- from .random import LatinHypercubeRNG, MCRandomNumberGenerator, RandomNumberGenerator
61
- from .uncertainty_choices import uncertainty_choices
62
+ from stats_arrays.random import LatinHypercubeRNG, MCRandomNumberGenerator, RandomNumberGenerator
63
+ from stats_arrays.uncertainty_choices import uncertainty_choices
@@ -0,0 +1,32 @@
1
+ __all__ = (
2
+ "BernoulliUncertainty",
3
+ "BetaUncertainty",
4
+ "BetaPERTUncertainty",
5
+ "BoundedUncertaintyBase",
6
+ "DiscreteUniform",
7
+ "GammaUncertainty",
8
+ "GeneralizedExtremeValueUncertainty",
9
+ "LognormalUncertainty",
10
+ "NormalUncertainty",
11
+ "NoUncertainty",
12
+ "StudentsTUncertainty",
13
+ "TriangularUncertainty",
14
+ "UncertaintyBase",
15
+ "UndefinedUncertainty",
16
+ "UniformUncertainty",
17
+ "WeibullUncertainty",
18
+ )
19
+
20
+ from stats_arrays.distributions.base import BoundedUncertaintyBase, UncertaintyBase
21
+ from stats_arrays.distributions.bernoulli import BernoulliUncertainty
22
+ from stats_arrays.distributions.beta import BetaUncertainty
23
+ from stats_arrays.distributions.discrete_uniform import DiscreteUniform
24
+ from stats_arrays.distributions.extreme import GeneralizedExtremeValueUncertainty
25
+ from stats_arrays.distributions.gamma import GammaUncertainty
26
+ from stats_arrays.distributions.geometric import TriangularUncertainty, UniformUncertainty
27
+ from stats_arrays.distributions.lognormal import LognormalUncertainty
28
+ from stats_arrays.distributions.normal import NormalUncertainty
29
+ from stats_arrays.distributions.student import StudentsTUncertainty
30
+ from stats_arrays.distributions.undefined import NoUncertainty, UndefinedUncertainty
31
+ from stats_arrays.distributions.weibull import WeibullUncertainty
32
+ from stats_arrays.distributions.beta_pert import BetaPERTUncertainty
@@ -2,13 +2,13 @@ from __future__ import division
2
2
 
3
3
  import numpy as np
4
4
 
5
- from ..errors import (
5
+ from stats_arrays.errors import (
6
6
  ImproperBoundsError,
7
7
  InvalidParamsError,
8
8
  MaximumIterationsError,
9
9
  UnreasonableBoundsError,
10
10
  )
11
- from ..utils import construct_params_array, one_row_params_array
11
+ from stats_arrays.utils import construct_params_array, one_row_params_array
12
12
 
13
13
  np.seterr(invalid="ignore")
14
14
 
@@ -2,7 +2,7 @@ from __future__ import division
2
2
 
3
3
  from numpy import array, random, zeros
4
4
 
5
- from .base import BoundedUncertaintyBase
5
+ from stats_arrays.distributions.base import BoundedUncertaintyBase
6
6
 
7
7
 
8
8
  class BernoulliUncertainty(BoundedUncertaintyBase):
@@ -1,11 +1,11 @@
1
1
  from __future__ import division
2
2
 
3
- from numpy import isnan, linspace, random, zeros
3
+ from numpy import isnan, linspace, random, zeros, newaxis
4
4
  from scipy import stats
5
5
 
6
- from ..errors import InvalidParamsError, ImproperBoundsError
7
- from ..utils import one_row_params_array
8
- from .base import UncertaintyBase
6
+ from stats_arrays.errors import InvalidParamsError, ImproperBoundsError
7
+ from stats_arrays.utils import one_row_params_array
8
+ from stats_arrays.distributions.base import UncertaintyBase
9
9
 
10
10
 
11
11
  class BetaUncertainty(UncertaintyBase):
@@ -43,34 +43,38 @@ class BetaUncertainty(UncertaintyBase):
43
43
 
44
44
  @classmethod
45
45
  def _rescale(cls, params, results):
46
- mask = ~isnan(params["minimum"])
47
- params[~mask]["minimum"] = 0
48
- if mask.sum():
49
- results[mask] += params[mask]["minimum"]
50
- mask = ~isnan(params["maximum"])
51
- params[~mask]["maximum"] = 1
52
- if mask.sum():
53
- results[mask] *= params[mask]["maximum"]
46
+ """Rescale results from [0, 1] to [minimum, maximum] range.
47
+
48
+ The correct scaling formula is: results = results * scale + minimum
49
+ where scale = maximum - minimum.
50
+ """
51
+ minimum, scale = cls._minimum_scale(params)
52
+
53
+ # Handle broadcasting for multiple rows
54
+ if results.ndim == 2 and minimum.ndim == 1:
55
+ # results shape: (n_rows, n_samples), minimum/scale shape: (n_rows,)
56
+ results = results * scale[:, newaxis] + minimum[:, newaxis]
57
+ else:
58
+ # Single row case or matching dimensions
59
+ results = results * scale + minimum
60
+
54
61
  return results
55
62
 
56
63
  @classmethod
57
- def _loc_scale(cls, params):
58
- loc = params["minimum"].copy()
59
- loc[isnan(loc)] = 0
64
+ def _minimum_scale(cls, params):
65
+ minimum = params["minimum"].copy()
66
+ minimum[isnan(minimum)] = 0
60
67
  scale = params["maximum"].copy()
61
68
  scale[isnan(scale)] = 1
62
- scale -= loc
63
- return loc, scale
69
+ scale -= minimum
70
+ return minimum, scale
64
71
 
65
72
  @classmethod
66
73
  def random_variables(cls, params, size, seeded_random=None, transform=False):
67
74
  if not seeded_random:
68
75
  seeded_random = random
69
- # scale = params['scale']
70
- # scale[isnan(scale)] = 1
71
76
  return cls._rescale(
72
77
  params,
73
- # scale.reshape((-1, 1)) * seeded_random.beta(
74
78
  seeded_random.beta(
75
79
  params["loc"], params["shape"], size=(size, params.shape[0])
76
80
  ).T,
@@ -80,7 +84,7 @@ class BetaUncertainty(UncertaintyBase):
80
84
  def cdf(cls, params, vector):
81
85
  vector = cls.check_2d_inputs(params, vector)
82
86
  results = zeros(vector.shape)
83
- loc, scale = cls._loc_scale(params)
87
+ loc, scale = cls._minimum_scale(params)
84
88
  for row in range(params.shape[0]):
85
89
  results[row, :] = stats.beta.cdf(
86
90
  vector[row, :],
@@ -95,7 +99,7 @@ class BetaUncertainty(UncertaintyBase):
95
99
  def ppf(cls, params, percentages):
96
100
  percentages = cls.check_2d_inputs(params, percentages)
97
101
  results = zeros(percentages.shape)
98
- loc, scale = cls._loc_scale(params)
102
+ loc, scale = cls._minimum_scale(params)
99
103
  for row in range(percentages.shape[0]):
100
104
  results[row, :] = stats.beta.ppf(
101
105
  percentages[row, :],
@@ -109,17 +113,19 @@ class BetaUncertainty(UncertaintyBase):
109
113
  @classmethod
110
114
  @one_row_params_array
111
115
  def statistics(cls, params):
112
- alpha = float(params["loc"])
113
- beta = float(params["shape"])
114
- loc = 0 if isnan(params["minimum"]) else float(params["minimum"])
115
- scale = 1 if isnan(params["maximum"]) else float(params["maximum"])
116
- # scale = 1 if isnan(params['maximum'])[0] else float(params['maximum'])
116
+ alpha = float(params["loc"][0][0])
117
+ beta = float(params["shape"][0][0])
118
+
119
+ minimum, scale = cls._minimum_scale(params)
120
+ minimum = float(minimum[0][0])
121
+ scale = float(scale[0][0])
122
+
117
123
  if alpha <= 1 or beta <= 1:
118
124
  mode = "Undefined"
119
125
  else:
120
- mode = ((alpha - 1) / (alpha + beta - 2)) * scale + loc
126
+ mode = ((alpha - 1) / (alpha + beta - 2)) * scale + minimum
121
127
  return {
122
- "mean": (alpha / (alpha + beta)) * scale + loc,
128
+ "mean": (alpha / (alpha + beta)) * scale + minimum,
123
129
  "mode": mode,
124
130
  "median": "Not Implemented",
125
131
  "lower": "Not Implemented",
@@ -129,8 +135,10 @@ class BetaUncertainty(UncertaintyBase):
129
135
  @classmethod
130
136
  @one_row_params_array
131
137
  def pdf(cls, params, xs=None):
132
- loc = 0 if isnan(params["minimum"]) else float(params["minimum"])
133
- scale = 1 if isnan(params["scale"])[0] else float(params["scale"])
138
+ loc, scale = cls._minimum_scale(params)
139
+ loc = float(loc[0][0])
140
+ scale = float(scale[0][0])
141
+
134
142
  if xs is None:
135
143
  xs = linspace(loc, loc + scale, cls.default_number_points_in_pdf)
136
144
  ys = stats.beta.pdf(xs, params["loc"], params["shape"], loc=loc, scale=scale)
@@ -0,0 +1,114 @@
1
+ from typing import Optional
2
+ from numpy import isnan, ndarray, nan, random
3
+
4
+ from stats_arrays.distributions.beta import BetaUncertainty
5
+ from stats_arrays.errors import InvalidParamsError, ImproperBoundsError
6
+ from stats_arrays.utils import one_row_params_array
7
+
8
+
9
+ class BetaPERTUncertainty(BetaUncertainty):
10
+ """
11
+ The Beta PERT distribution is a particular form of the Beta distribution which takes these input parameters:
12
+
13
+ #. ``minimum``: ``A``, the minimum value
14
+ #. ``loc``: ``B``, the mean value
15
+ #. ``maximum``: ``C``, the maximum value
16
+ #. ``shape``: ``:math:`\\lambda```, the optional shape parameter
17
+
18
+ The standard default shape parameter is 4, though according to Wikipedia values from 2 to 3.5 are commonly used. A higher value makes the distribution more concentrated on the mean value.
19
+
20
+ Wikipedia: `Beta PERT distribution <https://en.wikipedia.org/wiki/PERT_distribution>`_
21
+ """
22
+
23
+ id = 13
24
+ description = "Beta PERT uncertainty"
25
+
26
+ @classmethod
27
+ def validate(cls, params):
28
+ if isnan(params["minimum"]).sum():
29
+ raise InvalidParamsError(
30
+ "Real, positive `A` values are required for Beta PERT uncertainties."
31
+ )
32
+ if isnan(params["loc"]).sum():
33
+ raise InvalidParamsError(
34
+ "Real, positive `B` values are required for Beta PERT uncertainties."
35
+ )
36
+ if isnan(params["maximum"]).sum():
37
+ raise InvalidParamsError(
38
+ "Real, positive `C` values are required for Beta PERT uncertainties."
39
+ )
40
+ if (params["minimum"] > params["loc"]).sum() or (
41
+ params["loc"] > params["maximum"]
42
+ ).sum():
43
+ raise ImproperBoundsError("`A <= B <= C` not respected.")
44
+ if (params["minimum"] == params["maximum"]).sum():
45
+ raise ImproperBoundsError("`A` and `C` have the same values.")
46
+ # Check lambda values where they are provided (not NaN)
47
+ provided_lambda = params[~isnan(params["scale"])]
48
+ if (provided_lambda["scale"] <= 0).sum():
49
+ raise InvalidParamsError("Lambda values must be greater than zero.")
50
+
51
+ @classmethod
52
+ def _as_beta(cls, params: ndarray, default_lambda: float = 4.0) -> ndarray:
53
+ """Calculate α and β values for Beta distribution from PERT A/B/C inputs."""
54
+ beta = params.copy()
55
+ # Use provided lambda values or default
56
+ lambda_values = params["scale"].copy()
57
+ missing_lambda_mask = isnan(lambda_values)
58
+ lambda_values[missing_lambda_mask] = default_lambda
59
+
60
+ a, b, c = params["minimum"], params["loc"], params["maximum"]
61
+ # Set Beta distribution parameters
62
+ beta["scale"] = nan
63
+ beta["loc"] = 1 + lambda_values * ((b - a) / (c - a)) # alpha
64
+ beta["shape"] = 1 + lambda_values * ((c - b) / (c - a)) # beta
65
+ # Set minimum and maximum for scaling from [0, 1] to [A, C]
66
+ beta["minimum"] = a
67
+ beta["maximum"] = c
68
+ return beta
69
+
70
+ @classmethod
71
+ def random_variables(
72
+ cls,
73
+ params: ndarray,
74
+ size: int,
75
+ seeded_random: Optional[random.RandomState] = None,
76
+ transform: bool = False,
77
+ default_lambda: float = 4.0,
78
+ ):
79
+ return BetaUncertainty.random_variables(
80
+ params=cls._as_beta(params=params, default_lambda=default_lambda),
81
+ size=size,
82
+ seeded_random=seeded_random,
83
+ transform=transform,
84
+ )
85
+
86
+ @classmethod
87
+ def cdf(cls, params: ndarray, vector: ndarray, default_lambda: float = 4.0):
88
+ return BetaUncertainty.cdf(
89
+ params=cls._as_beta(params=params, default_lambda=default_lambda),
90
+ vector=vector,
91
+ )
92
+
93
+ @classmethod
94
+ def ppf(cls, params: ndarray, percentages: ndarray, default_lambda: float = 4.0):
95
+ return BetaUncertainty.ppf(
96
+ params=cls._as_beta(params=params, default_lambda=default_lambda),
97
+ percentages=percentages,
98
+ )
99
+
100
+ @classmethod
101
+ @one_row_params_array
102
+ def statistics(cls, params: ndarray, default_lambda: float = 4.0):
103
+ return BetaUncertainty.statistics(
104
+ params=cls._as_beta(params=params, default_lambda=default_lambda)
105
+ )
106
+
107
+ @classmethod
108
+ @one_row_params_array
109
+ def pdf(
110
+ cls, params: ndarray, xs: Optional[ndarray] = None, default_lambda: float = 4.0
111
+ ):
112
+ return BetaUncertainty.pdf(
113
+ params=cls._as_beta(params=params, default_lambda=default_lambda), xs=xs
114
+ )
@@ -2,9 +2,9 @@
2
2
  import numpy as np
3
3
  from scipy import stats
4
4
 
5
- from ..errors import ImproperBoundsError, InvalidParamsError
6
- from ..utils import one_row_params_array
7
- from .base import UncertaintyBase
5
+ from stats_arrays.errors import ImproperBoundsError, InvalidParamsError
6
+ from stats_arrays.utils import one_row_params_array
7
+ from stats_arrays.distributions.base import UncertaintyBase
8
8
 
9
9
 
10
10
  class DiscreteUniform(UncertaintyBase):
@@ -2,8 +2,8 @@ from __future__ import division
2
2
 
3
3
  import numpy as np
4
4
 
5
- from ..errors import InvalidParamsError
6
- from .base import UncertaintyBase
5
+ from stats_arrays.errors import InvalidParamsError
6
+ from stats_arrays.distributions.base import UncertaintyBase
7
7
 
8
8
 
9
9
  class GeneralizedExtremeValueUncertainty(UncertaintyBase):
@@ -2,8 +2,8 @@ from __future__ import division
2
2
 
3
3
  import numpy as np
4
4
 
5
- from ..errors import InvalidParamsError
6
- from .base import UncertaintyBase
5
+ from stats_arrays.errors import InvalidParamsError
6
+ from stats_arrays.distributions.base import UncertaintyBase
7
7
 
8
8
 
9
9
  class GammaUncertainty(UncertaintyBase):
@@ -3,9 +3,9 @@ from __future__ import division
3
3
  import numpy as np
4
4
  from scipy import stats
5
5
 
6
- from ..errors import ImproperBoundsError
7
- from ..utils import one_row_params_array
8
- from .base import BoundedUncertaintyBase
6
+ from stats_arrays.errors import ImproperBoundsError
7
+ from stats_arrays.utils import one_row_params_array
8
+ from stats_arrays.distributions.base import BoundedUncertaintyBase
9
9
 
10
10
 
11
11
  class UniformUncertainty(BoundedUncertaintyBase):
@@ -3,9 +3,9 @@ from __future__ import division
3
3
  import numpy as np
4
4
  from scipy import stats
5
5
 
6
- from ..errors import InvalidParamsError
7
- from ..utils import one_row_params_array
8
- from .base import UncertaintyBase
6
+ from stats_arrays.errors import InvalidParamsError
7
+ from stats_arrays.utils import one_row_params_array
8
+ from stats_arrays.distributions.base import UncertaintyBase
9
9
 
10
10
 
11
11
  class LognormalUncertainty(UncertaintyBase):
@@ -3,9 +3,9 @@ from __future__ import division
3
3
  import numpy as np
4
4
  from scipy import stats
5
5
 
6
- from ..errors import InvalidParamsError
7
- from ..utils import one_row_params_array
8
- from .base import UncertaintyBase
6
+ from stats_arrays.errors import InvalidParamsError
7
+ from stats_arrays.utils import one_row_params_array
8
+ from stats_arrays.distributions.base import UncertaintyBase
9
9
 
10
10
 
11
11
  class NormalUncertainty(UncertaintyBase):
@@ -2,8 +2,8 @@ from __future__ import division
2
2
 
3
3
  import numpy as np
4
4
 
5
- from ..errors import InvalidParamsError
6
- from .base import UncertaintyBase
5
+ from stats_arrays.errors import InvalidParamsError
6
+ from stats_arrays.distributions.base import UncertaintyBase
7
7
 
8
8
 
9
9
  class StudentsTUncertainty(UncertaintyBase):
@@ -2,8 +2,8 @@ from __future__ import division
2
2
 
3
3
  from numpy import repeat, tile
4
4
 
5
- from ..errors import UndefinedDistributionError
6
- from .base import UncertaintyBase
5
+ from stats_arrays.errors import UndefinedDistributionError
6
+ from stats_arrays.distributions.base import UncertaintyBase
7
7
 
8
8
 
9
9
  class UndefinedUncertainty(UncertaintyBase):
@@ -2,8 +2,8 @@ from __future__ import division
2
2
 
3
3
  import numpy as np
4
4
 
5
- from ..errors import InvalidParamsError
6
- from .base import UncertaintyBase
5
+ from stats_arrays.errors import InvalidParamsError
6
+ from stats_arrays.distributions.base import UncertaintyBase
7
7
 
8
8
 
9
9
  class WeibullUncertainty(UncertaintyBase):
@@ -1,7 +1,7 @@
1
1
  import numpy as np
2
2
 
3
- from .errors import UnknownUncertaintyType
4
- from .uncertainty_choices import uncertainty_choices
3
+ from stats_arrays.errors import UnknownUncertaintyType
4
+ from stats_arrays.uncertainty_choices import uncertainty_choices
5
5
 
6
6
  try:
7
7
  from collections.abc import Iterable
@@ -1,6 +1,6 @@
1
1
  import warnings
2
2
 
3
- from .distributions import (
3
+ from stats_arrays.distributions import (
4
4
  BernoulliUncertainty,
5
5
  BetaUncertainty,
6
6
  DiscreteUniform,
@@ -2,7 +2,7 @@ from functools import wraps
2
2
 
3
3
  import numpy as np
4
4
 
5
- from .errors import MultipleRowParamsArrayError
5
+ from stats_arrays.errors import MultipleRowParamsArrayError
6
6
 
7
7
  BASE_DTYPE = [
8
8
  ("loc", np.float64),
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: stats_arrays
3
- Version: 0.7.dev8
3
+ Version: 0.8
4
4
  Summary: Standard NumPy array interface for defining uncertain parameters
5
5
  Author-email: Chris Mutel <cmutel@gmail.com>
6
6
  Maintainer-email: Chris Mutel <cmutel@gmail.com>
@@ -14,10 +14,12 @@ Classifier: Programming Language :: Python :: 3.9
14
14
  Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
17
19
  Classifier: Natural Language :: English
18
20
  Classifier: Operating System :: OS Independent
19
21
  Classifier: Topic :: Scientific/Engineering
20
- Requires-Python: >=3.6
22
+ Requires-Python: >=3.9
21
23
  Description-Content-Type: text/markdown
22
24
  License-File: LICENSE
23
25
  Requires-Dist: numpy>=1.6.0
@@ -35,6 +37,7 @@ Requires-Dist: pytest; extra == "dev"
35
37
  Requires-Dist: pytest-cov; extra == "dev"
36
38
  Requires-Dist: pytest-randomly; extra == "dev"
37
39
  Requires-Dist: setuptools; extra == "dev"
40
+ Dynamic: license-file
38
41
 
39
42
  The `stats_arrays` package provides a standard NumPy array interface for defining uncertain parameters used in models, and classes for Monte Carlo sampling. It also plays well with others.
40
43
 
@@ -0,0 +1,55 @@
1
+ CHANGES.md
2
+ CODE_OF_CONDUCT.md
3
+ CONTRIBUTING.md
4
+ LICENSE
5
+ MANIFEST.in
6
+ README.md
7
+ pyproject.toml
8
+ docs/index.rst
9
+ docs/lhc.rst
10
+ docs/mcrng.rst
11
+ docs/rng.rst
12
+ docs/distributions/base.rst
13
+ docs/distributions/bernoulli.rst
14
+ docs/distributions/beta.rst
15
+ docs/distributions/beta_pert.rst
16
+ docs/distributions/discrete-uniform.rst
17
+ docs/distributions/extreme.rst
18
+ docs/distributions/gamma.rst
19
+ docs/distributions/lognormal.rst
20
+ docs/distributions/normal.rst
21
+ docs/distributions/student.rst
22
+ docs/distributions/triangular.rst
23
+ docs/distributions/uniform.rst
24
+ docs/distributions/weibull.rst
25
+ src/stats_arrays/__init__.py
26
+ src/stats_arrays/dataset_statistics.py
27
+ src/stats_arrays/errors.py
28
+ src/stats_arrays/random.py
29
+ src/stats_arrays/uncertainty_choices.py
30
+ src/stats_arrays/utils.py
31
+ src/stats_arrays.egg-info/PKG-INFO
32
+ src/stats_arrays.egg-info/SOURCES.txt
33
+ src/stats_arrays.egg-info/dependency_links.txt
34
+ src/stats_arrays.egg-info/requires.txt
35
+ src/stats_arrays.egg-info/top_level.txt
36
+ src/stats_arrays/distributions/__init__.py
37
+ src/stats_arrays/distributions/base.py
38
+ src/stats_arrays/distributions/bernoulli.py
39
+ src/stats_arrays/distributions/beta.py
40
+ src/stats_arrays/distributions/beta_pert.py
41
+ src/stats_arrays/distributions/discrete_uniform.py
42
+ src/stats_arrays/distributions/extreme.py
43
+ src/stats_arrays/distributions/gamma.py
44
+ src/stats_arrays/distributions/geometric.py
45
+ src/stats_arrays/distributions/lognormal.py
46
+ src/stats_arrays/distributions/normal.py
47
+ src/stats_arrays/distributions/student.py
48
+ src/stats_arrays/distributions/undefined.py
49
+ src/stats_arrays/distributions/weibull.py
50
+ tests/test_base.py
51
+ tests/test_choices.py
52
+ tests/test_conversions.py
53
+ tests/test_lhc.py
54
+ tests/test_mc.py
55
+ tests/test_rng.py
@@ -1,30 +0,0 @@
1
- __all__ = (
2
- "BernoulliUncertainty",
3
- "BetaUncertainty",
4
- "BoundedUncertaintyBase",
5
- "DiscreteUniform",
6
- "GammaUncertainty",
7
- "GeneralizedExtremeValueUncertainty",
8
- "LognormalUncertainty",
9
- "NormalUncertainty",
10
- "NoUncertainty",
11
- "StudentsTUncertainty",
12
- "TriangularUncertainty",
13
- "UncertaintyBase",
14
- "UndefinedUncertainty",
15
- "UniformUncertainty",
16
- "WeibullUncertainty",
17
- )
18
-
19
- from .base import BoundedUncertaintyBase, UncertaintyBase
20
- from .bernoulli import BernoulliUncertainty
21
- from .beta import BetaUncertainty
22
- from .discrete_uniform import DiscreteUniform
23
- from .extreme import GeneralizedExtremeValueUncertainty
24
- from .gamma import GammaUncertainty
25
- from .geometric import TriangularUncertainty, UniformUncertainty
26
- from .lognormal import LognormalUncertainty
27
- from .normal import NormalUncertainty
28
- from .student import StudentsTUncertainty
29
- from .undefined import NoUncertainty, UndefinedUncertainty
30
- from .weibull import WeibullUncertainty
@@ -1,53 +0,0 @@
1
- CHANGES.md
2
- CODE_OF_CONDUCT.md
3
- CONTRIBUTING.md
4
- LICENSE
5
- MANIFEST.in
6
- README.md
7
- pyproject.toml
8
- docs/index.rst
9
- docs/lhc.rst
10
- docs/mcrng.rst
11
- docs/rng.rst
12
- docs/distributions/base.rst
13
- docs/distributions/bernoulli.rst
14
- docs/distributions/beta.rst
15
- docs/distributions/discrete-uniform.rst
16
- docs/distributions/extreme.rst
17
- docs/distributions/gamma.rst
18
- docs/distributions/lognormal.rst
19
- docs/distributions/normal.rst
20
- docs/distributions/student.rst
21
- docs/distributions/triangular.rst
22
- docs/distributions/uniform.rst
23
- docs/distributions/weibull.rst
24
- stats_arrays/__init__.py
25
- stats_arrays/dataset_statistics.py
26
- stats_arrays/errors.py
27
- stats_arrays/random.py
28
- stats_arrays/uncertainty_choices.py
29
- stats_arrays/utils.py
30
- stats_arrays.egg-info/PKG-INFO
31
- stats_arrays.egg-info/SOURCES.txt
32
- stats_arrays.egg-info/dependency_links.txt
33
- stats_arrays.egg-info/requires.txt
34
- stats_arrays.egg-info/top_level.txt
35
- stats_arrays/distributions/__init__.py
36
- stats_arrays/distributions/base.py
37
- stats_arrays/distributions/bernoulli.py
38
- stats_arrays/distributions/beta.py
39
- stats_arrays/distributions/discrete_uniform.py
40
- stats_arrays/distributions/extreme.py
41
- stats_arrays/distributions/gamma.py
42
- stats_arrays/distributions/geometric.py
43
- stats_arrays/distributions/lognormal.py
44
- stats_arrays/distributions/normal.py
45
- stats_arrays/distributions/student.py
46
- stats_arrays/distributions/undefined.py
47
- stats_arrays/distributions/weibull.py
48
- tests/test_base.py
49
- tests/test_choices.py
50
- tests/test_conversions.py
51
- tests/test_lhc.py
52
- tests/test_mc.py
53
- tests/test_rng.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes