pyuncertainnumber.pba.intervals¶
Submodules¶
- pyuncertainnumber.pba.intervals.activation
- pyuncertainnumber.pba.intervals.arithmetic
- pyuncertainnumber.pba.intervals.backcalc
- pyuncertainnumber.pba.intervals.complex
- pyuncertainnumber.pba.intervals.intervalOperators
- pyuncertainnumber.pba.intervals.mat_features
- pyuncertainnumber.pba.intervals.methods
- pyuncertainnumber.pba.intervals.number
- pyuncertainnumber.pba.intervals.plotting
- pyuncertainnumber.pba.intervals.random
- pyuncertainnumber.pba.intervals.utils
Classes¶
Interval is the main class |
Functions¶
|
Return the left endpoint of an Interval object. |
|
Return the right endpoint of an Interval object. |
|
Return the midpoint of an Interval. |
|
Return the radius of an Interval object. |
|
Return the width of an Interval object. |
|
|
|
|
|
|
|
|
|
|
|
This function casts an array-like structure into an Interval structure. |
|
Takes an unsized scalar interval and turns it in to a sized one. |
|
Draws endpoints from a uniform distribution. |
Package Contents¶
- class pyuncertainnumber.pba.intervals.Interval(lo: float | numpy.ndarray, hi: float | numpy.ndarray | None = None, do_heavy_checks: bool = True)¶
Bases:
pyuncertainnumber.pba.mixins.NominalValueMixinInterval is the main class
- _lo¶
- _hi = None¶
- run_heavy_checks()¶
Run heavy checks on the interval object
- __repr__()¶
- __str__()¶
- __len__()¶
- __iter__()¶
- __contains__(item)¶
Check if an item is enclosed within the interval.
Example
>>> i = Interval(1,3) >>> 2 in i True >>> 4 in i False
- __next__()¶
- __getitem__(i: int | slice)¶
- to_numpy() numpy.ndarray¶
transform interval objects to numpy arrays
- to_pbox()¶
- lhs_sample(n) numpy.ndarray¶
LHS sampling within the interval
- Parameters:
n – number of samples
- endpoints_lhs_sample(n) numpy.ndarray¶
LHS sampling within the interval plus the endpoints
- Parameters:
n – number of samples
- plot(ax=None, **kwargs)¶
- display()¶
- is_degenerate() bool¶
Check if the interval is degenerate (i.e., has zero width).
- _compute_nominal_value()¶
- ravel()¶
Return a flattened (1D) interval object for multi-dimensional intervals
Example
>>> A = np.random.rand(200, 200, 2) >>> i = pba.intervalise(A) >>> print(i.shape) >>> i2 = i.ravel() >>> print(i2.shape)
- property lo: numpy.ndarray | float¶
- property hi: numpy.ndarray | float¶
- property left¶
- property right¶
- property width¶
- property rad¶
half width
- property mid¶
- property unsized¶
- property val¶
seemingly equivalent to self.to_numpy()
- property scalar¶
Check if the interval is wide sense scalar
Note
wide sense: I(1,2) and I([1],[2]) are both scalars
- property is_scalar¶
Check if the interval is a strict-sense scalar
Note
strict sense: I(1,2) is a scalar, but I([1],[2]) is not
- property shape¶
- property ndim¶
- __neg__()¶
- __pos__()¶
- __add__(other)¶
- __radd__(left)¶
- __sub__(other)¶
- __rsub__(left)¶
- __mul__(other)¶
- __rmul__(left)¶
- __truediv__(other)¶
- __rtruediv__(left)¶
- __pow__(other)¶
- __lt__(other)¶
- __rlt__(left)¶
- __gt__(other)¶
- __rgt__(left)¶
- __le__(other)¶
- __rle__(left)¶
- __ge__(other)¶
- __rge__(left)¶
- __eq__(other)¶
- __ne__(other)¶
- __array_ufunc__(ufunc, method, *inputs, **kwargs)¶
- abs()¶
- sqrt()¶
- exp()¶
- log()¶
- sin()¶
- cos()¶
- tan()¶
- classmethod from_meanform(x, half_width)¶
- save_json(filename: str, comment: str = None, save_dir: str | pathlib.Path = '.') None¶
Save the interval object to a JSON5 file.
- Parameters:
filename (str) – The name of the file (without extension) to save the interval object to.
comment (str, optional) – A comment to include at the top of the file.
save_dir (str | Path, optional) – Directory where the file should be saved. Defaults to current directory.
Note
The file is saved with a .json5 extension.
Example
>>> a.save_json("interval_data", comment="This is interval data", save_dir="results/")
- pyuncertainnumber.pba.intervals.lo(x: Interval) float | numpy.ndarray¶
Return the left endpoint of an Interval object.
If x is not of class Interval, input is returned.
- pyuncertainnumber.pba.intervals.hi(x: Interval) float | numpy.ndarray¶
Return the right endpoint of an Interval object.
If x is not of class Interval, input is returned.
- pyuncertainnumber.pba.intervals.mid(x: Interval) float | numpy.ndarray¶
Return the midpoint of an Interval.
If x is not of class Interval, input is returned.
- pyuncertainnumber.pba.intervals.rad(x: Interval) float | numpy.ndarray¶
Return the radius of an Interval object.
If x is not of class Interval, input is returned.
- pyuncertainnumber.pba.intervals.width(x: Interval) float | numpy.ndarray¶
Return the width of an Interval object.
If x is not of class Interval, input is returned.
- pyuncertainnumber.pba.intervals.contain(x: pyuncertainnumber.pba.intervals.number.Interval, y: pyuncertainnumber.pba.intervals.number.Interval)¶
- pyuncertainnumber.pba.intervals.intersect(x: pyuncertainnumber.pba.intervals.number.Interval, y: pyuncertainnumber.pba.intervals.number.Interval)¶
- pyuncertainnumber.pba.intervals.straddle_zero(x: pyuncertainnumber.pba.intervals.number.Interval) bool¶
- pyuncertainnumber.pba.intervals.split_interval(x: pyuncertainnumber.pba.intervals.number.Interval, y: float = None)¶
- pyuncertainnumber.pba.intervals.subintervalise(x_: pyuncertainnumber.pba.intervals.number.Interval, n: int | tuple = 0) pyuncertainnumber.pba.intervals.number.Interval¶
- Returns:
matrix Interval
- pyuncertainnumber.pba.intervals.intervalise(x_: Any, interval_index=-1) pyuncertainnumber.pba.intervals.number.Interval | Any¶
This function casts an array-like structure into an Interval structure. All array-like structures will be first coerced into an ndarray of floats. If the coercion is unsuccessful the following error is thrown: ValueError: setting an array element with a sequence.
For example this is the expected behaviour: (*) an ndarray of shape (4,2) will be cast as an Interval of shape (4,).
(*) an ndarray of shape (7,3,2) will be cast as an Interval of shape (7,3).
(*) an ndarray of shape (3,2,7) will be cast as a degenerate Interval of shape (3,2,7).
(*) an ndarray of shape (2,3,7) will be cast as an Interval of shape (3,7).
(*) an ndarray of shape (2,3,7,2) will be cast as an Interval of shape (2,3,7) if interval_index is set to -1.
If an ndarray has shape with multiple dimensions having size 2, then the last dimension is intervalised. So, an ndarray of shape (7,2,2) will be cast as an Interval of shape (7,2) with the last dimension intervalised. When the ndarray has shape (2,2) again is the last dimension that gets intervalised.
In case of ambiguity, e.g. (2,5,2), now the first dimension can be forced to be intervalised, selecting index=0, default is -1.
It returns an interval only if the input is an array-like structure, otherwise it returns the following numpy error: ValueError: setting an array element with a sequence.
TODO: Parse a list of mixed numbers: interval and ndarrays.
- pyuncertainnumber.pba.intervals.sizeit(x: pyuncertainnumber.pba.intervals.number.Interval) pyuncertainnumber.pba.intervals.number.Interval¶
Takes an unsized scalar interval and turns it in to a sized one.
- pyuncertainnumber.pba.intervals.uniform_endpoints(n: int = 2, left_bound: float = None, right_bound: float = None, kind: type = float, shape: tuple = None)¶
Draws endpoints from a uniform distribution. It was created as an interval random generator.