From 6d84f39519ccf92b2db56ccec4762e927af31974 Mon Sep 17 00:00:00 2001 From: Damar Wicaksono Date: Thu, 7 Nov 2024 17:58:45 +0100 Subject: [PATCH 1/4] function_id and input_id are now properties of ProbInput `function_id` and `input_id` are now properties of `ProbInput` so the relation with a particular function can be made explicit although without enforcement. Additionally changes include: - Specifications of probabilistic input in each of the test function modules now use simple dictionary with typing made explicit via `TypedDict` instead of using a `NamedTuple`. In particular, `UnivDistSpec` `ProbInputSpecFixDim`, and `ProbInputSpecVarDim` have been removed. - Class method `from_spec()` of `ProbInput` is removed. - The test suite has been accordingly updated. - The documentation has been updated. This commit should resolve Issue #363. --- CHANGELOG.md | 1 + docs/api/input-spec.rst | 27 --- docs/api/overview.md | 4 - .../adding-test-function-implementation.md | 101 +++++----- src/uqtestfuns/core/custom_typing.py | 73 +++++++ src/uqtestfuns/core/parameters.py | 5 +- src/uqtestfuns/core/prob_input/input_spec.py | 67 ------ src/uqtestfuns/core/prob_input/marginal.py | 23 --- .../core/prob_input/probabilistic_input.py | 162 ++++++++------- src/uqtestfuns/core/uqtestfun_abc.py | 94 +++++++-- src/uqtestfuns/meta/uqmetatestfun.py | 2 + src/uqtestfuns/test_functions/ackley.py | 61 ++---- src/uqtestfuns/test_functions/alemazkoor.py | 73 +++---- src/uqtestfuns/test_functions/borehole.py | 159 +++++++-------- src/uqtestfuns/test_functions/bratley1992.py | 55 ++--- .../test_functions/cantilever_beam_2d.py | 48 ++--- .../test_functions/circular_pipe_crack.py | 46 ++--- .../test_functions/convex_fail_domain.py | 45 +++-- .../test_functions/damped_cosine.py | 33 +-- .../test_functions/damped_oscillator.py | 190 +++++++++--------- src/uqtestfuns/test_functions/flood.py | 119 +++++------ src/uqtestfuns/test_functions/forrester.py | 33 +-- src/uqtestfuns/test_functions/four_branch.py | 49 ++--- src/uqtestfuns/test_functions/franke.py | 50 ++--- src/uqtestfuns/test_functions/friedman.py | 60 +++--- src/uqtestfuns/test_functions/gayton_hat.py | 44 ++-- src/uqtestfuns/test_functions/gramacy2007.py | 33 +-- src/uqtestfuns/test_functions/hyper_sphere.py | 44 ++-- src/uqtestfuns/test_functions/ishigami.py | 68 ++++--- src/uqtestfuns/test_functions/mclain.py | 49 +++-- src/uqtestfuns/test_functions/oakley2002.py | 33 +-- src/uqtestfuns/test_functions/otl_circuit.py | 125 ++++++------ src/uqtestfuns/test_functions/piston.py | 137 ++++++------- src/uqtestfuns/test_functions/portfolio_3d.py | 64 +++--- .../test_functions/rs_circular_bar.py | 48 ++--- src/uqtestfuns/test_functions/rs_quadratic.py | 45 +++-- src/uqtestfuns/test_functions/sobol_g.py | 59 ++---- .../test_functions/speed_reducer_shaft.py | 80 ++++---- src/uqtestfuns/test_functions/sulfur.py | 133 ++++++------ src/uqtestfuns/test_functions/webster.py | 44 ++-- src/uqtestfuns/test_functions/welch1992.py | 35 ++-- src/uqtestfuns/test_functions/wing_weight.py | 143 ++++++------- ...ltivariate_input.py => test_prob_input.py} | 88 +------- tests/core/test_input_spec.py | 95 --------- tests/core/test_uqtestfun.py | 9 +- 45 files changed, 1397 insertions(+), 1559 deletions(-) delete mode 100644 docs/api/input-spec.rst create mode 100644 src/uqtestfuns/core/custom_typing.py delete mode 100644 src/uqtestfuns/core/prob_input/input_spec.py rename tests/core/prob_input/{test_multivariate_input.py => test_prob_input.py} (76%) delete mode 100644 tests/core/test_input_spec.py diff --git a/CHANGELOG.md b/CHANGELOG.md index cda84f3..c65d4e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- `function_id` and `input_id` are now property of `ProbInput`. - `output_dimension` is now property of `UQTestFunBareABC` and inherited to all concrete classes of UQ test functions. - Printing a test function instance now shows whether the function is diff --git a/docs/api/input-spec.rst b/docs/api/input-spec.rst deleted file mode 100644 index bca5e92..0000000 --- a/docs/api/input-spec.rst +++ /dev/null @@ -1,27 +0,0 @@ -.. _api_reference_input_spec: - -Input Specification -=================== - -.. automodule:: uqtestfuns.core.prob_input.input_spec - -.. _api_reference_input_spec_univdist: - -``UnivDistSpec`` ----------------- - -.. autoclass:: uqtestfuns.core.prob_input.input_spec.UnivDistSpec - -.. _api_reference_input_spec_fixdim: - -``ProbInputSpecFixDim`` ------------------------ - -.. autoclass:: uqtestfuns.core.prob_input.input_spec.ProbInputSpecFixDim - -.. _api_reference_input_spec_vardim: - -``ProbInputSpecVarDim`` ------------------------ - -.. autoclass:: uqtestfuns.core.prob_input.input_spec.ProbInputSpecVarDim diff --git a/docs/api/overview.md b/docs/api/overview.md index 9865035..43ea1d5 100644 --- a/docs/api/overview.md +++ b/docs/api/overview.md @@ -26,10 +26,6 @@ let's start from the top, the {ref}`built-in test functions ` ``NamedTuple`` - are defined, namely {ref}`api_reference_input_spec_univdist`, - {ref}`api_reference_input_spec_fixdim`, and {ref}`api_reference_input_spec_vardim`. ```{note} To facilitate the creation of a custom UQ test function diff --git a/docs/development/adding-test-function-implementation.md b/docs/development/adding-test-function-implementation.md index f2c9956..d1902ba 100644 --- a/docs/development/adding-test-function-implementation.md +++ b/docs/development/adding-test-function-implementation.md @@ -109,8 +109,8 @@ Here are the few things we usually use: ```python import numpy as np -from ..core.uqtestfun_abc import UQTestFunABC -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim +from uqtestfuns.core.custom_typing import ProbInputSpecs, FunParamSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Branin"] ``` @@ -120,16 +120,11 @@ Here are some explanations: - NumPy is usually a must, especially for implementing the evaluation function. - All built-in test functions are concrete implementations of the abstract base class `UQTestFunABC`. -- The specification for a probabilistic input model is stored in `UnivDistSpec` - (the one-dimensional marginal specification) and `ProbInputSpecFixDim` - (the probabilistic input model). These are lightweight _containers_ - (meaning no custom methods) of all the information required to construct, - later on, `Marginal` and `ProbInput` instances, respectively. - -```{note} -There is also the corresponding `ProbInputSpecVarDim` to store the information -required to construct probabilistic input model with variable dimension. -``` +- To assist specifying the data for probabilistic input model the custom type + `ProbInputSpecs` can be used; these are supposed to help you specifying + all the required data via the typechecker. +- Similarly, the custom type `FunParamSpecs` is used for specifying the + function parameters. ### Implementing a concrete evaluation function @@ -181,36 +176,36 @@ include the parameters. The specification of the probabilistic model is stored in a module-level dictionary. While you're free to name the dictionary anything you like, -the convention is `AVAILABLE_INPUT_SPECS`. +the convention is `AVAILABLE_INPUTS`. We define the variable as follows: ```python -AVAILABLE_INPUT_SPECS = { - "Dixon1978": ProbInputSpecFixDim( - name="Branin-Dixon-2008", - description=( +AVAILABLE_INPUT_SPECS: ProbInputSpecs = { + "Dixon1978": { + "name": "Branin", + "description": ( "Search domain for the Branin function from Dixon and Szegö (1978)." ), - marginals=[ - UnivDistSpec( - name="x1", - distribution="uniform", - parameters=[-5, 10], - description="None", - ), - UnivDistSpec( - name="x2", - distribution="uniform", - parameters=[0.0, 15.0], - description="None", - ) + "marginals": [ + { + "name": "x1", + "distribution": "uniform", + "parameters": [-5, 10], + "description": None, + }, + { + "name": "x2", + "distribution": "uniform", + "parameters": [0.0, 15.0], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + }, } ``` -Each key-value pair of this dictionary contains a complete specification +Each key-value pair of this dictionary contains the specification to create an input model as an instance of the `ProbInput` class. For this particular example, we only have one input specification available. If there were more, we would add them here in the dictionary each with a unique keyword. @@ -219,8 +214,8 @@ If there were more, we would add them here in the dictionary each with a unique The keyword is, by convention, the citation key of the particular reference as listed in the BibTeX file. ``` -Also notice that in the code above, we store the specifications of the marginals -in a list of {ref}`api_reference_input_spec_univdist`. +Also notice that in the code above, we store the specifications of +the marginals in a list of marginal specifications. Each element of this list is used to create an instance of `Marginal`. With that, we have completed the input specification of the Branin function. @@ -232,7 +227,7 @@ dictionary that stores the parameter sets. Conventionally, we name this variable `AVAILABLE_PARAMETERS`: ```python -AVAILABLE_PARAMETERS = { +AVAILABLE_PARAMETERS: FunParamSpecs = { "Dixon1978": { "function_id": "Branin", "description": "Parameter set for the Branin function from Dixon (1978)", @@ -301,9 +296,9 @@ class Branin(UQTestFunABC): _tags = ["optimization"] # Application tags _description = "Branin function from Dixon and Szegö (1978)" # Short description - _available_inputs = AVAILABLE_INPUT_SPECS # As defined above - _available_parameters = AVAILABLE_PARAMETERS # As defined above - _default_input_dimension = 2 # input dimension of the function + _available_inputs = AVAILABLE_INPUTS # As defined above + _available_parameters = AVAILABLE_PARAMETERS # As defined above + _default_input_dimension = 2 # input dimension of the function _default_input = "Dixon1978" # Optional, if only one input is available _default_parameters = "Dixon1978" # Optional, if only one set of parameters is available @@ -313,7 +308,6 @@ class Branin(UQTestFunABC): There is no need to define an `__init__()` method. We will use the default `__init__()` from the base class. - Notice the two last class properties: `_default_input` and `_default_parameters`. In case of only one input specification (resp. set of parameters) is available, these properties are optional. @@ -346,13 +340,26 @@ built-in functions from a Python terminal. ```python >>> import uqtestfuns as uqtf >>> uqtf.list_functions() - No. Constructor Input Dim. Parameterized Application Description ------ ----------------------------- ------------ --------------- -------------------------------------- ---------------------------------------------------------------------------- - 1 Ackley() M True optimization, metamodeling Optimization test function from Ackley (1987) - 2 Alemazkoor20D() 20 False metamodeling High-dimensional low-degree polynomial from Alemazkoor & Meidani (2018) - 3 Alemazkoor2D() 2 False metamodeling Low-dimensional high-degree polynomial from Alemazkoor & Meidani (2018) - 4 Borehole() 8 False metamodeling, sensitivity Borehole function from Harper and Gupta (1983) - 5 Branin() 2 True optimization Branin function from Dixon and Szegö (1978) ++-------+-------------------------------+-----------+------------+----------+---------------+--------------------------------+ +| No. | Constructor | # Input | # Output | Param. | Application | Description | ++=======+===============================+===========+============+==========+===============+================================+ +| 1 | Ackley() | M | 1 | True | optimization, | Optimization test function | +| | | | | | metamodeling | from Ackley (1987) | ++-------+-------------------------------+-----------+------------+----------+---------------+--------------------------------+ +| 2 | Alemazkoor20D() | 20 | 1 | False | metamodeling | High-dimensional low-degree | +| | | | | | | polynomial from Alemazkoor & | +| | | | | | | Meidani (2018) | ++-------+-------------------------------+-----------+------------+----------+---------------+--------------------------------+ +| 3 | Alemazkoor2D() | 2 | 1 | False | metamodeling | Low-dimensional high-degree | +| | | | | | | polynomial from Alemazkoor & | +| | | | | | | Meidani (2018) | ++-------+-------------------------------+-----------+------------+----------+---------------+--------------------------------+ +| 4 | Borehole() | 8 | 1 | False | metamodeling, | Borehole function from Harper | +| | | | | | sensitivity | and Gupta (1983) | ++-------+-------------------------------+-----------+------------+----------+---------------+--------------------------------+ +| 5 | Branin() | 2 | 1 | False | optimization | Branin function from Dixon | +| | | | | | | and Szegö (1978) | ++-------+-------------------------------+-----------+------------+----------+---------------+--------------------------------+ ... ``` diff --git a/src/uqtestfuns/core/custom_typing.py b/src/uqtestfuns/core/custom_typing.py new file mode 100644 index 0000000..6d656b9 --- /dev/null +++ b/src/uqtestfuns/core/custom_typing.py @@ -0,0 +1,73 @@ +""" +Core module that contains custom types used in UQTestFuns. + +Custom types are used to assist type checker during the code development. +""" + +from typing import List, Union, Optional, Any, Dict, Sequence +from typing_extensions import TypedDict + +from uqtestfuns.core.prob_input.marginal import Marginal + +__all__ = [ + "MarginalSpecs", + "ProbInputSpecs", + "ProbInputArgs", + "FunParamSpecs", + "FunParamsArgs", + "DeclaredParameters", +] + + +class MarginalSpec(TypedDict): + name: str + distribution: str + parameters: List[Union[float, int]] + description: Optional[str] + + +MarginalSpecs = List[MarginalSpec] + + +class ProbInputSpec(TypedDict): + function_id: str + description: str + marginals: List[MarginalSpec] + copulas: Optional[Any] + + +ProbInputSpecs = Dict[str, ProbInputSpec] + + +class ProbInputArgs(TypedDict): + function_id: str + input_id: str + description: str + marginals: Sequence[Marginal] + copulas: Optional[Any] + + +class DeclaredParameter(TypedDict): + keyword: str + value: Any + type: Optional[type] + description: Optional[str] + + +DeclaredParameters = List[DeclaredParameter] + + +class FunParamsSpec(TypedDict): + function_id: str + description: str + declared_parameters: DeclaredParameters + + +FunParamSpecs = Dict[str, FunParamsSpec] + + +class FunParamsArgs(TypedDict): + function_id: str + parameter_id: str + description: str + declared_parameters: DeclaredParameters diff --git a/src/uqtestfuns/core/parameters.py b/src/uqtestfuns/core/parameters.py index 7adace4..369becf 100644 --- a/src/uqtestfuns/core/parameters.py +++ b/src/uqtestfuns/core/parameters.py @@ -14,6 +14,7 @@ import numpy as np +from uqtestfuns.core.custom_typing import DeclaredParameters FIELD_NAMES = ["Keyword", "Value", "Type", "Description"] @@ -44,7 +45,7 @@ def __init__( function_id: str = "", parameter_id: str = "", description: str = "", - declared_parameters: Optional[List[dict]] = None, + declared_parameters: Optional[DeclaredParameters] = None, ): self._declared_parameters: dict = {} self._dict: dict = {} @@ -166,7 +167,7 @@ def add( keyword: str, value: Any, type: Optional[type] = None, - description: str = "", + description: Optional[str] = "", ) -> None: """Add a parameter to the parameter set. diff --git a/src/uqtestfuns/core/prob_input/input_spec.py b/src/uqtestfuns/core/prob_input/input_spec.py deleted file mode 100644 index aec699f..0000000 --- a/src/uqtestfuns/core/prob_input/input_spec.py +++ /dev/null @@ -1,67 +0,0 @@ -""" -Module with definition of data structure to hold information on prob. input. - -A probabilistic input specification may be stored in a built-in Python -data type that contains the only information required to construct -a ``UnivDist`` (for one-dimensional marginals) and ``ProbInput`` -(for probabilistic input models) instances. -The container type should be free of custom methods and derived from -``NamedTuple`` class to provide typing information. -""" - -from typing import Any, Callable, List, NamedTuple, Optional, Tuple, Union - - -__all__ = ["UnivDistSpec", "ProbInputSpecFixDim", "ProbInputSpecVarDim"] - - -class UnivDistSpec(NamedTuple): - """A univariate marginal distribution specification. - - Parameters - ---------- - name : str - The name of the univariate marginal. - distribution : str - The name of the distribution of the univariate marginal. - parameters : Union[List[Union[int, float]], Tuple[Union[int, float], ...]] - Parameter values of the distribution. - description : str - Short description of the univariate marginal. - """ - - name: Optional[str] - distribution: str - parameters: Union[List[Union[int, float]], Tuple[Union[int, float], ...]] - description: Optional[str] - - -class ProbInputSpecFixDim(NamedTuple): - """All the information to construct a ProbInput w/ a fixed dimension. - - Parameters - ---------- - name : str - The name of the probabilistic input model. - description : str - A short description of the probabilistic input model. - marginals : Union[Callable, List[UnivDistSpec]] - A list of univariate marginal specifications or a callable - to construct the list of marginal specifications. - copulas : Optional[Any] - The copula specification of the probabilistic input model. - """ - - name: Optional[str] - description: Optional[str] - marginals: List[UnivDistSpec] - copulas: Optional[Any] - - -class ProbInputSpecVarDim(NamedTuple): - """All the information to construct a ProbInput w/ variable dimension.""" - - name: Optional[str] - description: Optional[str] - marginals_generator: Callable[[int], List[UnivDistSpec]] - copulas: Optional[Any] diff --git a/src/uqtestfuns/core/prob_input/marginal.py b/src/uqtestfuns/core/prob_input/marginal.py index 18c67ed..28ca890 100644 --- a/src/uqtestfuns/core/prob_input/marginal.py +++ b/src/uqtestfuns/core/prob_input/marginal.py @@ -23,7 +23,6 @@ get_cdf_values, get_icdf_values, ) -from .input_spec import UnivDistSpec from ...global_settings import ARRAY_FLOAT __all__ = ["Marginal"] @@ -173,25 +172,3 @@ def icdf(self, xx: Union[float, np.ndarray]) -> ARRAY_FLOAT: return get_icdf_values( xx, self.distribution, self.parameters, self.lower, self.upper ) - - @classmethod - def from_spec( - cls, marginal_spec: UnivDistSpec, rng_seed: Optional[int] = None - ): - """Create an instance of UnivDist from a marginal specification. - - Parameters - ---------- - marginal_spec : UnivDistSpec - The specification for the univariate marginal. - rng_seed : int, optional - The seed used to initialize the pseudo-random number generator. - If not specified, the value is taken from the system entropy. - """ - return cls( - distribution=marginal_spec.distribution, - parameters=marginal_spec.parameters, - name=marginal_spec.name, - description=marginal_spec.description, - rng_seed=rng_seed, - ) diff --git a/src/uqtestfuns/core/prob_input/probabilistic_input.py b/src/uqtestfuns/core/prob_input/probabilistic_input.py index 9f8dcba..e5475f9 100644 --- a/src/uqtestfuns/core/prob_input/probabilistic_input.py +++ b/src/uqtestfuns/core/prob_input/probabilistic_input.py @@ -11,18 +11,15 @@ import numpy as np import textwrap -from dataclasses import dataclass, field from numpy.random._generator import Generator from tabulate import tabulate -from typing import Any, List, Optional, Union, Tuple +from typing import Any, List, Optional, Sequence from .marginal import Marginal, FIELD_NAMES -from .input_spec import ProbInputSpecFixDim, ProbInputSpecVarDim __all__ = ["ProbInput"] -@dataclass class ProbInput: """A class for multivariate input variables. @@ -33,36 +30,62 @@ class ProbInput: copulas : Any Copulas between univariate inputs that define dependence structure (currently not used). - name : str, optional - The name of the probabilistic input model. - description : str, optional + input_id: str, optional + The ID of the probabilistic input. If not specified, the value is None. + function_id: str, optional + The ID of the function associated with the input. If not specified, + the value is None. + description: str, optional The short description regarding the input model. rng_seed : int, optional. The seed used to initialize the pseudo-random number generator. If not specified, the value is taken from the system entropy. - - Attributes - ---------- - input_dimension : int - Number of constituents (random) input variables. - _rng : Generator - The default pseudo-random number generator of NumPy. - The generator is only created if or when needed (e.g., generating - a random sample from the distribution). """ - input_dimension: int = field(init=False) - marginals: Union[List[Marginal], Tuple[Marginal, ...]] - copulas: Any = None - name: Optional[str] = None - description: Optional[str] = None - rng_seed: Optional[int] = field(default=None, repr=False) - _rng: Optional[Generator] = field(init=False, default=None, repr=False) - - def __post_init__(self): - self.input_dimension = len(self.marginals) - # Protect marginals by making it immutable - self.marginals = tuple(self.marginals) + def __init__( + self, + marginals: Sequence[Marginal], + copulas: Any = None, + input_id: Optional[str] = None, + function_id: Optional[str] = None, + description: Optional[str] = None, + rng_seed: Optional[int] = None, + ): + # Read-only properties + self._marginals = marginals + self._copulas = copulas + # Attributes + self.input_id = input_id + self.function_id = function_id + self.description = description + # Other properties + self._rng_seed = rng_seed + self._rng: Optional[Generator] = None + + @property + def input_dimension(self) -> int: + """Return the number of constituents (random) input variables.""" + return len(self._marginals) + + @property + def marginals(self) -> Sequence[Marginal]: + """Return the sequence of Marginals that define the input variables.""" + return self._marginals + + @property + def copulas(self) -> Any: + """Return the underlying Copulas of the probabilistic input.""" + return self._copulas + + @property + def rng_seed(self) -> Optional[int]: + """Return the seed for RNG.""" + return self._rng_seed + + @rng_seed.setter + def rng_seed(self, value: Optional[int]): + """Set/reset the seed for RNG.""" + self.reset_rng(self._rng_seed) def transform_sample(self, xx: np.ndarray, other: ProbInput): """Transform a sample from the distribution to another.""" @@ -115,19 +138,6 @@ def get_sample(self, sample_size: int = 1) -> np.ndarray: return xx - def reset_rng(self, rng_seed: Optional[int]) -> None: - """Reset the random number generator. - - Parameters - ---------- - rng_seed : int, optional. - The seed used to initialize the pseudo-random number generator. - If not specified, the value is taken from the system entropy. - """ - rng = np.random.default_rng(rng_seed) - object.__setattr__(self, "_rng", rng) - object.__setattr__(self, "rng_seed", rng_seed) - def pdf(self, xx: np.ndarray) -> np.ndarray: """Get the PDF value of the distribution on a set of values. @@ -152,8 +162,31 @@ def pdf(self, xx: np.ndarray) -> np.ndarray: return yy + def reset_rng(self, rng_seed: Optional[int]) -> None: + """Reset the random number generator. + + Parameters + ---------- + rng_seed : int, optional. + The seed used to initialize the pseudo-random number generator. + If not specified, the value is taken from the system entropy. + """ + rng = np.random.default_rng(rng_seed) + self._rng = rng + self._rng_seed = rng_seed + def __str__(self): - table = f"Name : {self.name}\n" + """Return human-readable string representation of the instance.""" + if self.input_id is None or self.input_id == "": + input_id = "-" + else: + input_id = self.input_id + if self.function_id is None or self.function_id == "": + function_id = "-" + else: + function_id = self.function_id + table = f"Function ID : {function_id}\n" + table += f"Input ID : {input_id}\n" table += f"Input Dimension : {self.input_dimension}\n" # Parse the description column @@ -186,40 +219,25 @@ def __str__(self): return table - @classmethod - def from_spec( - cls, - prob_input_spec: Union[ProbInputSpecFixDim, ProbInputSpecVarDim], - *, - input_dimension: Optional[int] = None, - rng_seed: Optional[int] = None, - ): - """Create an instance from a ProbInputSpec instance.""" + def __repr__(self): + """Return the unambiguous string representation of the instance.""" + class_name = self.__class__.__name__ + # Get the value of the constructor arguments + attrs = { + "marginals": self.marginals, + "copulas": self.copulas, + "input_id": self.input_id, + "function_id": self.function_id, + "description": self.description, + "rng_seed": self.rng_seed, + } + attrs_str = ", ".join(f"{k}={v!r}" for k, v in attrs.items()) - if isinstance(prob_input_spec, ProbInputSpecVarDim): - if input_dimension is None: - raise ValueError("Input dimension must be specified!") - marginals_gen = prob_input_spec.marginals_generator - marginals_spec = marginals_gen(input_dimension) - else: - marginals_spec = prob_input_spec.marginals - - # Create a list of Marginal instances representing univariate marginals - marginals = [ - Marginal.from_spec(marginal) for marginal in marginals_spec - ] - - return cls( - marginals=marginals, - copulas=prob_input_spec.copulas, - name=prob_input_spec.name, - description=prob_input_spec.description, - rng_seed=rng_seed, - ) + return f"{class_name}({attrs_str})" def _get_values_as_list( - univ_inputs: Union[List[Marginal], Tuple[Marginal, ...]], + univ_inputs: Sequence[Marginal], field_names: List[str], ) -> list: """Get the values from each field from a list of UnivariateInput diff --git a/src/uqtestfuns/core/uqtestfun_abc.py b/src/uqtestfuns/core/uqtestfun_abc.py index 2779307..66b9fb2 100644 --- a/src/uqtestfuns/core/uqtestfun_abc.py +++ b/src/uqtestfuns/core/uqtestfun_abc.py @@ -7,11 +7,17 @@ from copy import deepcopy from inspect import signature -from typing import Any, Callable, Dict, List, Optional, Union +from typing import Callable, cast, List, Optional +from .prob_input.marginal import Marginal from .prob_input.probabilistic_input import ProbInput from .parameters import FunParams -from .prob_input.input_spec import ProbInputSpecFixDim, ProbInputSpecVarDim +from .custom_typing import ( + ProbInputSpecs, + ProbInputArgs, + FunParamSpecs, + FunParamsArgs, +) from .utils import create_canonical_uniform_input __all__ = ["UQTestFunBareABC", "UQTestFunABC"] @@ -254,28 +260,30 @@ def __init__( available_inputs = self.available_inputs if not prob_input_selection: prob_input_selection = self.default_input + prob_input_selection = cast(str, prob_input_selection) if prob_input_selection not in available_inputs: print(prob_input_selection) raise KeyError( "Input selection is not in the available specifications." ) - prob_input_spec = available_inputs[prob_input_selection] - # Determine the dimensionality of the test function - if isinstance(prob_input_spec, ProbInputSpecFixDim): + if self.default_input_dimension is None: + if not input_dimension: + input_dimension = DEFAULT_DIMENSION + prob_input_data = _parse_input_vardim( + input_dimension, + prob_input_selection, + available_inputs, + ) + else: if input_dimension: raise TypeError("Fixed test dimension!") - if not input_dimension: - input_dimension = DEFAULT_DIMENSION - - # Create a ProbInput instance - if isinstance(prob_input_spec, ProbInputSpecVarDim): - prob_input = ProbInput.from_spec( - prob_input_spec, - input_dimension=input_dimension, + prob_input_data = _parse_input_fixdim( + prob_input_selection, + available_inputs, ) - else: - prob_input = ProbInput.from_spec(prob_input_spec) + + prob_input = ProbInput(**prob_input_data) # --- Select the parameters set, when applicable if self.available_parameters is None: @@ -364,19 +372,17 @@ def tags(cls) -> List[str]: return cls._tags # type: ignore @classproperty - def available_inputs( - cls, - ) -> Union[Dict[str, ProbInputSpecFixDim], Dict[str, ProbInputSpecVarDim]]: + def available_inputs(cls) -> ProbInputSpecs: """All the keys to the available probabilistic input specifications.""" return cls._available_inputs # type: ignore @classproperty def default_input(cls) -> Optional[str]: """The key to the default probabilistic input specification.""" - return cls._default_input # type: ignore + return cls._default_input @classproperty - def available_parameters(cls) -> Optional[Dict[str, Any]]: + def available_parameters(cls) -> Optional[FunParamSpecs]: """All the keys to the available set of parameter values.""" return cls._available_parameters # type: ignore @@ -456,10 +462,55 @@ def _verify_sample_domain(xx: np.ndarray, min_value: float, max_value: float): ) +def _parse_input_vardim( + input_dimension: int, + input_id: str, + available_inputs: ProbInputSpecs, +) -> ProbInputArgs: + """Get the selected input.""" + # Get the input + raw_data = available_inputs[input_id].copy() + + # Process the marginals + marginals = [] + for i in range(input_dimension): + marginal = raw_data["marginals"][0].copy() + marginal["name"] = f"{marginal['name']}{i}" + marginals.append(Marginal(**marginal)) + + # Recast the type to satisfy type checker + input_data = cast(ProbInputArgs, raw_data) + input_data["input_id"] = input_id + input_data["marginals"] = marginals + + return input_data + + +def _parse_input_fixdim( + input_id: str, + available_inputs: ProbInputSpecs, +) -> ProbInputArgs: + """Get the selected input.""" + # Get the input + raw_data = available_inputs[input_id].copy() + + # Process the marginals + marginals = [] + for marginal in raw_data["marginals"]: + marginals.append(Marginal(**marginal)) + + # Recast the type to satisfy type checker + input_data = cast(ProbInputArgs, raw_data) + input_data["input_id"] = input_id + input_data["marginals"] = marginals + + return input_data + + def _create_parameters( function_id: str, parameter_id: str, - available_parameters: dict, + available_parameters: FunParamSpecs, input_dimension: Optional[int] = None, ) -> FunParams: """Create the Parameter set of a UQ test function.""" @@ -478,6 +529,7 @@ def _create_parameters( raise ValueError() # Prepare the dictionary as input + param_dict = cast(FunParamsArgs, param_dict) # Recasting for type checker param_dict["parameter_id"] = parameter_id # Deal with variable dimension parameter diff --git a/src/uqtestfuns/meta/uqmetatestfun.py b/src/uqtestfuns/meta/uqmetatestfun.py index d0defb3..0e9003e 100644 --- a/src/uqtestfuns/meta/uqmetatestfun.py +++ b/src/uqtestfuns/meta/uqmetatestfun.py @@ -153,6 +153,7 @@ def get_sample( "keyword": "spec", "value": testfun_specs, "type": UQTestFunSpec, + "description": None, }, ], ) @@ -176,6 +177,7 @@ def get_sample( "keyword": "spec", "value": testfun_specs[i], "type": UQTestFunSpec, + "description": None, }, ], ) diff --git a/src/uqtestfuns/test_functions/ackley.py b/src/uqtestfuns/test_functions/ackley.py index 54dd53d..ca03a97 100644 --- a/src/uqtestfuns/test_functions/ackley.py +++ b/src/uqtestfuns/test_functions/ackley.py @@ -22,53 +22,32 @@ import numpy as np -from typing import List - -from ..core.uqtestfun_abc import UQTestFunABC -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecVarDim +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs, FunParamSpecs __all__ = ["Ackley"] -def _ackley_input(input_dimension: int) -> List[UnivDistSpec]: - """Create a list of marginals for the M-dimensional Ackley function. - - Parameters - ---------- - input_dimension : int - The requested input dimension of the probabilistic input model. - - Returns - ------- - List[UnivDistSpec] - A list of marginals for the multivariate input following Ref. [1] - """ - marginals = [] - for i in range(input_dimension): - marginals.append( - UnivDistSpec( - name=f"X{i + 1}", - distribution="uniform", - parameters=[-32.768, 32.768], - description=None, - ) - ) - - return marginals - - -AVAILABLE_INPUT_SPECS = { - "Ackley1987": ProbInputSpecVarDim( - name="Ackley1987", - description=( - "Search domain for the Ackley function from Ackley (1987)." +AVAILABLE_INPUTS: ProbInputSpecs = { + "Ackley1987": { + "function_id": "Ackley1987", + "description": ( + "Search domain for the Ackley function from Ackley (1987)" ), - marginals_generator=_ackley_input, - copulas=None, - ), + "marginals": [ + { + "name": "X", + "distribution": "uniform", + "parameters": [-32.768, 32.768], + "description": None, + }, + ], + "copulas": None, + } } -AVAILABLE_PARAMETERS = { + +AVAILABLE_PARAMETERS: FunParamSpecs = { "Ackley1987": { "function_id": "Ackley", "description": ( @@ -136,7 +115,7 @@ class Ackley(UQTestFunABC): _tags = ["optimization", "metamodeling"] _description = "Optimization test function from Ackley (1987)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = AVAILABLE_PARAMETERS _default_input_dimension = None # Indicate that this is variable dim. diff --git a/src/uqtestfuns/test_functions/alemazkoor.py b/src/uqtestfuns/test_functions/alemazkoor.py index 3cc7ae2..b6ab6e1 100644 --- a/src/uqtestfuns/test_functions/alemazkoor.py +++ b/src/uqtestfuns/test_functions/alemazkoor.py @@ -19,54 +19,55 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Alemazkoor2D", "Alemazkoor20D"] -AVAILABLE_INPUT_SPECS_2D = { - "Alemazkoor2018": ProbInputSpecFixDim( - name="2D-Alemazkoor2018", - description=( + +AVAILABLE_INPUTS_2D: ProbInputSpecs = { + "Alemazkoor2018": { + "function_id": "Alemazkoor2D", + "description": ( "Input specification for the 2D test function " "from Alemazkoor & Meidani (2018)" ), - marginals=[ - UnivDistSpec( - name="X1", - distribution="uniform", - parameters=[-1, 1], - description=None, - ), - UnivDistSpec( - name="X2", - distribution="uniform", - parameters=[-1, 1], - description=None, - ), + "marginals": [ + { + "name": "X1", + "distribution": "uniform", + "parameters": [-1.0, 1.0], + "description": None, + }, + { + "name": "X2", + "distribution": "uniform", + "parameters": [-1.0, 1.0], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + }, } -AVAILABLE_INPUT_SPECS_20D = { - "Alemazkoor2018": ProbInputSpecFixDim( - name="20D-Alemazkoor2018", - description=( +AVAILABLE_INPUTS_20D: ProbInputSpecs = { + "Alemazkoor2018": { + "function_id": "Alemazkoor20D", + "description": ( "Input specification for the 20D test function " "from Alemazkoor & Meidani (2018)" ), - marginals=[ - UnivDistSpec( - name=f"X{i + 1}", - distribution="uniform", - parameters=[-1, 1], - description="None", - ) + "marginals": [ + { + "name": f"X{i + 1}", + "distribution": "uniform", + "parameters": [-1, 1], + "description": None, + } for i in range(20) ], - copulas=None, - ) + "copulas": None, + }, } @@ -101,7 +102,7 @@ class Alemazkoor2D(UQTestFunABC): "Low-dimensional high-degree polynomial from Alemazkoor " "& Meidani (2018)" ) - _available_inputs = AVAILABLE_INPUT_SPECS_2D + _available_inputs = AVAILABLE_INPUTS_2D _available_parameters = None _default_input_dimension = 2 @@ -136,7 +137,7 @@ class Alemazkoor20D(UQTestFunABC): "High-dimensional low-degree polynomial from Alemazkoor " "& Meidani (2018)" ) - _available_inputs = AVAILABLE_INPUT_SPECS_20D + _available_inputs = AVAILABLE_INPUTS_20D _available_parameters = None _default_input_dimension = 20 diff --git a/src/uqtestfuns/test_functions/borehole.py b/src/uqtestfuns/test_functions/borehole.py index f0b4345..c928f91 100644 --- a/src/uqtestfuns/test_functions/borehole.py +++ b/src/uqtestfuns/test_functions/borehole.py @@ -24,99 +24,100 @@ import numpy as np -from ..core.uqtestfun_abc import UQTestFunABC -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim +from uqtestfuns.core.custom_typing import MarginalSpecs, ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Borehole"] + # From Ref. [1] -INPUT_MARGINALS_HARPER1983 = [ - UnivDistSpec( - name="rw", - distribution="normal", - parameters=[0.10, 0.0161812], - description="radius of the borehole [m]", - ), - UnivDistSpec( - name="r", - distribution="lognormal", - parameters=[7.71, 1.0056], - description="radius of influence [m]", - ), - UnivDistSpec( - name="Tu", - distribution="uniform", - parameters=[63070.0, 115600.0], - description="transmissivity of upper aquifer [m^2/year]", - ), - UnivDistSpec( - name="Hu", - distribution="uniform", - parameters=[990.0, 1100.0], - description="potentiometric head of upper aquifer [m]", - ), - UnivDistSpec( - name="Tl", - distribution="uniform", - parameters=[63.1, 116.0], - description="transmissivity of lower aquifer [m^2/year]", - ), - UnivDistSpec( - name="Hl", - distribution="uniform", - parameters=[700.0, 820.0], - description="potentiometric head of lower aquifer [m]", - ), - UnivDistSpec( - name="L", - distribution="uniform", - parameters=[1120.0, 1680.0], - description="length of the borehole [m]", - ), - UnivDistSpec( - name="Kw", - distribution="uniform", - parameters=[9985.0, 12045.0], - description="hydraulic conductivity of the borehole [m/year]", - ), +MARGINALS_HARPER1983: MarginalSpecs = [ + { + "name": "rw", + "distribution": "normal", + "parameters": [0.10, 0.0161812], + "description": "radius of the borehole [m]", + }, + { + "name": "r", + "distribution": "lognormal", + "parameters": [7.71, 1.0056], + "description": "radius of influence [m]", + }, + { + "name": "Tu", + "distribution": "uniform", + "parameters": [63070.0, 115600.0], + "description": "transmissivity of upper aquifer [m^2/year]", + }, + { + "name": "Hu", + "distribution": "uniform", + "parameters": [990.0, 1100.0], + "description": "potentiometric head of upper aquifer [m]", + }, + { + "name": "Tl", + "distribution": "uniform", + "parameters": [63.1, 116.0], + "description": "transmissivity of lower aquifer [m^2/year]", + }, + { + "name": "Hl", + "distribution": "uniform", + "parameters": [700.0, 820.0], + "description": "potentiometric head of lower aquifer [m]", + }, + { + "name": "L", + "distribution": "uniform", + "parameters": [1120.0, 1680.0], + "description": "length of the borehole [m]", + }, + { + "name": "Kw", + "distribution": "uniform", + "parameters": [9985.0, 12045.0], + "description": "hydraulic conductivity of the borehole [m/year]", + }, ] # From Ref. [2] -INPUT_MARGINALS_MORRIS1993 = list(INPUT_MARGINALS_HARPER1983) -INPUT_MARGINALS_MORRIS1993[0:2] = [ - UnivDistSpec( - name="rw", - distribution="uniform", - parameters=[0.05, 0.15], - description="radius of the borehole [m]", - ), - UnivDistSpec( - name="r", - distribution="uniform", - parameters=[100, 50000], - description="radius of influence [m]", - ), +MARGINALS_MORRIS1993 = list(MARGINALS_HARPER1983) +MARGINALS_MORRIS1993[0:2] = [ + { + "name": "rw", + "distribution": "uniform", + "parameters": [0.05, 0.15], + "description": "radius of the borehole [m]", + }, + { + "name": "r", + "distribution": "uniform", + "parameters": [100, 50000], + "description": "radius of influence [m]", + }, ] -AVAILABLE_INPUT_SPECS = { - "Harper1983": ProbInputSpecFixDim( - name="Borehole-Harper-1983", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Harper1983": { + "function_id": "Borehole", + "description": ( "Probabilistic input model of the Borehole model " "from Harper and Gupta (1983)." ), - marginals=INPUT_MARGINALS_HARPER1983, - copulas=None, - ), - "Morris1993": ProbInputSpecFixDim( - name="Borehole-Morris-1993", - description=( + "marginals": MARGINALS_HARPER1983, + "copulas": None, + }, + "Morris1993": { + "function_id": "Borehole", + "description": ( "Probabilistic input model of the Borehole model " "from Morris et al. (1993)." ), - marginals=INPUT_MARGINALS_MORRIS1993, - copulas=None, - ), + "marginals": MARGINALS_MORRIS1993, + "copulas": None, + }, } DEFAULT_INPUT_SELECTION = "Harper1983" @@ -158,7 +159,7 @@ class Borehole(UQTestFunABC): _tags = ["metamodeling", "sensitivity"] _description = "Borehole function from Harper and Gupta (1983)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input = DEFAULT_INPUT_SELECTION _default_input_dimension = 8 diff --git a/src/uqtestfuns/test_functions/bratley1992.py b/src/uqtestfuns/test_functions/bratley1992.py index f827f65..3786948 100644 --- a/src/uqtestfuns/test_functions/bratley1992.py +++ b/src/uqtestfuns/test_functions/bratley1992.py @@ -36,58 +36,37 @@ import numpy as np from scipy.special import eval_chebyt -from typing import List from .sobol_g import evaluate as evaluate_sobol_g -from ..core.uqtestfun_abc import UQTestFunABC -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecVarDim +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Bratley1992a", "Bratley1992b", "Bratley1992c", "Bratley1992d"] -def _bratley_input(input_dimension: int) -> List[UnivDistSpec]: - """Create a list of marginals for the M-dimensional Bratley test functions. - - Parameters - ---------- - input_dimension : int - The requested input dimension of the probabilistic input model. - - Returns - ------- - List[UnivDistSpec] - A list of marginals for the multivariate input following Ref. [1] - """ - marginals = [] - for i in range(input_dimension): - marginals.append( - UnivDistSpec( - name=f"X{i + 1}", - distribution="uniform", - parameters=[0.0, 1.0], - description=None, - ) - ) - - return marginals - - -AVAILABLE_INPUT_SPECS = { - "Bratley1992": ProbInputSpecVarDim( - name="Bratley1992", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Bratley1992": { + "function_id": "Bratley1992", + "description": ( "Integration domain of the functions from Bratley et al. (1992)" ), - marginals_generator=_bratley_input, - copulas=None, - ), + "marginals": [ + { + "name": "X", + "distribution": "uniform", + "parameters": [0.0, 1.0], + "description": None, + }, + ], + "copulas": None, + }, } # Common metadata used in each class definition of Bratley test functions COMMON_METADATA = dict( _tags=["integration", "sensitivity"], - _available_inputs=AVAILABLE_INPUT_SPECS, + _available_inputs=AVAILABLE_INPUTS, _available_parameters=None, _default_input_dimension=None, _description="from Bratley et al. (1992)", diff --git a/src/uqtestfuns/test_functions/cantilever_beam_2d.py b/src/uqtestfuns/test_functions/cantilever_beam_2d.py index dc0b806..bf248fa 100644 --- a/src/uqtestfuns/test_functions/cantilever_beam_2d.py +++ b/src/uqtestfuns/test_functions/cantilever_beam_2d.py @@ -28,37 +28,39 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs, FunParamSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["CantileverBeam2D"] -AVAILABLE_INPUT_SPECS = { - "Rajashekhar1993": ProbInputSpecFixDim( - name="Cantilever2D-Rajashekhar1993", - description=( + +AVAILABLE_INPUTS: ProbInputSpecs = { + "Rajashekhar1993": { + "function_id": "Cantilever2D", + "description": ( "Input model for the cantilever beam problem " "from Rajashekhar and Ellingwood (1993)" ), - marginals=[ - UnivDistSpec( - name="W", - distribution="normal", - parameters=[1000.0, 200.0], - description="Load per unit area [N/m^2]", - ), - UnivDistSpec( - name="H", - distribution="normal", - parameters=[250.0, 37.5], - description="Depth of the cross-section [mm]", - ), + "marginals": [ + { + "name": "W", + "distribution": "normal", + "parameters": [1000.0, 200.0], + "description": "Load per unit area [N/m^2]", + }, + { + "name": "H", + "distribution": "normal", + "parameters": [250.0, 37.5], + "description": "Depth of the cross-section [mm]", + }, ], - copulas=None, - ), + "copulas": None, + }, } -AVAILABLE_PARAMETERS = { + +AVAILABLE_PARAMETERS: FunParamSpecs = { "Rajashekhar1993": { "function_id": "CantileverBeam2D", "description": ( @@ -123,7 +125,7 @@ class CantileverBeam2D(UQTestFunABC): "Cantilever beam reliability problem " "from Rajashekhar and Ellington (1993)" ) - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = AVAILABLE_PARAMETERS _default_input_dimension = 2 diff --git a/src/uqtestfuns/test_functions/circular_pipe_crack.py b/src/uqtestfuns/test_functions/circular_pipe_crack.py index 7935d56..65ddda2 100644 --- a/src/uqtestfuns/test_functions/circular_pipe_crack.py +++ b/src/uqtestfuns/test_functions/circular_pipe_crack.py @@ -23,39 +23,39 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs, FunParamSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["CircularPipeCrack"] -AVAILABLE_INPUT_SPECS = { - "Verma2015": ProbInputSpecFixDim( - name="CircularPipeCrack-Verma2015", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Verma2015": { + "function_id": "CircularPipeCrack", + "description": ( "Input model for the circular pipe crack problem " "from Verma et al. (2015)" ), - marginals=[ - UnivDistSpec( - name="sigma_f", - distribution="normal", - parameters=[301.079, 14.78], - description="flow stress [MNm]", - ), - UnivDistSpec( - name="theta", - distribution="normal", - parameters=[0.503, 0.049], - description="half crack angle [-]", - ), + "marginals": [ + { + "name": "sigma_f", + "distribution": "normal", + "parameters": [301.079, 14.78], + "description": "flow stress [MNm]", + }, + { + "name": "theta", + "distribution": "normal", + "parameters": [0.503, 0.049], + "description": "half crack angle [-]", + }, ], - copulas=None, - ), + "copulas": None, + }, } -AVAILABLE_PARAMETERS = { +AVAILABLE_PARAMETERS: FunParamSpecs = { "Verman2016": { "function_id": "CircularPipeCrack", "description": ( @@ -133,7 +133,7 @@ class CircularPipeCrack(UQTestFunABC): _description = ( "Circular pipe under bending moment from Verma et al. (2015)" ) - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = AVAILABLE_PARAMETERS _default_input_dimension = 2 diff --git a/src/uqtestfuns/test_functions/convex_fail_domain.py b/src/uqtestfuns/test_functions/convex_fail_domain.py index a91e419..7ea28a0 100644 --- a/src/uqtestfuns/test_functions/convex_fail_domain.py +++ b/src/uqtestfuns/test_functions/convex_fail_domain.py @@ -17,34 +17,35 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["ConvexFailDomain"] -AVAILABLE_INPUT_SPECS = { - "Borri1997": ProbInputSpecFixDim( - name="ConvexFailDomain-Borri1997", - description=( + +AVAILABLE_INPUTS: ProbInputSpecs = { + "Borri1997": { + "function_id": "ConvexFailDomain", + "description": ( "Input model for the convex failure domain problem " "from Borri and Speranzini (1997)" ), - marginals=[ - UnivDistSpec( - name="X1", - distribution="normal", - parameters=[0, 1], - description=None, - ), - UnivDistSpec( - name="X2", - distribution="normal", - parameters=[0, 1], - description=None, - ), + "marginals": [ + { + "name": "X1", + "distribution": "normal", + "parameters": [0, 1], + "description": None, + }, + { + "name": "X2", + "distribution": "normal", + "parameters": [0, 1], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + }, } @@ -82,7 +83,7 @@ class ConvexFailDomain(UQTestFunABC): _description = ( "Convex failure domain problem from Borri and Speranzini (1997)" ) - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 2 diff --git a/src/uqtestfuns/test_functions/damped_cosine.py b/src/uqtestfuns/test_functions/damped_cosine.py index 7585a16..c3fa53b 100644 --- a/src/uqtestfuns/test_functions/damped_cosine.py +++ b/src/uqtestfuns/test_functions/damped_cosine.py @@ -13,28 +13,29 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["DampedCosine"] -AVAILABLE_INPUT_SPECS = { - "Santner2018": ProbInputSpecFixDim( - name="Santner2018", - description=( + +AVAILABLE_INPUTS: ProbInputSpecs = { + "Santner2018": { + "function_id": "DampedCosine", + "description": ( "Input model for the one-dimensional damped cosine " "from Santner et al. (2018)" ), - marginals=[ - UnivDistSpec( - name="x", - distribution="uniform", - parameters=[0.0, 1.0], - description=None, - ) + "marginals": [ + { + "name": "x", + "distribution": "uniform", + "parameters": [0.0, 1.0], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + } } @@ -64,7 +65,7 @@ class DampedCosine(UQTestFunABC): _tags = ["metamodeling"] _description = "One-dimensional damped cosine from Santner et al. (2018)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 1 diff --git a/src/uqtestfuns/test_functions/damped_oscillator.py b/src/uqtestfuns/test_functions/damped_oscillator.py index 0912f8f..8620804 100644 --- a/src/uqtestfuns/test_functions/damped_oscillator.py +++ b/src/uqtestfuns/test_functions/damped_oscillator.py @@ -41,155 +41,161 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ( + ProbInputSpecs, + FunParamSpecs, + MarginalSpecs, +) +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC from .utils import lognorm2norm_mean, lognorm2norm_std __all__ = ["DampedOscillator", "DampedOscillatorReliability"] -INPUT_MARGINALS_DERKIUREGHIAN1991 = [ # From [2] - UnivDistSpec( - name="Mp", - distribution="lognormal", - parameters=[ + +MARGINALS_DERKIUREGHIAN1991: MarginalSpecs = [ # From [2] + { + "name": "Mp", + "distribution": "lognormal", + "parameters": [ lognorm2norm_mean(1.5, 0.1 * 1.5), lognorm2norm_std(1.5, 0.1 * 1.5), ], - description="Primary mass", - ), - UnivDistSpec( - name="Ms", - distribution="lognormal", - parameters=[ + "description": "Primary mass", + }, + { + "name": "Ms", + "distribution": "lognormal", + "parameters": [ lognorm2norm_mean(0.01, 0.1 * 0.01), lognorm2norm_std(0.01, 0.1 * 0.01), ], - description="Secondary mass", - ), - UnivDistSpec( - name="Kp", - distribution="lognormal", - parameters=[ + "description": "Secondary mass", + }, + { + "name": "Kp", + "distribution": "lognormal", + "parameters": [ lognorm2norm_mean(1.0, 0.2 * 1.0), lognorm2norm_std(1.0, 0.2 * 1.0), ], - description="Primary spring stiffness", - ), - UnivDistSpec( - name="Ks", - distribution="lognormal", - parameters=[ + "description": "Primary spring stiffness", + }, + { + "name": "Ks", + "distribution": "lognormal", + "parameters": [ lognorm2norm_mean(0.01, 0.2 * 0.01), lognorm2norm_std(0.01, 0.2 * 0.01), ], - description="Secondary spring stiffness", - ), - UnivDistSpec( - name="Zeta_p", - distribution="lognormal", - parameters=[ + "description": "Secondary spring stiffness", + }, + { + "name": "Zeta_p", + "distribution": "lognormal", + "parameters": [ lognorm2norm_mean(0.05, 0.4 * 0.05), lognorm2norm_std(0.05, 0.4 * 0.05), ], - description="Primary damping ratio", - ), - UnivDistSpec( - name="Zeta_s", - distribution="lognormal", - parameters=[ + "description": "Primary damping ratio", + }, + { + "name": "Zeta_s", + "distribution": "lognormal", + "parameters": [ lognorm2norm_mean(0.02, 0.5 * 0.02), lognorm2norm_std(0.02, 0.5 * 0.02), ], - description="Secondary damping ratio", - ), - UnivDistSpec( - name="S0", - distribution="lognormal", - parameters=[ + "description": "Secondary damping ratio", + }, + { + "name": "S0", + "distribution": "lognormal", + "parameters": [ lognorm2norm_mean(100.0, 0.1 * 100.0), lognorm2norm_std(100.0, 0.1 * 100.0), ], - description="White noise base acceleration", - ), + "description": "White noise base acceleration", + }, ] -AVAILABLE_INPUT_SPECS_BASE = { - "DerKiureghian1991": ProbInputSpecFixDim( - name="DampedOscillator-DerKiureghian1991", - description=( +AVAILABLE_INPUTS_BASE: ProbInputSpecs = { + "DerKiureghian1991": { + "function_id": "DampedOscillator", + "description": ( "Probabilistic input model for the Damped Oscillator model " "from Der Kiureghian and De Stefano (1991)." ), - marginals=INPUT_MARGINALS_DERKIUREGHIAN1991, - copulas=None, - ), + "marginals": MARGINALS_DERKIUREGHIAN1991, + "copulas": None, + }, } -AVAILABLE_INPUT_SPECS_RELIABILITY = { - "DerKiureghian1990a": ProbInputSpecFixDim( - name="DampedOscillatorReliability-DerKiureghian1990a", - description=( +AVAILABLE_INPUTS_RELIABILITY: ProbInputSpecs = { + "DerKiureghian1990a": { + "function_id": "DampedOscillatorReliability", + "description": ( "Input model #1 for the damped oscillator reliability " "from Der Kiureghian and De Stefano (1990)" ), - marginals=INPUT_MARGINALS_DERKIUREGHIAN1991 + "marginals": MARGINALS_DERKIUREGHIAN1991 + [ - UnivDistSpec( - name="Fs", - distribution="lognormal", - parameters=[ + { + "name": "Fs", + "distribution": "lognormal", + "parameters": [ lognorm2norm_mean(15.0, 0.1 * 15.0), lognorm2norm_std(15.0, 0.1 * 15.0), ], - description="Force capacity of the secondary spring", - ), + "description": "Force capacity of the secondary spring", + }, ], - copulas=None, - ), - "DerKiureghian1990b": ProbInputSpecFixDim( - name="DampedOscillatorReliability-DerKiureghian1990b", - description=( + "copulas": None, + }, + "DerKiureghian1990b": { + "function_id": "DampedOscillatorReliability", + "description": ( "Input model #2 for the damped oscillator reliability " "from Der Kiureghian and De Stefano (1990)" ), - marginals=INPUT_MARGINALS_DERKIUREGHIAN1991 + "marginals": MARGINALS_DERKIUREGHIAN1991 + [ - UnivDistSpec( - name="Fs", - distribution="lognormal", - parameters=[ + { + "name": "Fs", + "distribution": "lognormal", + "parameters": [ lognorm2norm_mean(21.5, 0.1 * 21.5), lognorm2norm_std(21.5, 0.1 * 21.5), ], - description="Force capacity of the secondary spring", - ), + "description": "Force capacity of the secondary spring", + }, ], - copulas=None, - ), - "DerKiureghian1990c": ProbInputSpecFixDim( - name="DampedOscillatorReliability-DerKiureghian1990c", - description=( + "copulas": None, + }, + "DerKiureghian1990c": { + "function_id": "DampedOscillatorReliability", + "description": ( "Input model #3 for the damped oscillator reliability " "from Der Kiureghian and De Stefano (1990)" ), - marginals=INPUT_MARGINALS_DERKIUREGHIAN1991 + "marginals": MARGINALS_DERKIUREGHIAN1991 + [ - UnivDistSpec( - name="Fs", - distribution="lognormal", - parameters=[ + { + "name": "Fs", + "distribution": "lognormal", + "parameters": [ lognorm2norm_mean(27.5, 0.1 * 27.5), lognorm2norm_std(27.5, 0.1 * 27.5), ], - description="Force capacity of the secondary spring", - ), + "description": "Force capacity of the secondary spring", + }, ], - copulas=None, - ), + "copulas": None, + }, } -AVAILABLE_PARAMETERS_RELIABILITY = { + +AVAILABLE_PARAMETERS_RELIABILITY: FunParamSpecs = { "DerKiureghian1990": { "function_id": "DampedOscillatorReliability", "description": ( @@ -270,7 +276,7 @@ class DampedOscillator(UQTestFunABC): _description = ( "Damped oscillator model from Igusa and Der Kiureghian (1985)" ) - _available_inputs = AVAILABLE_INPUT_SPECS_BASE + _available_inputs = AVAILABLE_INPUTS_BASE _available_parameters = None _default_input_dimension = 8 @@ -311,7 +317,7 @@ class DampedOscillatorReliability(UQTestFunABC): _description = ( "Performance function from Der Kiureghian and De Stefano (1990)" ) - _available_inputs = AVAILABLE_INPUT_SPECS_RELIABILITY + _available_inputs = AVAILABLE_INPUTS_RELIABILITY _available_parameters = AVAILABLE_PARAMETERS_RELIABILITY _default_input_dimension = 8 _default_input = "DerKiureghian1990a" diff --git a/src/uqtestfuns/test_functions/flood.py b/src/uqtestfuns/test_functions/flood.py index 7a656d1..6f1e649 100644 --- a/src/uqtestfuns/test_functions/flood.py +++ b/src/uqtestfuns/test_functions/flood.py @@ -33,72 +33,73 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import MarginalSpecs, ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Flood"] -INPUT_MARGINALS_IOOSS2015 = [ # From Ref. [1] - UnivDistSpec( - name="Q", - distribution="trunc-gumbel", - parameters=[1013.0, 558.0, 500.0, 3000.0], - description="Maximum annual flow rate [m^3/s]", - ), - UnivDistSpec( - name="Ks", - distribution="trunc-normal", - parameters=[30.0, 8.0, 15.0, np.inf], - description="Strickler coefficient [m^(1/3)/s]", - ), - UnivDistSpec( - name="Zv", - distribution="triangular", - parameters=[49.0, 51.0, 50.0], - description="River downstream level [m]", - ), - UnivDistSpec( - name="Zm", - distribution="triangular", - parameters=[54.0, 56.0, 55.0], - description="River upstream level [m]", - ), - UnivDistSpec( - name="Hd", - distribution="uniform", - parameters=[7.0, 9.0], - description="Dyke height [m]", - ), - UnivDistSpec( - name="Cb", - distribution="triangular", - parameters=[55.0, 56.0, 55.5], - description="Bank level [m]", - ), - UnivDistSpec( - name="L", - distribution="triangular", - parameters=[4990.0, 5010.0, 5000.0], - description="Length of the river stretch [m]", - ), - UnivDistSpec( - name="B", - distribution="triangular", - parameters=[295.0, 305.0, 300.0], - description="River width [m]", - ), + +MARGINALS_IOOSS2015: MarginalSpecs = [ # From Ref. [1] + { + "name": "Q", + "distribution": "trunc-gumbel", + "parameters": [1013.0, 558.0, 500.0, 3000.0], + "description": "Maximum annual flow rate [m^3/s]", + }, + { + "name": "Ks", + "distribution": "trunc-normal", + "parameters": [30.0, 8.0, 15.0, np.inf], + "description": "Strickler coefficient [m^(1/3)/s]", + }, + { + "name": "Zv", + "distribution": "triangular", + "parameters": [49.0, 51.0, 50.0], + "description": "River downstream level [m]", + }, + { + "name": "Zm", + "distribution": "triangular", + "parameters": [54.0, 56.0, 55.0], + "description": "River upstream level [m]", + }, + { + "name": "Hd", + "distribution": "uniform", + "parameters": [7.0, 9.0], + "description": "Dyke height [m]", + }, + { + "name": "Cb", + "distribution": "triangular", + "parameters": [55.0, 56.0, 55.5], + "description": "Bank level [m]", + }, + { + "name": "L", + "distribution": "triangular", + "parameters": [4990.0, 5010.0, 5000.0], + "description": "Length of the river stretch [m]", + }, + { + "name": "B", + "distribution": "triangular", + "parameters": [295.0, 305.0, 300.0], + "description": "River width [m]", + }, ] -AVAILABLE_INPUT_SPECS = { - "Iooss2015": ProbInputSpecFixDim( - name="Flood-Iooss2015", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Iooss2015": { + "function_id": "Flood", + "description": ( "Probabilistic input model for the Flood model " "from Iooss and Lemaître (2015)." ), - marginals=INPUT_MARGINALS_IOOSS2015, - copulas=None, - ), + "marginals": MARGINALS_IOOSS2015, + "copulas": None, + }, } @@ -143,7 +144,7 @@ class Flood(UQTestFunABC): _tags = ["metamodeling", "sensitivity"] _description = "Flood model from Iooss and Lemaître (2015)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 8 diff --git a/src/uqtestfuns/test_functions/forrester.py b/src/uqtestfuns/test_functions/forrester.py index 9052de7..fafb233 100644 --- a/src/uqtestfuns/test_functions/forrester.py +++ b/src/uqtestfuns/test_functions/forrester.py @@ -16,28 +16,29 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Forrester2008"] -AVAILABLE_INPUT_SPECS = { - "Forrester2008": ProbInputSpecFixDim( - name="Forrester2008", - description=( + +AVAILABLE_INPUTS: ProbInputSpecs = { + "Forrester2008": { + "function_id": "Forrester2008", + "description": ( "Input specification for the 1D test function " "from Forrester et al. (2008)" ), - marginals=[ - UnivDistSpec( - name="x", - distribution="uniform", - parameters=[0, 1], - description=None, - ) + "marginals": [ + { + "name": "x", + "distribution": "uniform", + "parameters": [0, 1], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + }, } @@ -67,7 +68,7 @@ class Forrester2008(UQTestFunABC): _tags = ["optimization", "metamodeling"] _description = "One-dimensional function from Forrester et al. (2008)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 1 diff --git a/src/uqtestfuns/test_functions/four_branch.py b/src/uqtestfuns/test_functions/four_branch.py index cd05c6b..f4df679 100644 --- a/src/uqtestfuns/test_functions/four_branch.py +++ b/src/uqtestfuns/test_functions/four_branch.py @@ -34,38 +34,39 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs, FunParamSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["FourBranch"] -AVAILABLE_INPUT_SPECS = { - "Katsuki1994": ProbInputSpecFixDim( - name="FourBranch-Katsuki1994", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Katsuki1994": { + "function_id": "FourBranch", + "description": ( "Input model for the four-branch function " "from Katsuki and Frangopol (1994)" ), - marginals=[ - UnivDistSpec( - name="X1", - distribution="normal", - parameters=[0, 1], - description=None, - ), - UnivDistSpec( - name="X2", - distribution="normal", - parameters=[0, 1], - description=None, - ), + "marginals": [ + { + "name": "X1", + "distribution": "normal", + "parameters": [0, 1], + "description": None, + }, + { + "name": "X2", + "distribution": "normal", + "parameters": [0, 1], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + }, } -AVAILABLE_PARAMETERS = { + +AVAILABLE_PARAMETERS: FunParamSpecs = { "Katsuki1994": { "function_id": "FourBranch", "description": ( @@ -77,6 +78,7 @@ "keyword": "p", "value": 3.5 * np.sqrt(2), "type": float, + "description": None, }, ], }, @@ -91,6 +93,7 @@ "keyword": "p", "value": 6.0 / np.sqrt(2), "type": float, + "description": None, }, ], }, @@ -141,7 +144,7 @@ class FourBranch(UQTestFunABC): _description = ( "Series system reliability from Katsuki and Frangopol (1994)" ) - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = AVAILABLE_PARAMETERS _default_input_dimension = 2 _default_parameters = "Schueremans2005" diff --git a/src/uqtestfuns/test_functions/franke.py b/src/uqtestfuns/test_functions/franke.py index 7f9dc03..6aeab8b 100644 --- a/src/uqtestfuns/test_functions/franke.py +++ b/src/uqtestfuns/test_functions/franke.py @@ -42,42 +42,42 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Franke1", "Franke2", "Franke3", "Franke4", "Franke5", "Franke6"] -INPUT_MARGINALS_FRANKE1979 = [ # From Ref. [1] - UnivDistSpec( - name="X1", - distribution="uniform", - parameters=[0.0, 1.0], - description=None, - ), - UnivDistSpec( - name="X2", - distribution="uniform", - parameters=[0.0, 1.0], - description=None, - ), -] - -AVAILABLE_INPUT_SPECS = { - "Franke1979": ProbInputSpecFixDim( - name="Franke1979", - description=( + +AVAILABLE_INPUTS: ProbInputSpecs = { + "Franke1979": { + "function_id": "Franke", + "description": ( "Input specification for the test functions from Franke (1979)." ), - marginals=INPUT_MARGINALS_FRANKE1979, - copulas=None, - ), + "marginals": [ + { + "name": "X1", + "distribution": "uniform", + "parameters": [0.0, 1.0], + "description": None, + }, + { + "name": "X2", + "distribution": "uniform", + "parameters": [0.0, 1.0], + "description": None, + }, + ], + "copulas": None, + }, } + DEFAULT_INPUT_SELECTION = "Franke1979" COMMON_METADATA = dict( _tags=["metamodeling"], - _available_inputs=AVAILABLE_INPUT_SPECS, + _available_inputs=AVAILABLE_INPUTS, _available_parameters=None, _default_input_dimension=2, _description="from Franke (1979)", diff --git a/src/uqtestfuns/test_functions/friedman.py b/src/uqtestfuns/test_functions/friedman.py index 8d81dd4..2b23da3 100644 --- a/src/uqtestfuns/test_functions/friedman.py +++ b/src/uqtestfuns/test_functions/friedman.py @@ -26,51 +26,51 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Friedman6D", "Friedman10D"] -AVAILABLE_INPUT_SPECS_6D = { - "Friedman1983": ProbInputSpecFixDim( - name="Friedman1983", - description=( +AVAILABLE_INPUTS_6D: ProbInputSpecs = { + "Friedman1983": { + "function_id": "Friedman6D", + "description": ( "Input specification for the 6D test function " "from Friedman et al. (1983)" ), - marginals=[ - UnivDistSpec( - name=f"x_{i + 1}", - distribution="uniform", - parameters=[0, 1], - description=None, - ) + "marginals": [ + { + "name": f"x_{i + 1}", + "distribution": "uniform", + "parameters": [0, 1], + "description": None, + } for i in range(6) ], - copulas=None, - ), + "copulas": None, + }, } -AVAILABLE_INPUT_SPECS_10D = { - "Friedman1983": ProbInputSpecFixDim( - name="Friedman1991", - description=( +AVAILABLE_INPUTS_10D: ProbInputSpecs = { + "Friedman1983": { + "function_id": "Friedman10D", + "description": ( "Input specification for the 6D test function " "from Friedman (1991)" ), - marginals=[ - UnivDistSpec( - name=f"x_{i + 1}", - distribution="uniform", - parameters=[0, 1], - description=None, - ) + "marginals": [ + { + "name": f"x_{i + 1}", + "distribution": "uniform", + "parameters": [0, 1], + "description": None, + } for i in range(10) ], - copulas=None, - ), + "copulas": None, + }, } @@ -103,7 +103,7 @@ class Friedman6D(UQTestFunABC): _tags = ["metamodeling", "sensitivity"] _description = "Six-dimensional function from Friedman et al. (1983)" - _available_inputs = AVAILABLE_INPUT_SPECS_6D + _available_inputs = AVAILABLE_INPUTS_6D _available_parameters = None _default_input_dimension = 6 @@ -115,7 +115,7 @@ class Friedman10D(UQTestFunABC): _tags = ["metamodeling"] _description = "Ten-dimensional function from Friedman (1991)" - _available_inputs = AVAILABLE_INPUT_SPECS_10D + _available_inputs = AVAILABLE_INPUTS_10D _available_parameters = None _default_input_dimension = 10 diff --git a/src/uqtestfuns/test_functions/gayton_hat.py b/src/uqtestfuns/test_functions/gayton_hat.py index 7938fd5..cfc83af 100644 --- a/src/uqtestfuns/test_functions/gayton_hat.py +++ b/src/uqtestfuns/test_functions/gayton_hat.py @@ -16,35 +16,35 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["GaytonHat"] -AVAILABLE_INPUT_SPECS = { - "Echard2013": ProbInputSpecFixDim( - name="Echard2013", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Echard2013": { + "function_id": "GaytonHat", + "description": ( "Input model for the Gayton Hat function " "from Echard et al. (2013)" ), - marginals=[ - UnivDistSpec( - name="U1", - distribution="normal", - parameters=[0, 1], - description=None, - ), - UnivDistSpec( - name="U2", - distribution="normal", - parameters=[0, 1], - description=None, - ), + "marginals": [ + { + "name": "U1", + "distribution": "normal", + "parameters": [0, 1], + "description": None, + }, + { + "name": "U2", + "distribution": "normal", + "parameters": [0, 1], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + }, } @@ -75,7 +75,7 @@ class GaytonHat(UQTestFunABC): _description = ( "Two-Dimensional Gayton Hat function from Echard et al. (2013)" ) - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 2 diff --git a/src/uqtestfuns/test_functions/gramacy2007.py b/src/uqtestfuns/test_functions/gramacy2007.py index 19788c3..6866b54 100644 --- a/src/uqtestfuns/test_functions/gramacy2007.py +++ b/src/uqtestfuns/test_functions/gramacy2007.py @@ -20,28 +20,29 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Gramacy1DSine"] -AVAILABLE_INPUT_SPECS = { - "Gramacy2007": ProbInputSpecFixDim( - name="Gramacy2007", - description=( + +AVAILABLE_INPUTS: ProbInputSpecs = { + "Gramacy2007": { + "function_id": "Gramacy1DSine", + "description": ( "Input model for the one-dimensional function " "from Gramacy (2007)" ), - marginals=[ - UnivDistSpec( - name="x", - distribution="uniform", - parameters=[0.0, 20.0], - description=None, - ) + "marginals": [ + { + "name": "x", + "distribution": "uniform", + "parameters": [0.0, 20.0], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + }, } @@ -80,7 +81,7 @@ class Gramacy1DSine(UQTestFunABC): _tags = ["metamodeling"] _description = "One-dimensional sine function from Gramacy (2007)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 1 diff --git a/src/uqtestfuns/test_functions/hyper_sphere.py b/src/uqtestfuns/test_functions/hyper_sphere.py index 4c835d8..f22b9d3 100644 --- a/src/uqtestfuns/test_functions/hyper_sphere.py +++ b/src/uqtestfuns/test_functions/hyper_sphere.py @@ -15,35 +15,35 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["HyperSphere"] -AVAILABLE_INPUT_SPECS = { - "Li2018": ProbInputSpecFixDim( - name="Li2018", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Li2018": { + "function_id": "Li2018", + "description": ( "Input model for the hyper-sphere reliability problem " "from Li et al. (2018)" ), - marginals=[ - UnivDistSpec( - name="X1", - distribution="normal", - parameters=[0.5, 0.2], - description=None, - ), - UnivDistSpec( - name="X2", - distribution="normal", - parameters=[0.5, 0.2], - description=None, - ), + "marginals": [ + { + "name": "X1", + "distribution": "normal", + "parameters": [0.5, 0.2], + "description": None, + }, + { + "name": "X2", + "distribution": "normal", + "parameters": [0.5, 0.2], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + }, } @@ -74,7 +74,7 @@ class HyperSphere(UQTestFunABC): _description = ( "Hyper-sphere bound reliability problem from Li et al. (2018)" ) - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 2 diff --git a/src/uqtestfuns/test_functions/ishigami.py b/src/uqtestfuns/test_functions/ishigami.py index b986694..dbc4b77 100644 --- a/src/uqtestfuns/test_functions/ishigami.py +++ b/src/uqtestfuns/test_functions/ishigami.py @@ -30,46 +30,50 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ( + MarginalSpecs, + ProbInputSpecs, + FunParamSpecs, +) +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Ishigami"] -INPUT_MARGINALS_ISHIGAMI1991 = [ - UnivDistSpec( - name="X1", - distribution="uniform", - parameters=[-np.pi, np.pi], - description=None, - ), - UnivDistSpec( - name="X2", - distribution="uniform", - parameters=[-np.pi, np.pi], - description=None, - ), - UnivDistSpec( - name="X3", - distribution="uniform", - parameters=[-np.pi, np.pi], - description=None, - ), +MARGINALS_ISHIGAMI1991: MarginalSpecs = [ + { + "name": "X1", + "distribution": "uniform", + "parameters": [-np.pi, np.pi], + "description": None, + }, + { + "name": "X2", + "distribution": "uniform", + "parameters": [-np.pi, np.pi], + "description": None, + }, + { + "name": "X3", + "distribution": "uniform", + "parameters": [-np.pi, np.pi], + "description": None, + }, ] -AVAILABLE_INPUT_SPECS = { - "Ishigami1991": ProbInputSpecFixDim( - name="Ishigami1991", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Ishigami1991": { + "function_id": "Ishigami", + "description": ( "Probabilistic input model for the Ishigami function " "from Ishigami and Homma (1991)." ), - marginals=INPUT_MARGINALS_ISHIGAMI1991, - copulas=None, - ), + "marginals": MARGINALS_ISHIGAMI1991, + "copulas": None, + }, } -AVAILABLE_PARAMETERS = { +AVAILABLE_PARAMETERS: FunParamSpecs = { "Ishigami1991": { "function_id": "Ishigami", "description": ( @@ -81,11 +85,13 @@ "keyword": "a", "value": 7.0, "type": float, + "description": None, }, { "keyword": "b", "value": 0.1, "type": float, + "description": None, }, ], }, @@ -100,11 +106,13 @@ "keyword": "a", "value": 7.0, "type": float, + "description": None, }, { "keyword": "b", "value": 0.05, "type": float, + "description": None, }, ], }, @@ -147,7 +155,7 @@ class Ishigami(UQTestFunABC): _tags = ["sensitivity"] _description = "Ishigami function from Ishigami and Homma (1991)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = AVAILABLE_PARAMETERS _default_parameters = DEFAULT_PARAMETERS_SELECTION _default_input_dimension = 3 diff --git a/src/uqtestfuns/test_functions/mclain.py b/src/uqtestfuns/test_functions/mclain.py index 299e8ad..49b03b8 100644 --- a/src/uqtestfuns/test_functions/mclain.py +++ b/src/uqtestfuns/test_functions/mclain.py @@ -30,41 +30,40 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["McLainS1", "McLainS2", "McLainS3", "McLainS4", "McLainS5"] -INPUT_MARGINALS_MCLAIN1974 = [ # From Ref. [1] - UnivDistSpec( - name="X1", - distribution="uniform", - parameters=[1.0, 10.0], - description=None, - ), - UnivDistSpec( - name="X2", - distribution="uniform", - parameters=[1.0, 10.0], - description=None, - ), -] - -AVAILABLE_INPUT_SPECS = { - "McLain1974": ProbInputSpecFixDim( - name="McLain-1974", - description=( + +AVAILABLE_INPUTS: ProbInputSpecs = { + "McLain1974": { + "function_id": "McLain", + "description": ( "Input specification for the McLain's test functions " "from McLain (1974)." ), - marginals=INPUT_MARGINALS_MCLAIN1974, - copulas=None, - ), + "marginals": [ # From Ref. [1] + { + "name": "X1", + "distribution": "uniform", + "parameters": [1.0, 10.0], + "description": None, + }, + { + "name": "X2", + "distribution": "uniform", + "parameters": [1.0, 10.0], + "description": None, + }, + ], + "copulas": None, + }, } COMMON_METADATA = dict( _tags=["metamodeling"], - _available_inputs=AVAILABLE_INPUT_SPECS, + _available_inputs=AVAILABLE_INPUTS, _available_parameters=None, _default_input_dimension=2, _description="from McLain (1974)", diff --git a/src/uqtestfuns/test_functions/oakley2002.py b/src/uqtestfuns/test_functions/oakley2002.py index 8ff0ced..b02bead 100644 --- a/src/uqtestfuns/test_functions/oakley2002.py +++ b/src/uqtestfuns/test_functions/oakley2002.py @@ -17,28 +17,29 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Oakley1D"] -AVAILABLE_INPUT_SPECS = { - "Oakley2002": ProbInputSpecFixDim( - name="Oakley2002", - description=( + +AVAILABLE_INPUTS: ProbInputSpecs = { + "Oakley2002": { + "function_id": "Oakley1D", + "description": ( "Probabilistic input model for the one-dimensional function " "from Oakley and O'Hagan (2002)" ), - marginals=[ - UnivDistSpec( - name="x", - distribution="normal", - parameters=[0.0, 4.0], - description=None, - ) + "marginals": [ + { + "name": "x", + "distribution": "normal", + "parameters": [0.0, 4.0], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + }, } @@ -68,7 +69,7 @@ class Oakley1D(UQTestFunABC): _tags = ["metamodeling"] _description = "One-dimensional function from Oakley and O'Hagan (2002)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 1 diff --git a/src/uqtestfuns/test_functions/otl_circuit.py b/src/uqtestfuns/test_functions/otl_circuit.py index 946d889..ff17cbf 100644 --- a/src/uqtestfuns/test_functions/otl_circuit.py +++ b/src/uqtestfuns/test_functions/otl_circuit.py @@ -23,82 +23,83 @@ import numpy as np -from copy import copy +from copy import deepcopy -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import MarginalSpecs, ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["OTLCircuit"] -INPUT_MARGINALS_BENARI2007 = [ - UnivDistSpec( - name="Rb1", - distribution="uniform", - parameters=[50.0, 150.0], - description="Resistance b1 [kOhm]", - ), - UnivDistSpec( - name="Rb2", - distribution="uniform", - parameters=[25.0, 70.0], - description="Resistance b2 [kOhm]", - ), - UnivDistSpec( - name="Rf", - distribution="uniform", - parameters=[0.5, 3.0], - description="Resistance f [kOhm]", - ), - UnivDistSpec( - name="Rc1", - distribution="uniform", - parameters=[1.2, 2.5], - description="Resistance c1 [kOhm]", - ), - UnivDistSpec( - name="Rc2", - distribution="uniform", - parameters=[0.25, 1.20], - description="Resistance c2 [kOhm]", - ), - UnivDistSpec( - name="beta", - distribution="uniform", - parameters=[50.0, 300.0], - description="Current gain [A]", - ), + +MARGINALS_BENARI2007: MarginalSpecs = [ + { + "name": "Rb1", + "distribution": "uniform", + "parameters": [50.0, 150.0], + "description": "Resistance b1 [kOhm]", + }, + { + "name": "Rb2", + "distribution": "uniform", + "parameters": [25.0, 70.0], + "description": "Resistance b2 [kOhm]", + }, + { + "name": "Rf", + "distribution": "uniform", + "parameters": [0.5, 3.0], + "description": "Resistance f [kOhm]", + }, + { + "name": "Rc1", + "distribution": "uniform", + "parameters": [1.2, 2.5], + "description": "Resistance c1 [kOhm]", + }, + { + "name": "Rc2", + "distribution": "uniform", + "parameters": [0.25, 1.20], + "description": "Resistance c2 [kOhm]", + }, + { + "name": "beta", + "distribution": "uniform", + "parameters": [50.0, 300.0], + "description": "Current gain [A]", + }, ] -INPUT_MARGINALS_MOON2010 = [copy(_) for _ in INPUT_MARGINALS_BENARI2007] +MARGINALS_MOON2010 = [deepcopy(_) for _ in MARGINALS_BENARI2007] for i in range(14): - INPUT_MARGINALS_MOON2010.append( - UnivDistSpec( - name=f"Inert {i+1}", - distribution="uniform", - parameters=[100.0, 200.0], - description="Inert input [-]", - ) + MARGINALS_MOON2010.append( + { + "name": f"Inert {i+1}", + "distribution": "uniform", + "parameters": [100.0, 200.0], + "description": "Inert input [-]", + }, ) -AVAILABLE_INPUT_SPECS = { - "BenAri2007": ProbInputSpecFixDim( - name="OTLCircuit-BenAri2007", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "BenAri2007": { + "function_id": "OTLCircuit", + "description": ( "Probabilistic input model for the OTL Circuit function " "from Ben-Ari and Steinberg (2007)." ), - marginals=INPUT_MARGINALS_BENARI2007, - copulas=None, - ), - "Moon2010": ProbInputSpecFixDim( - name="OTLCircuit-Moon2010", - description=( + "marginals": MARGINALS_BENARI2007, + "copulas": None, + }, + "Moon2010": { + "function_id": "OTLCircuit", + "description": ( "Probabilistic input model for the OTL Circuit function " "from Moon (2010)." ), - marginals=INPUT_MARGINALS_MOON2010, - copulas=None, - ), + "marginals": MARGINALS_MOON2010, + "copulas": None, + }, } DEFAULT_INPUT_SELECTION = "BenAri2007" @@ -156,7 +157,7 @@ class OTLCircuit(UQTestFunABC): "Output transformerless (OTL) circuit model " "from Ben-Ari and Steinberg (2007)" ) - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input = DEFAULT_INPUT_SELECTION diff --git a/src/uqtestfuns/test_functions/piston.py b/src/uqtestfuns/test_functions/piston.py index 7bc6db1..c101105 100644 --- a/src/uqtestfuns/test_functions/piston.py +++ b/src/uqtestfuns/test_functions/piston.py @@ -23,90 +23,91 @@ import numpy as np -from copy import copy +from copy import deepcopy -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import MarginalSpecs, ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Piston"] + # Marginals specification from [1] -INPUT_MARGINALS_BENARI2007 = [ - UnivDistSpec( - name="M", - distribution="uniform", - parameters=[30.0, 60.0], - description="Piston weight [kg]", - ), - UnivDistSpec( - name="S", - distribution="uniform", - parameters=[0.005, 0.020], - description="Piston surface area [m^2]", - ), - UnivDistSpec( - name="V0", - distribution="uniform", - parameters=[0.002, 0.010], - description="Initial gas volume [m^3]", - ), - UnivDistSpec( - name="k", - distribution="uniform", - parameters=[1000.0, 5000.0], - description="Spring coefficient [N/m]", - ), - UnivDistSpec( - name="P0", - distribution="uniform", - parameters=[90000.0, 110000.0], - description="Atmospheric pressure [N/m^2]", - ), - UnivDistSpec( - name="Ta", - distribution="uniform", - parameters=[290.0, 296.0], - description="Ambient temperature [K]", - ), - UnivDistSpec( - name="T0", - distribution="uniform", - parameters=[340.0, 360.0], - description="Filling gas temperature [K]", - ), +MARGINALS_BENARI2007: MarginalSpecs = [ + { + "name": "M", + "distribution": "uniform", + "parameters": [30.0, 60.0], + "description": "Piston weight [kg]", + }, + { + "name": "S", + "distribution": "uniform", + "parameters": [0.005, 0.020], + "description": "Piston surface area [m^2]", + }, + { + "name": "V0", + "distribution": "uniform", + "parameters": [0.002, 0.010], + "description": "Initial gas volume [m^3]", + }, + { + "name": "k", + "distribution": "uniform", + "parameters": [1000.0, 5000.0], + "description": "Spring coefficient [N/m]", + }, + { + "name": "P0", + "distribution": "uniform", + "parameters": [90000.0, 110000.0], + "description": "Atmospheric pressure [N/m^2]", + }, + { + "name": "Ta", + "distribution": "uniform", + "parameters": [290.0, 296.0], + "description": "Ambient temperature [K]", + }, + { + "name": "T0", + "distribution": "uniform", + "parameters": [340.0, 360.0], + "description": "Filling gas temperature [K]", + }, ] # Marginals specification from [2] -INPUT_MARGINALS_MOON2010 = [copy(_) for _ in INPUT_MARGINALS_BENARI2007] +MARGINALS_MOON2010 = [deepcopy(_) for _ in MARGINALS_BENARI2007] for i in range(13): - INPUT_MARGINALS_MOON2010.append( - UnivDistSpec( - name=f"Inert {i+1}", - distribution="uniform", - parameters=[100.0, 200.0], - description="Inert input [-]", - ) + MARGINALS_MOON2010.append( + { + "name": f"Inert {i+1}", + "distribution": "uniform", + "parameters": [100.0, 200.0], + "description": "Inert input [-]", + } ) -AVAILABLE_INPUT_SPECS = { - "BenAri2007": ProbInputSpecFixDim( - name="Piston-BenAri2007", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "BenAri2007": { + "function_id": "Piston", + "description": ( "Probabilistic input model for the Piston simulation model " "from Ben-Ari and Steinberg (2007)." ), - marginals=INPUT_MARGINALS_BENARI2007, - copulas=None, - ), - "Moon2010": ProbInputSpecFixDim( - name="Piston-Moon2010", - description=( + "marginals": MARGINALS_BENARI2007, + "copulas": None, + }, + "Moon2010": { + "function_id": "Piston", + "description": ( "Probabilistic input model for the Piston simulation model " "from Moon (2010)." ), - marginals=INPUT_MARGINALS_MOON2010, - copulas=None, - ), + "marginals": MARGINALS_MOON2010, + "copulas": None, + }, } DEFAULT_INPUT_SELECTION = "BenAri2007" @@ -165,7 +166,7 @@ class Piston(UQTestFunABC): _tags = ["metamodeling", "sensitivity"] _description = "Piston simulation model from Ben-Ari and Steinberg (2007)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 7 _default_input = DEFAULT_INPUT_SELECTION diff --git a/src/uqtestfuns/test_functions/portfolio_3d.py b/src/uqtestfuns/test_functions/portfolio_3d.py index 9c624b9..bd83143 100644 --- a/src/uqtestfuns/test_functions/portfolio_3d.py +++ b/src/uqtestfuns/test_functions/portfolio_3d.py @@ -15,47 +15,51 @@ import numpy as np +from uqtestfuns.core.custom_typing import ( + MarginalSpecs, + ProbInputSpecs, + FunParamSpecs, +) +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC __all__ = ["Portfolio3D"] -INPUT_MARGINALS_SALTELLI2004 = [ - UnivDistSpec( - name="Ps", - distribution="normal", - parameters=[0.0, 4.0], - description="Hedged portfolio 's' [\N{euro sign}]", - ), - UnivDistSpec( - name="Pt", - distribution="normal", - parameters=[0.0, 2.0], - description="Hedged portfolio 't' [\N{euro sign}]", - ), - UnivDistSpec( - name="Pj", - distribution="normal", - parameters=[0.0, 1.0], - description="Hedged portfolio 'j' [\N{euro sign}]", - ), +MARGINALS_SALTELLI2004: MarginalSpecs = [ + { + "name": "Ps", + "distribution": "normal", + "parameters": [0.0, 4.0], + "description": "Hedged portfolio 's' [\N{euro sign}]", + }, + { + "name": "Pt", + "distribution": "normal", + "parameters": [0.0, 2.0], + "description": "Hedged portfolio 't' [\N{euro sign}]", + }, + { + "name": "Pj", + "distribution": "normal", + "parameters": [0.0, 1.0], + "description": "Hedged portfolio 'j' [\N{euro sign}]", + }, ] -AVAILABLE_INPUT_SPECS = { - "Saltelli2004": ProbInputSpecFixDim( - name="Portfolio3D-Saltelli2004", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Saltelli2004": { + "function_id": "Portfolio3D", + "description": ( "Probabilistic input model for the simple portfolio model " "from Saltelli et al. (2004)." ), - marginals=INPUT_MARGINALS_SALTELLI2004, - copulas=None, - ), + "marginals": MARGINALS_SALTELLI2004, + "copulas": None, + }, } -AVAILABLE_PARAMETERS = { +AVAILABLE_PARAMETERS: FunParamSpecs = { "Saltelli2004-1": { "function_id": "Portfolio3D", "description": ( @@ -180,7 +184,7 @@ class Portfolio3D(UQTestFunABC): _tags = ["sensitivity"] _description = "Simple portfolio model from Saltelli et al. (2004)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = AVAILABLE_PARAMETERS _default_parameters = DEFAULT_PARAMETERS_SELECTION _default_input_dimension = 3 diff --git a/src/uqtestfuns/test_functions/rs_circular_bar.py b/src/uqtestfuns/test_functions/rs_circular_bar.py index a95a0f9..d3a05b7 100644 --- a/src/uqtestfuns/test_functions/rs_circular_bar.py +++ b/src/uqtestfuns/test_functions/rs_circular_bar.py @@ -14,36 +14,38 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs, FunParamSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC + __all__ = ["RSCircularBar"] -AVAILABLE_INPUT_SPECS = { - "Verma2016": ProbInputSpecFixDim( - name="RSCircularBar-Verma2016", - description=( + +AVAILABLE_INPUTS: ProbInputSpecs = { + "Verma2016": { + "function_id": "RSCircularBar", + "description": ( "Input model for the circular bar RS from Verma et al. (2016)" ), - marginals=[ - UnivDistSpec( - name="Y", - distribution="normal", - parameters=[250.0, 25.0], - description="Material mean yield strength [MPa]", - ), - UnivDistSpec( - name="F", - distribution="normal", - parameters=[70.0, 7.0], - description="Force mean value [kN]", - ), + "marginals": [ + { + "name": "Y", + "distribution": "normal", + "parameters": [250.0, 25.0], + "description": "Material mean yield strength [MPa]", + }, + { + "name": "F", + "distribution": "normal", + "parameters": [70.0, 7.0], + "description": "Force mean value [kN]", + }, ], - copulas=None, - ), + "copulas": None, + }, } -AVAILABLE_PARAMETERS = { +AVAILABLE_PARAMETERS: FunParamSpecs = { "Verma2016": { "function_id": "RSCircularBar", "description": ( @@ -96,7 +98,7 @@ class RSCircularBar(UQTestFunABC): _tags = ["reliability"] _description = "RS problem as a circular bar from Verma et al. (2016)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = AVAILABLE_PARAMETERS _default_input_dimension = 2 diff --git a/src/uqtestfuns/test_functions/rs_quadratic.py b/src/uqtestfuns/test_functions/rs_quadratic.py index a348bb5..d5b0bf5 100644 --- a/src/uqtestfuns/test_functions/rs_quadratic.py +++ b/src/uqtestfuns/test_functions/rs_quadratic.py @@ -14,31 +14,32 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["RSQuadratic"] -AVAILABLE_INPUT_SPECS = { - "Waarts2000": ProbInputSpecFixDim( - name="RSQuadratic-Waarts2000", - description="Input model for the quadratic RS from Waarts (2000)", - marginals=[ - UnivDistSpec( - name="X1", - distribution="normal", - parameters=[11.0, 1.0], - description=None, - ), - UnivDistSpec( - name="X2", - distribution="normal", - parameters=[1.5, 0.5], - description=None, - ), + +AVAILABLE_INPUTS: ProbInputSpecs = { + "Waarts2000": { + "function_id": "RSQuadratic", + "description": "Input model for the quadratic RS from Waarts (2000)", + "marginals": [ + { + "name": "X1", + "distribution": "normal", + "parameters": [11.0, 1.0], + "description": None, + }, + { + "name": "X2", + "distribution": "normal", + "parameters": [1.5, 0.5], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + }, } @@ -70,7 +71,7 @@ class RSQuadratic(UQTestFunABC): _tags = ["reliability"] _description = "RS problem w/ one quadratic term from Waarts (2000)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 2 diff --git a/src/uqtestfuns/test_functions/sobol_g.py b/src/uqtestfuns/test_functions/sobol_g.py index ed08779..219ebc1 100644 --- a/src/uqtestfuns/test_functions/sobol_g.py +++ b/src/uqtestfuns/test_functions/sobol_g.py @@ -58,52 +58,29 @@ import numpy as np -from typing import List - -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecVarDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs, FunParamSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["SobolG"] -def _create_sobol_input(input_dimension: int) -> List[UnivDistSpec]: - """Construct an input instance for a given dimension according to [1]. - - Parameters - ---------- - input_dimension : int - The number of marginals to be created. - - Returns - ------- - List[UnivDistSpec] - A list of M marginals as UnivariateInput instances to construct - the MultivariateInput. - """ - marginals = [] - for i in range(input_dimension): - marginals.append( - UnivDistSpec( - name=f"X{i + 1}", - distribution="uniform", - parameters=[0.0, 1.0], - description=None, - ) - ) - - return marginals - - -AVAILABLE_INPUT_SPECS = { - "Saltelli1995": ProbInputSpecVarDim( - name="Sobol-G-Saltelli1995", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Saltelli1995": { + "function_id": "Sobol-G", + "description": ( "Probabilistic input model for the Sobol'-G function " "from Saltelli and Sobol' (1995)" ), - marginals_generator=_create_sobol_input, - copulas=None, - ), + "marginals": [ + { + "name": "X", + "distribution": "uniform", + "parameters": [0.0, 1.0], + "description": None, + }, + ], + "copulas": None, + }, } DEFAULT_INPUT_SELECTION = "Saltelli1995" @@ -238,7 +215,7 @@ def _get_params_kucherenko_2011_3b(input_dimension: int) -> np.ndarray: return yy -AVAILABLE_PARAMETERS = { +AVAILABLE_PARAMETERS: FunParamSpecs = { "Saltelli1995-1": { "function_id": "SobolG", "description": ( @@ -414,7 +391,7 @@ class SobolG(UQTestFunABC): _tags = ["sensitivity", "integration"] _description = "Sobol'-G function from Saltelli and Sobol' (1995)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = AVAILABLE_PARAMETERS _default_parameters = DEFAULT_PARAMETERS_SELECTION _default_input_dimension = None diff --git a/src/uqtestfuns/test_functions/speed_reducer_shaft.py b/src/uqtestfuns/test_functions/speed_reducer_shaft.py index 7b02ff6..e429aa6 100644 --- a/src/uqtestfuns/test_functions/speed_reducer_shaft.py +++ b/src/uqtestfuns/test_functions/speed_reducer_shaft.py @@ -23,54 +23,54 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC from .utils import gumbel_max_mu, gumbel_max_beta __all__ = ["SpeedReducerShaft"] -AVAILABLE_INPUT_SPECS = { - "Du2004": ProbInputSpecFixDim( - name="SpeedReducerShaft-Du2004", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Du2004": { + "function_id": "SpeedReducerShaft", + "description": ( "Input model for the speed reducer shaft problem " "from Du and Sudjianto (2004)" ), - marginals=[ - UnivDistSpec( - name="D", - distribution="normal", - parameters=[39, 0.1], - description="Shaft diameter [mm]", - ), - UnivDistSpec( - name="L", - distribution="normal", - parameters=[400, 0.1], - description="Shaft span [mm]", - ), - UnivDistSpec( - name="F", - distribution="gumbel", - parameters=[gumbel_max_mu(1500, 350), gumbel_max_beta(350)], - description="External force [N]", - ), - UnivDistSpec( - name="T", - distribution="normal", - parameters=[250, 35], - description="Torque [Nm]", - ), - UnivDistSpec( - name="S", - distribution="uniform", - parameters=[70, 80], - description="Strength [MPa]", - ), + "marginals": [ + { + "name": "D", + "distribution": "normal", + "parameters": [39, 0.1], + "description": "Shaft diameter [mm]", + }, + { + "name": "L", + "distribution": "normal", + "parameters": [400, 0.1], + "description": "Shaft span [mm]", + }, + { + "name": "F", + "distribution": "gumbel", + "parameters": [gumbel_max_mu(1500, 350), gumbel_max_beta(350)], + "description": "External force [N]", + }, + { + "name": "T", + "distribution": "normal", + "parameters": [250, 35], + "description": "Torque [Nm]", + }, + { + "name": "S", + "distribution": "uniform", + "parameters": [70, 80], + "description": "Strength [MPa]", + }, ], - copulas=None, - ), + "copulas": None, + }, } @@ -112,7 +112,7 @@ class SpeedReducerShaft(UQTestFunABC): "Reliability of a shaft in a speed reducer " "from Du and Sudjianto (2004)" ) - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 5 diff --git a/src/uqtestfuns/test_functions/sulfur.py b/src/uqtestfuns/test_functions/sulfur.py index 7b7e4e2..2673815 100644 --- a/src/uqtestfuns/test_functions/sulfur.py +++ b/src/uqtestfuns/test_functions/sulfur.py @@ -61,80 +61,83 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import MarginalSpecs, ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Sulfur"] -INPUT_MARGINALS_PENNER1994 = [ # From [3] (Table 2) - UnivDistSpec( - name="Q", - distribution="lognormal", - parameters=[np.log(71.0), np.log(1.15)], - description="Source strength of anthropogenic Sulfur [10^12 g/year]", - ), - UnivDistSpec( - name="Y", - distribution="lognormal", - parameters=[np.log(0.5), np.log(1.5)], - description="Fraction of SO2 oxidized to SO4(2-) aerosol [-]", - ), - UnivDistSpec( - name="L", - distribution="lognormal", - parameters=[np.log(5.5), np.log(1.5)], - description="Average lifetime of atmospheric SO4(2-) [days]", - ), - UnivDistSpec( - name="Psi_e", - distribution="lognormal", - parameters=[np.log(5.0), np.log(1.4)], - description="Aerosol mass scattering efficiency [m^2/g]", - ), - UnivDistSpec( - name="beta", - distribution="lognormal", - parameters=[np.log(0.3), np.log(1.3)], - description="Fraction of light scattered upward hemisphere [-]", - ), - UnivDistSpec( - name="f_Psi_e", - distribution="lognormal", - parameters=[np.log(1.7), np.log(1.2)], - description="Fractional increase in aerosol scattering efficiency " + +MARGINALS_PENNER1994: MarginalSpecs = [ # From [3] (Table 2) + { + "name": "Q", + "distribution": "lognormal", + "parameters": [np.log(71.0), np.log(1.15)], + "description": ( + "Source strength of anthropogenic Sulfur [10^12 g/year]" + ), + }, + { + "name": "Y", + "distribution": "lognormal", + "parameters": [np.log(0.5), np.log(1.5)], + "description": "Fraction of SO2 oxidized to SO4(2-) aerosol [-]", + }, + { + "name": "L", + "distribution": "lognormal", + "parameters": [np.log(5.5), np.log(1.5)], + "description": "Average lifetime of atmospheric SO4(2-) [days]", + }, + { + "name": "Psi_e", + "distribution": "lognormal", + "parameters": [np.log(5.0), np.log(1.4)], + "description": "Aerosol mass scattering efficiency [m^2/g]", + }, + { + "name": "beta", + "distribution": "lognormal", + "parameters": [np.log(0.3), np.log(1.3)], + "description": "Fraction of light scattered upward hemisphere [-]", + }, + { + "name": "f_Psi_e", + "distribution": "lognormal", + "parameters": [np.log(1.7), np.log(1.2)], + "description": "Fractional increase in aerosol scattering efficiency " "due to hygroscopic growth [-]", - ), - UnivDistSpec( - name="T^2", - distribution="lognormal", - parameters=[np.log(0.58), np.log(1.4)], - description="Square of atmospheric " + }, + { + "name": "T^2", + "distribution": "lognormal", + "parameters": [np.log(0.58), np.log(1.4)], + "description": "Square of atmospheric " "transmittance above aerosol layer [-]", - ), - UnivDistSpec( - name="(1-Ac)", - distribution="lognormal", - parameters=[np.log(0.39), np.log(1.1)], - description="Fraction of earth not covered by cloud [-]", - ), - UnivDistSpec( - name="(1-Rs)^2", - distribution="lognormal", - parameters=[np.log(0.72), np.log(1.2)], - description="Square of surface coalbedo [-]", - ), + }, + { + "name": "(1-Ac)", + "distribution": "lognormal", + "parameters": [np.log(0.39), np.log(1.1)], + "description": "Fraction of earth not covered by cloud [-]", + }, + { + "name": "(1-Rs)^2", + "distribution": "lognormal", + "parameters": [np.log(0.72), np.log(1.2)], + "description": "Square of surface coalbedo [-]", + }, ] -AVAILABLE_INPUT_SPECS = { - "Penner1994": ProbInputSpecFixDim( - name="Sulfur-Penner1994", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Penner1994": { + "function_id": "Sulfur", + "description": ( "Probabilistic input model for the Sulfur model " "from Penner et al. (1994)." ), - marginals=INPUT_MARGINALS_PENNER1994, - copulas=None, - ), + "marginals": MARGINALS_PENNER1994, + "copulas": None, + }, } DEFAULT_INPUT_SELECTION = "Penner1994" @@ -199,7 +202,7 @@ class Sulfur(UQTestFunABC): _tags = ["metamodeling", "sensitivity"] _description = "Sulfur model from Charlson et al. (1992)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 9 diff --git a/src/uqtestfuns/test_functions/webster.py b/src/uqtestfuns/test_functions/webster.py index 4a44070..5890d09 100644 --- a/src/uqtestfuns/test_functions/webster.py +++ b/src/uqtestfuns/test_functions/webster.py @@ -16,35 +16,35 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Webster2D"] -AVAILABLE_INPUT_SPECS = { - "Webster1996": ProbInputSpecFixDim( - name="Webster1996", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Webster1996": { + "function_id": "Webster2D", + "description": ( "Input specification for the 2D function " "from Webster et al. (1996)" ), - marginals=[ - UnivDistSpec( - name="A", - distribution="uniform", - parameters=[1.0, 10.0], - description=None, - ), - UnivDistSpec( - name="B", - distribution="normal", - parameters=[2.0, 1.0], - description=None, - ), + "marginals": [ + { + "name": "A", + "distribution": "uniform", + "parameters": [1.0, 10.0], + "description": None, + }, + { + "name": "B", + "distribution": "normal", + "parameters": [2.0, 1.0], + "description": None, + }, ], - copulas=None, - ), + "copulas": None, + }, } @@ -73,7 +73,7 @@ class Webster2D(UQTestFunABC): _tags = ["metamodeling"] _description = "2D polynomial function from Webster et al. (1996)." - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 2 diff --git a/src/uqtestfuns/test_functions/welch1992.py b/src/uqtestfuns/test_functions/welch1992.py index 466993d..c86415f 100644 --- a/src/uqtestfuns/test_functions/welch1992.py +++ b/src/uqtestfuns/test_functions/welch1992.py @@ -21,34 +21,35 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import MarginalSpecs, ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC __all__ = ["Welch1992"] -INPUT_MARGINALS_WELCH1992 = [ - UnivDistSpec( - name=f"x{i}", - distribution="uniform", - parameters=[-0.5, 0.5], - description=None, - ) +MARGINALS_WELCH1992: MarginalSpecs = [ + { + "name": f"x{i}", + "distribution": "uniform", + "parameters": [-0.5, 0.5], + "description": None, + } for i in range(1, 20 + 1) ] -AVAILABLE_INPUT_SPECS = { - "Welch1992": ProbInputSpecFixDim( - name="Welch1992", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Welch1992": { + "function_id": "Welch1992", + "description": ( "Input specification for the test function " "from Welch et al. (1992)" ), - marginals=INPUT_MARGINALS_WELCH1992, - copulas=None, - ), + "marginals": MARGINALS_WELCH1992, + "copulas": None, + }, } + DEFAULT_INPUT_SELECTION = "Welch1992" @@ -100,7 +101,7 @@ class Welch1992(UQTestFunABC): _tags = ["metamodeling", "sensitivity", "integration"] _description = "20-Dimensional function from Welch et al. (1992)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 20 diff --git a/src/uqtestfuns/test_functions/wing_weight.py b/src/uqtestfuns/test_functions/wing_weight.py index 69724b4..48784f9 100644 --- a/src/uqtestfuns/test_functions/wing_weight.py +++ b/src/uqtestfuns/test_functions/wing_weight.py @@ -22,85 +22,86 @@ import numpy as np -from ..core.prob_input.input_spec import UnivDistSpec, ProbInputSpecFixDim -from ..core.uqtestfun_abc import UQTestFunABC +from uqtestfuns.core.custom_typing import MarginalSpecs, ProbInputSpecs +from uqtestfuns.core.uqtestfun_abc import UQTestFunABC from .utils import deg2rad __all__ = ["WingWeight"] -INPUT_MARGINALS_FORRESTER2008 = [ - UnivDistSpec( - name="Sw", - distribution="uniform", - parameters=[150.0, 200.0], - description="wing area [ft^2]", - ), - UnivDistSpec( - name="Wfw", - distribution="uniform", - parameters=[220.0, 300.0], - description="weight of fuel in the wing [lb]", - ), - UnivDistSpec( - name="A", - distribution="uniform", - parameters=[6.0, 10.0], - description="aspect ratio [-]", - ), - UnivDistSpec( - name="Lambda", - distribution="uniform", - parameters=[-10.0, 10.0], - description="quarter-chord sweep [degrees]", - ), - UnivDistSpec( - name="q", - distribution="uniform", - parameters=[16.0, 45.0], - description="dynamic pressure at cruise [lb/ft^2]", - ), - UnivDistSpec( - name="lambda", - distribution="uniform", - parameters=[0.5, 1.0], - description="taper ratio [-]", - ), - UnivDistSpec( - name="tc", - distribution="uniform", - parameters=[0.08, 0.18], - description="aerofoil thickness to chord ratio [-]", - ), - UnivDistSpec( - name="Nz", - distribution="uniform", - parameters=[2.5, 6.0], - description="ultimate load factor [-]", - ), - UnivDistSpec( - name="Wdg", - distribution="uniform", - parameters=[1700, 2500], - description="flight design gross weight [lb]", - ), - UnivDistSpec( - name="Wp", - distribution="uniform", - parameters=[0.025, 0.08], - description="paint weight [lb/ft^2]", - ), + +MARGINALS_FORRESTER2008: MarginalSpecs = [ + { + "name": "Sw", + "distribution": "uniform", + "parameters": [150.0, 200.0], + "description": "wing area [ft^2]", + }, + { + "name": "Wfw", + "distribution": "uniform", + "parameters": [220.0, 300.0], + "description": "weight of fuel in the wing [lb]", + }, + { + "name": "A", + "distribution": "uniform", + "parameters": [6.0, 10.0], + "description": "aspect ratio [-]", + }, + { + "name": "Lambda", + "distribution": "uniform", + "parameters": [-10.0, 10.0], + "description": "quarter-chord sweep [degrees]", + }, + { + "name": "q", + "distribution": "uniform", + "parameters": [16.0, 45.0], + "description": "dynamic pressure at cruise [lb/ft^2]", + }, + { + "name": "lambda", + "distribution": "uniform", + "parameters": [0.5, 1.0], + "description": "taper ratio [-]", + }, + { + "name": "tc", + "distribution": "uniform", + "parameters": [0.08, 0.18], + "description": "aerofoil thickness to chord ratio [-]", + }, + { + "name": "Nz", + "distribution": "uniform", + "parameters": [2.5, 6.0], + "description": "ultimate load factor [-]", + }, + { + "name": "Wdg", + "distribution": "uniform", + "parameters": [1700, 2500], + "description": "flight design gross weight [lb]", + }, + { + "name": "Wp", + "distribution": "uniform", + "parameters": [0.025, 0.08], + "description": "paint weight [lb/ft^2]", + }, ] -AVAILABLE_INPUT_SPECS = { - "Forrester2008": ProbInputSpecFixDim( - name="Wing-Weight-Forrester-2008", - description=( +AVAILABLE_INPUTS: ProbInputSpecs = { + "Forrester2008": { + "function_id": "WingWeight", + "description": ( "Probabilistic input model for the Wing Weight model " "from Forrester et al. (2008)." ), - marginals=INPUT_MARGINALS_FORRESTER2008, - copulas=None, - ), + "marginals": MARGINALS_FORRESTER2008, + "copulas": None, + }, } @@ -139,7 +140,7 @@ class WingWeight(UQTestFunABC): _tags = ["metamodeling", "sensitivity"] _description = "Wing weight model from Forrester et al. (2008)" - _available_inputs = AVAILABLE_INPUT_SPECS + _available_inputs = AVAILABLE_INPUTS _available_parameters = None _default_input_dimension = 10 diff --git a/tests/core/prob_input/test_multivariate_input.py b/tests/core/prob_input/test_prob_input.py similarity index 76% rename from tests/core/prob_input/test_multivariate_input.py rename to tests/core/prob_input/test_prob_input.py index dec2886..1886020 100644 --- a/tests/core/prob_input/test_multivariate_input.py +++ b/tests/core/prob_input/test_prob_input.py @@ -1,14 +1,7 @@ import pytest import numpy as np -from typing import List from uqtestfuns.core.prob_input.probabilistic_input import ProbInput -from uqtestfuns.core.prob_input.marginal import Marginal -from uqtestfuns.core.prob_input.input_spec import ( - UnivDistSpec, - ProbInputSpecFixDim, - ProbInputSpecVarDim, -) from conftest import create_random_marginals @@ -63,8 +56,7 @@ def test_generate_dependent_sample(): """Test dependent sample generation (not yet supported; raise error).""" marginals = create_random_marginals(5) - my_multivariate_input = ProbInput(marginals) - my_multivariate_input.copulas = "a" + my_multivariate_input = ProbInput(marginals, "a") with pytest.raises(ValueError): my_multivariate_input.get_sample(1000) @@ -90,8 +82,7 @@ def test_get_dependent_pdf_values(): """Test dependent PDF value computation (not yet supported).""" marginals = create_random_marginals(5) - my_multivariate_input = ProbInput(marginals) - my_multivariate_input.copulas = "b" + my_multivariate_input = ProbInput(marginals, "b") with pytest.raises(ValueError): my_multivariate_input.pdf(np.random.rand(2, 5)) @@ -138,7 +129,7 @@ def test_failed_transform_sample(): def test_transform_dependent_sample(): """Test dependent transformation (not yet supported; raise an error).""" marginals_1 = create_random_marginals(5) - my_multivariate_input_1 = ProbInput(marginals_1) + my_multivariate_input_1 = ProbInput(marginals_1, "a") marginals_2 = create_random_marginals(5) my_multivariate_input_2 = ProbInput(marginals_2) @@ -146,7 +137,6 @@ def test_transform_dependent_sample(): xx = np.random.rand(2, 5) with pytest.raises(ValueError): - my_multivariate_input_1.copulas = "a" my_multivariate_input_1.transform_sample(xx, my_multivariate_input_2) @@ -205,78 +195,6 @@ def test_reset_rng(input_dimension): assert np.allclose(xx_1, xx_2) -@pytest.mark.parametrize("input_dimension", [1, 2, 10, 100]) -def test_create_from_spec(input_dimension): - """Test creating an instance from specification NamedTuple""" - marginals: List[Marginal] = create_random_marginals(input_dimension) - - # Create a ProbInputSpecFixDim - name = "Test Name" - description = "Test description" - copulas = None - prob_spec = ProbInputSpecFixDim( - name=name, - description=description, - marginals=[ - UnivDistSpec( - name=marginal.name, - description=marginal.description, - distribution=marginal.distribution, - parameters=marginal.parameters, # type: ignore - ) - for marginal in marginals - ], - copulas=copulas, - ) - - # Create from spec - my_input = ProbInput.from_spec(prob_spec) - - # Assertions - assert my_input.name == name - assert my_input.description == description - assert my_input.copulas == copulas - - # Create a ProbInputSpecVarDim - def _test_vardim(input_dimension): - marginals_spec = [ - UnivDistSpec( - name=f"x{i+1}", - description="None", - distribution="uniform", - parameters=[0, 1], - ) - for i in range(input_dimension) - ] - - return marginals_spec - - name = "Test Name" - description = "Test description" - copulas = None - prob_spec_vardim = ProbInputSpecVarDim( - name=name, - description=description, - marginals_generator=_test_vardim, - copulas=copulas, - ) - - # Create from spec - my_input = ProbInput.from_spec( - prob_spec_vardim, input_dimension=input_dimension - ) - - # Assertions - assert my_input.name == name - assert my_input.description == description - assert my_input.copulas == copulas - assert my_input.input_dimension == input_dimension - - with pytest.raises(ValueError): - ProbInput.from_spec(prob_spec_vardim) - - -# # def test_get_cdf_values(): # """Test the CDF values from an instance of UnivariateInput.""" # name = create_random_alphanumeric(10) diff --git a/tests/core/test_input_spec.py b/tests/core/test_input_spec.py deleted file mode 100644 index c389d4d..0000000 --- a/tests/core/test_input_spec.py +++ /dev/null @@ -1,95 +0,0 @@ -""" -Test module for the prob. input specification class. -""" - -from typing import List - -from uqtestfuns.core.prob_input.input_spec import ( - UnivDistSpec, - ProbInputSpecFixDim, - ProbInputSpecVarDim, -) - - -def test_marginalspec(): - """Test the creation of MarginalSpec NamedTuple.""" - - name = "T0" - distribution = "uniform" - parameters = [340.0, 360.0] - description = "Filling gas temperature" - - # Create a MarginalSpec - my_marginalspec = UnivDistSpec( - name=name, - distribution=distribution, - parameters=parameters, - description=description, - ) - - # Assertions - assert my_marginalspec.name == name - assert my_marginalspec.distribution == distribution - assert my_marginalspec.parameters == parameters - assert my_marginalspec.description == description - - -def test_probinputspec_list(): - """Test the creation of ProbInputSpec NamedTuple w/ list of marginals.""" - - # Create a list of marginals - marginals = _create_marginals(10) - - # Create a ProbInputSpec - name = "Some input" - description = "Probabilistic input model from somewhere" - copulas = None - my_probinputspec = ProbInputSpecFixDim( - name=name, - description=description, - marginals=marginals, - copulas=copulas, - ) - - # Assertions - assert my_probinputspec.name == name - assert my_probinputspec.description == description - assert my_probinputspec.copulas == copulas - assert my_probinputspec.marginals == marginals - - -def test_probinputspec_vardim(): - """Test the creation of ProbInputSpec w/ a callable as marginal.""" - - # Create a list of marginals - marginals_gen = _create_marginals - - # Create a ProbInputSpec - name = "Some input" - description = "Probabilistic input model from somewhere" - copulas = None - my_probinputspec = ProbInputSpecVarDim( - name=name, - description=description, - marginals_generator=marginals_gen, - copulas=copulas, - ) - - # Assertions - assert my_probinputspec.name == name - assert my_probinputspec.description == description - assert my_probinputspec.copulas == copulas - assert my_probinputspec.marginals_generator == marginals_gen - - -def _create_marginals(input_dimension: int) -> List[UnivDistSpec]: - """Create a list of test marginals.""" - return [ - UnivDistSpec( - name=f"x{i + 1}", - distribution="uniform", - parameters=[0.0, 1.0], - description="None", - ) - for i in range(input_dimension) - ] diff --git a/tests/core/test_uqtestfun.py b/tests/core/test_uqtestfun.py index 5430d4f..3b929af 100644 --- a/tests/core/test_uqtestfun.py +++ b/tests/core/test_uqtestfun.py @@ -17,7 +17,14 @@ def evaluate(x, p): return p * (x + 1) parameters = FunParams( - declared_parameters=[{"keyword": "p", "value": 10.0}] + declared_parameters=[ + { + "keyword": "p", + "value": 10.0, + "type": None, + "description": None, + } + ] ) my_args = { From 54b13c1a6a7370bae40adcd547e93668112de9ed Mon Sep 17 00:00:00 2001 From: Damar Wicaksono Date: Thu, 7 Nov 2024 18:02:00 +0100 Subject: [PATCH 2/4] Add typing_extension as requirement --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 7a45f57..c0592d3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,6 +35,7 @@ install_requires = scipy>=1.7.3 tabulate>=0.8.10 importlib-metadata>=1.0; python_version < "3.8" + typing_extensions; python_version > "3.7" [options.packages.find] where = src From c5f6e57a0ffa3999f746019e98736c07c4841692 Mon Sep 17 00:00:00 2001 From: Damar Wicaksono Date: Thu, 7 Nov 2024 18:10:08 +0100 Subject: [PATCH 3/4] Update README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 438bb21..619b815 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,8 @@ The probabilistic input specification of this test function is built-in: ```python-repl >>> print(my_testfun.prob_input) -Name : Borehole-Harper-1983 +Function ID : Borehole +Input ID : Harper1983 Input Dimension : 8 Description : Probabilistic input model of the Borehole model from Harper and Gupta (1983). From e311390a0b0fc4d099f5e2b58b06bf03ce5cfbbc Mon Sep 17 00:00:00 2001 From: Damar Wicaksono Date: Thu, 7 Nov 2024 18:11:14 +0100 Subject: [PATCH 4/4] Update Borehole prob. input description --- README.md | 2 +- src/uqtestfuns/test_functions/borehole.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 619b815..9fc9061 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ Function ID : Borehole Input ID : Harper1983 Input Dimension : 8 Description : Probabilistic input model of the Borehole model from - Harper and Gupta (1983). + Harper and Gupta (1983) Marginals : No. Name Distribution Parameters Description diff --git a/src/uqtestfuns/test_functions/borehole.py b/src/uqtestfuns/test_functions/borehole.py index c928f91..fc47f61 100644 --- a/src/uqtestfuns/test_functions/borehole.py +++ b/src/uqtestfuns/test_functions/borehole.py @@ -104,7 +104,7 @@ "function_id": "Borehole", "description": ( "Probabilistic input model of the Borehole model " - "from Harper and Gupta (1983)." + "from Harper and Gupta (1983)" ), "marginals": MARGINALS_HARPER1983, "copulas": None, @@ -113,7 +113,7 @@ "function_id": "Borehole", "description": ( "Probabilistic input model of the Borehole model " - "from Morris et al. (1993)." + "from Morris et al. (1993)" ), "marginals": MARGINALS_MORRIS1993, "copulas": None,