Skip to content

Commit 9be9d7e

Browse files
output_dimension is now property of UQTestFunBareABC
Introduce the `output_dimension` property for UQ test functions and update related tests and documentations. Furthermore, the high-level function `list_functions()` is updated to display additional information related to output dimension and parameterization in grid format. This commit should resolve Issue #345.
1 parent 8341d92 commit 9be9d7e

File tree

13 files changed

+407
-217
lines changed

13 files changed

+407
-217
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- `output_dimension` is now property of `UQTestFunBareABC` and inherited to
13+
all concrete classes of UQ test functions.
1214
- Printing a test function instance now shows whether the function is
1315
parameterized or not.
1416
- The information related to the parameterization of a function is now
@@ -23,6 +25,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2325

2426
### Changed
2527

28+
- `list_functions()` is now printed in grid format and include information
29+
regarding the output dimension and the parameterization. Furthermore,
30+
filtering can be done based on the input dimension, output dimension,
31+
tag, and parameterization.
2632
- The class `UnivDist` has been renamed to `Marginal`. The name more clearly
2733
refers to one-dimensional marginal distributions (of a univariate random
2834
variable), which form a `ProbInput`.

README.md

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,23 @@ To list the available functions:
3333
```python-repl
3434
>>> import uqtestfuns as uqtf
3535
>>> uqtf.list_functions()
36-
No. Constructor Dimension Application Description
37-
----- ----------------------------- ----------- -------------------------------------- ----------------------------------------------------------------------------
38-
1 Ackley() M optimization, metamodeling Optimization test function from Ackley (1987)
39-
2 Alemazkoor2D() 2 metamodeling Two-dimensional high-degree polynomial from Alemazkoor & Meidani (2018)
40-
3 Borehole() 8 metamodeling, sensitivity Borehole function from Harper and Gupta (1983)
41-
4 Bratley1992a() M integration, sensitivity Integration test function #1 from Bratley et al. (1992)
42-
5 Bratley1992b() M integration, sensitivity Integration test function #2 from Bratley et al. (1992)
43-
6 Bratley1992c() M integration, sensitivity Integration test function #3 from Bratley et al. (1992)
44-
7 Bratley1992d() M integration, sensitivity Integration test function #4 from Bratley et al. (1992)
45-
8 CantileverBeam2D() 2 reliability Cantilever beam reliability problem from Rajashekhar and Ellington (1993)
46-
9 CircularPipeCrack() 2 reliability Circular pipe under bending moment from Verma et al. (2015)
36+
+-------+-------------------------------+-----------+------------+----------+---------------+--------------------------------+
37+
| No. | Constructor | # Input | # Output | Param. | Application | Description |
38+
+=======+===============================+===========+============+==========+===============+================================+
39+
| 1 | Ackley() | M | 1 | True | optimization, | Optimization test function |
40+
| | | | | | metamodeling | from Ackley (1987) |
41+
+-------+-------------------------------+-----------+------------+----------+---------------+--------------------------------+
42+
| 2 | Alemazkoor20D() | 20 | 1 | False | metamodeling | High-dimensional low-degree |
43+
| | | | | | | polynomial from Alemazkoor & |
44+
| | | | | | | Meidani (2018) |
45+
+-------+-------------------------------+-----------+------------+----------+---------------+--------------------------------+
46+
| 3 | Alemazkoor2D() | 2 | 1 | False | metamodeling | Low-dimensional high-degree |
47+
| | | | | | | polynomial from Alemazkoor & |
48+
| | | | | | | Meidani (2018) |
49+
+-------+-------------------------------+-----------+------------+----------+---------------+--------------------------------+
50+
| 4 | Borehole() | 8 | 1 | False | metamodeling, | Borehole function from Harper |
51+
| | | | | | sensitivity | and Gupta (1983) |
52+
+-------+-------------------------------+-----------+------------+----------+---------------+--------------------------------+
4753
...
4854
```
4955

@@ -53,33 +59,35 @@ and sensitivity analysis purposes; to create an instance of this test function:
5359
```python-repl
5460
>>> my_testfun = uqtf.Borehole()
5561
>>> print(my_testfun)
56-
Name : Borehole
57-
Spatial dimension : 8
58-
Description : Borehole function from Harper and Gupta (1983)
62+
Function ID : Borehole
63+
Input Dimension : 8
64+
Output Dimension : 1
65+
Parameterized : False
66+
Description : Borehole function from Harper and Gupta (1983)
5967
```
6068

6169
The probabilistic input specification of this test function is built-in:
6270

6371
```python-repl
6472
>>> print(my_testfun.prob_input)
65-
Name : Borehole-Harper-1983
66-
Spatial Dim. : 8
67-
Description : Probabilistic input model of the Borehole model from Harper and Gupta (1983).
68-
Marginals :
73+
Name : Borehole-Harper-1983
74+
Input Dimension : 8
75+
Description : Probabilistic input model of the Borehole model from
76+
Harper and Gupta (1983).
77+
Marginals :
6978
70-
No. Name Distribution Parameters Description
71-
79+
No. Name Distribution Parameters Description
7280
----- ------ -------------- --------------------- -----------------------------------------------
73-
1 rw normal [0.1 0.0161812] radius of the borehole [m]
74-
2 r lognormal [7.71 1.0056] radius of influence [m]
75-
3 Tu uniform [ 63070. 115600.] transmissivity of upper aquifer [m^2/year]
76-
4 Hu uniform [ 990. 1100.] potentiometric head of upper aquifer [m]
77-
5 Tl uniform [ 63.1 116. ] transmissivity of lower aquifer [m^2/year]
78-
6 Hl uniform [700. 820.] potentiometric head of lower aquifer [m]
79-
7 L uniform [1120. 1680.] length of the borehole [m]
80-
8 Kw uniform [ 9985. 12045.] hydraulic conductivity of the borehole [m/year]
81-
82-
Copulas : None
81+
1 rw normal [0.1 0.0161812] radius of the borehole [m]
82+
2 r lognormal [7.71 1.0056] radius of influence [m]
83+
3 Tu uniform [ 63070. 115600.] transmissivity of upper aquifer [m^2/year]
84+
4 Hu uniform [ 990. 1100.] potentiometric head of upper aquifer [m]
85+
5 Tl uniform [ 63.1 116. ] transmissivity of lower aquifer [m^2/year]
86+
6 Hl uniform [700. 820.] potentiometric head of lower aquifer [m]
87+
7 L uniform [1120. 1680.] length of the borehole [m]
88+
8 Kw uniform [ 9985. 12045.] hydraulic conductivity of the borehole [m/year]
89+
90+
Copulas : None
8391
```
8492

8593
A sample of input values can be generated from the input model:

docs/fundamentals/integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ using the ``tag`` parameter:
3535
3636
import uqtestfuns as uqtf
3737
38-
uqtf.list_functions(tag="integration")
38+
uqtf.list_functions(tag="integration", tablefmt="html")
3939
```

docs/fundamentals/metamodeling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ using the ``tag`` parameter:
5858
5959
import uqtestfuns as uqtf
6060
61-
uqtf.list_functions(tag="metamodeling")
61+
uqtf.list_functions(tag="metamodeling", tablefmt="html")
6262
```

docs/fundamentals/optimization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ using the ``tag`` parameter:
3131
3232
import uqtestfuns as uqtf
3333
34-
uqtf.list_functions(tag="optimization")
34+
uqtf.list_functions(tag="optimization", tablefmt="html")
3535
```

docs/fundamentals/reliability.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ using the ``tag`` parameter:
3939
4040
import uqtestfuns as uqtf
4141
42-
uqtf.list_functions(tag="reliability")
42+
uqtf.list_functions(tag="reliability", tablefmt="html")
4343
```
4444

4545
## About reliability analysis

docs/fundamentals/sensitivity.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ using the ``tag`` parameter:
4545
4646
import uqtestfuns as uqtf
4747
48-
uqtf.list_functions(tag="sensitivity")
48+
uqtf.list_functions(tag="sensitivity", tablefmt="html")
4949
```

src/uqtestfuns/core/uqtestfun_abc.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464
self.prob_input = prob_input
6565
self._parameters = parameters
6666
self._function_id = function_id
67+
self._output_dimension: Optional[int] = None
6768

6869
@property
6970
def prob_input(self) -> ProbInput:
@@ -105,6 +106,21 @@ def input_dimension(self) -> int:
105106
"""The input dimension of the UQ test function."""
106107
return self.prob_input.input_dimension
107108

109+
@property
110+
def output_dimension(self) -> int:
111+
if self._output_dimension is None:
112+
xx = self.prob_input.get_sample()
113+
yy = self(xx)
114+
if yy.ndim == 1:
115+
self._output_dimension = 1
116+
elif yy.ndim == 2:
117+
self._output_dimension = yy.shape[1]
118+
else:
119+
self._output_dimension = yy.shape[1:]
120+
return self._output_dimension
121+
122+
return self._output_dimension
123+
108124
def transform_sample(
109125
self,
110126
xx: np.ndarray,
@@ -151,9 +167,10 @@ def transform_sample(
151167

152168
def __str__(self):
153169
out = (
154-
f"Function ID : {self.function_id}\n"
155-
f"Input Dimension : {self.input_dimension}\n"
156-
f"Parameterized : {bool(self.parameters)}"
170+
f"Function ID : {self.function_id}\n"
171+
f"Input Dimension : {self.input_dimension}\n"
172+
f"Output Dimension : {self.output_dimension}\n"
173+
f"Parameterized : {bool(self.parameters)}"
157174
)
158175

159176
return out
@@ -380,10 +397,11 @@ def description(cls) -> Optional[str]:
380397

381398
def __str__(self):
382399
out = (
383-
f"Function ID : {self.function_id}\n"
384-
f"Input Dimension : {self.input_dimension}\n"
385-
f"Parameterized : {bool(self.parameters)}\n"
386-
f"Description : {self.description}"
400+
f"Function ID : {self.function_id}\n"
401+
f"Input Dimension : {self.input_dimension}\n"
402+
f"Output Dimension : {self.output_dimension}\n"
403+
f"Parameterized : {bool(self.parameters)}\n"
404+
f"Description : {self.description}"
387405
)
388406

389407
return out

0 commit comments

Comments
 (0)