pyuncertainnumber.pba.intervals =============================== .. py:module:: pyuncertainnumber.pba.intervals Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/pyuncertainnumber/pba/intervals/activation/index /autoapi/pyuncertainnumber/pba/intervals/arithmetic/index /autoapi/pyuncertainnumber/pba/intervals/backcalc/index /autoapi/pyuncertainnumber/pba/intervals/complex/index /autoapi/pyuncertainnumber/pba/intervals/intervalOperators/index /autoapi/pyuncertainnumber/pba/intervals/mat_features/index /autoapi/pyuncertainnumber/pba/intervals/methods/index /autoapi/pyuncertainnumber/pba/intervals/number/index /autoapi/pyuncertainnumber/pba/intervals/plotting/index /autoapi/pyuncertainnumber/pba/intervals/random/index /autoapi/pyuncertainnumber/pba/intervals/utils/index Classes ------- .. autoapisummary:: pyuncertainnumber.pba.intervals.Interval Functions --------- .. autoapisummary:: pyuncertainnumber.pba.intervals.lo pyuncertainnumber.pba.intervals.hi pyuncertainnumber.pba.intervals.mid pyuncertainnumber.pba.intervals.rad pyuncertainnumber.pba.intervals.width pyuncertainnumber.pba.intervals.contain pyuncertainnumber.pba.intervals.intersect pyuncertainnumber.pba.intervals.straddle_zero pyuncertainnumber.pba.intervals.split_interval pyuncertainnumber.pba.intervals.subintervalise pyuncertainnumber.pba.intervals.intervalise pyuncertainnumber.pba.intervals.sizeit pyuncertainnumber.pba.intervals.uniform_endpoints Package Contents ---------------- .. py:class:: Interval(lo: Union[float, numpy.ndarray], hi: Optional[Union[float, numpy.ndarray]] = None, do_heavy_checks: bool = True) Bases: :py:obj:`pyuncertainnumber.pba.mixins.NominalValueMixin` Interval is the main class .. py:attribute:: _lo .. py:attribute:: _hi :value: None .. py:method:: run_heavy_checks() Run heavy checks on the interval object .. py:method:: __repr__() .. py:method:: __str__() .. py:method:: __len__() .. py:method:: __iter__() .. py:method:: __contains__(item) Check if an item is enclosed within the interval. .. rubric:: Example >>> i = Interval(1,3) >>> 2 in i True >>> 4 in i False .. py:method:: __next__() .. py:method:: __getitem__(i: Union[int, slice]) .. py:method:: to_numpy() -> numpy.ndarray transform interval objects to numpy arrays .. py:method:: to_pbox() .. py:method:: lhs_sample(n) -> numpy.ndarray LHS sampling within the interval :param n: number of samples .. py:method:: endpoints_lhs_sample(n) -> numpy.ndarray LHS sampling within the interval plus the endpoints :param n: number of samples .. py:method:: plot(ax=None, **kwargs) .. py:method:: display() .. py:method:: is_degenerate() -> bool Check if the interval is degenerate (i.e., has zero width). .. py:method:: _compute_nominal_value() .. py:method:: ravel() Return a flattened (1D) interval object for multi-dimensional intervals .. rubric:: Example >>> A = np.random.rand(200, 200, 2) >>> i = pba.intervalise(A) >>> print(i.shape) >>> i2 = i.ravel() >>> print(i2.shape) .. py:property:: lo :type: Union[numpy.ndarray, float] .. py:property:: hi :type: Union[numpy.ndarray, float] .. py:property:: left .. py:property:: right .. py:property:: width .. py:property:: rad half width .. py:property:: mid .. py:property:: unsized .. py:property:: val seemingly equivalent to `self.to_numpy()` .. py:property:: scalar Check if the interval is wide sense scalar .. note:: wide sense: I(1,2) and I([1],[2]) are both scalars .. py: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 .. py:property:: shape .. py:property:: ndim .. py:method:: __neg__() .. py:method:: __pos__() .. py:method:: __add__(other) .. py:method:: __radd__(left) .. py:method:: __sub__(other) .. py:method:: __rsub__(left) .. py:method:: __mul__(other) .. py:method:: __rmul__(left) .. py:method:: __truediv__(other) .. py:method:: __rtruediv__(left) .. py:method:: __pow__(other) .. py:method:: __lt__(other) .. py:method:: __rlt__(left) .. py:method:: __gt__(other) .. py:method:: __rgt__(left) .. py:method:: __le__(other) .. py:method:: __rle__(left) .. py:method:: __ge__(other) .. py:method:: __rge__(left) .. py:method:: __eq__(other) .. py:method:: __ne__(other) .. py:method:: __array_ufunc__(ufunc, method, *inputs, **kwargs) .. py:method:: abs() .. py:method:: sqrt() .. py:method:: exp() .. py:method:: log() .. py:method:: sin() .. py:method:: cos() .. py:method:: tan() .. py:method:: from_meanform(x, half_width) :classmethod: .. py:method:: save_json(filename: str, comment: str = None, save_dir: str | pathlib.Path = '.') -> None Save the interval object to a JSON5 file. :param filename: The name of the file (without extension) to save the interval object to. :type filename: str :param comment: A comment to include at the top of the file. :type comment: str, optional :param save_dir: Directory where the file should be saved. Defaults to current directory. :type save_dir: str | Path, optional .. note:: The file is saved with a `.json5` extension. .. rubric:: Example >>> a.save_json("interval_data", comment="This is interval data", save_dir="results/") .. py:function:: lo(x: Interval) -> Union[float, numpy.ndarray] Return the left endpoint of an Interval object. If x is not of class Interval, input is returned. .. py:function:: hi(x: Interval) -> Union[float, numpy.ndarray] Return the right endpoint of an Interval object. If x is not of class Interval, input is returned. .. py:function:: mid(x: Interval) -> Union[float, numpy.ndarray] Return the midpoint of an Interval. If x is not of class Interval, input is returned. .. py:function:: rad(x: Interval) -> Union[float, numpy.ndarray] Return the radius of an Interval object. If x is not of class Interval, input is returned. .. py:function:: width(x: Interval) -> Union[float, numpy.ndarray] Return the width of an Interval object. If x is not of class Interval, input is returned. .. py:function:: contain(x: pyuncertainnumber.pba.intervals.number.Interval, y: pyuncertainnumber.pba.intervals.number.Interval) .. py:function:: intersect(x: pyuncertainnumber.pba.intervals.number.Interval, y: pyuncertainnumber.pba.intervals.number.Interval) .. py:function:: straddle_zero(x: pyuncertainnumber.pba.intervals.number.Interval) -> bool .. py:function:: split_interval(x: pyuncertainnumber.pba.intervals.number.Interval, y: float = None) .. py:function:: subintervalise(x_: pyuncertainnumber.pba.intervals.number.Interval, n: Union[int, tuple] = 0) -> pyuncertainnumber.pba.intervals.number.Interval :returns: - matrix Interval .. py:function:: intervalise(x_: Any, interval_index=-1) -> Union[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. .. py:function:: 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. .. py:function:: 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.