Interval

class Interval(*args)

Numerical interval.

Available constructors:

Interval(dim=0)

Interval(lowerBound, upperBound, finiteLowerBound=[True]*dim, finiteUpperBound=[True]*dim)

Parameters
dimint, dim \geq 0

Dimension of the interval. If only dim is mentioned, it leads to create the finite interval [0, 1]^{dim}. By default, an empty interval is created.

lowerBound, upperBoundfloat or sequence of float of dimension dim

Define an interval [lowerBound_0, upperBound_0]\times \dots \times [lowerBound_{dim-1}, upperBound_{dim-1}]. It is allowed to have lowerBound_i \geq upperBound_i for some i: it simply defines an empty interval. The lowerBound and the upperBound must be of the same type. If finiteLowerBound and finiteUpperBound are mentioned, they must be sequences.

finiteLowerBoundsequence of bool of dimension dim

Flags telling for each component of the lower bound whether it is finite or not.

finiteUpperBoundsequence of bool of dimension dim

Flags telling for each component of the upper bound whether it is finite or not.

Notes

The meaning of a flag is: if flag i is True, the corresponding component of the given bound is finite and its value is given by bound i. If not, the corresponding component is infinite and its value is either -\infty if bound i < 0 or +\infty if bound i \geq 0.

It is possible to add or subtract two intervals and multiply an interval by a scalar.

Examples

>>> import openturns as ot
>>> # A finite interval
>>> print(ot.Interval([2.0, 3.0], [4.0, 5.0]))
[2, 4]
[3, 5]
>>> # Not finite intervals
>>> a = 2.0
>>> print(ot.Interval([a], [1], [True], [False]))
[2, (1) +inf[
>>> print(ot.Interval([1], [a], [False], [True]))
]-inf (1), 2]
>>> # Operations with intervals:
>>> interval1 = ot.Interval([2.0, 3.0], [5.0, 8.0])
>>> interval2 = ot.Interval([1.0, 4.0], [6.0, 13.0])
>>> # Addition
>>> print(interval1 + interval2)
[3, 11]
[7, 21]
>>> # Subtraction
>>> print(interval1 - interval2)
[-4, 4]
[-10, 4]
>>> # Multiplication
>>> print(interval1 * 3)
[6, 15]
[9, 24]

Methods

contains(self, \*args)

Check if the given point is inside of the domain.

getClassName(self)

Accessor to the object’s name.

getDimension(self)

Get the dimension of the domain.

getFiniteLowerBound(self)

Tell for each component of the lower bound whether it is finite or not.

getFiniteUpperBound(self)

Tell for each component of the upper bound whether it is finite or not.

getId(self)

Accessor to the object’s id.

getLowerBound(self)

Get the lower bound.

getMarginal(self, \*args)

Marginal accessor.

getName(self)

Accessor to the object’s name.

getShadowedId(self)

Accessor to the object’s shadowed id.

getUpperBound(self)

Get the upper bound.

getVisibility(self)

Accessor to the object’s visibility state.

getVolume(self)

Get the volume of the interval.

hasName(self)

Test if the object is named.

hasVisibleName(self)

Test if the object has a distinguishable name.

intersect(self, other)

Get the intersection with an other interval.

isEmpty(self)

Check if the interval is empty.

isNumericallyEmpty(self)

Check if the interval is numerically empty.

join(self, other)

Get the smallest interval containing both the current interval and another one.

numericallyContains(self, point)

Check if the given point is inside of the discretization of the interval.

setFiniteLowerBound(self, finiteLowerBound)

Tell for each component of the lower bound whether it is finite or not.

setFiniteUpperBound(self, finiteUpperBound)

Tell for each component of the upper bound whether it is finite or not.

setLowerBound(self, lowerBound)

Set the lower bound.

setName(self, name)

Accessor to the object’s name.

setShadowedId(self, id)

Accessor to the object’s shadowed id.

setUpperBound(self, upperBound)

Set the upper bound.

setVisibility(self, visible)

Accessor to the object’s visibility state.

__init__(self, \*args)

Initialize self. See help(type(self)) for accurate signature.

contains(self, \*args)

Check if the given point is inside of the domain.

Parameters
pointsequence of float

Point with the same dimension as the current domain’s dimension.

Returns
isInsidebool

Flag telling whether the given point is inside of the domain.

getClassName(self)

Accessor to the object’s name.

Returns
class_namestr

The object class name (object.__class__.__name__).

getDimension(self)

Get the dimension of the domain.

Returns
dimint

Dimension of the domain.

getFiniteLowerBound(self)

Tell for each component of the lower bound whether it is finite or not.

Returns
flagsBoolCollection

If the i^{th} element is False, the corresponding component of the lower bound is infinite. Otherwise, it is finite.

Examples

>>> import openturns as ot
>>> interval = ot.Interval([2.0, 3.0], [4.0, 5.0], [True, False], [True, True])
>>> print(interval.getFiniteLowerBound())
[1,0]
getFiniteUpperBound(self)

Tell for each component of the upper bound whether it is finite or not.

Returns
flagsBoolCollection

If the i^{th} element is False, the corresponding component of the upper bound is infinite. Otherwise, it is finite.

Examples

>>> import openturns as ot
>>> interval = ot.Interval([2.0, 3.0], [4.0, 5.0], [True, False], [True, True])
>>> print(interval.getFiniteUpperBound())
[1,1]
getId(self)

Accessor to the object’s id.

Returns
idint

Internal unique identifier.

getLowerBound(self)

Get the lower bound.

Returns
lowerBoundPoint

Value of the lower bound.

Examples

>>> import openturns as ot
>>> interval = ot.Interval([2.0, 3.0], [4.0, 5.0], [True, False], [True, True])
>>> print(interval.getLowerBound())
[2,3]
getMarginal(self, \*args)

Marginal accessor.

Parameters
indexint or sequence of int

Index or indices of the selected components.

Returns
intervalInterval

The marginal interval.

getName(self)

Accessor to the object’s name.

Returns
namestr

The name of the object.

getShadowedId(self)

Accessor to the object’s shadowed id.

Returns
idint

Internal unique identifier.

getUpperBound(self)

Get the upper bound.

Returns
upperBoundPoint

Value of the upper bound.

Examples

>>> import openturns as ot
>>> interval = ot.Interval([2.0, 3.0], [4.0, 5.0], [True, False], [True, True])
>>> print(interval.getUpperBound())
[4,5]
getVisibility(self)

Accessor to the object’s visibility state.

Returns
visiblebool

Visibility flag.

getVolume(self)

Get the volume of the interval.

Returns
volumefloat

Volume contained within interval bounds.

Examples

>>> import openturns as ot
>>> interval = ot.Interval([2.0, 3.0], [4.0, 5.0], [True, False], [True, True])
>>> print(interval.getVolume())
4.0
hasName(self)

Test if the object is named.

Returns
hasNamebool

True if the name is not empty.

hasVisibleName(self)

Test if the object has a distinguishable name.

Returns
hasVisibleNamebool

True if the name is not empty and not the default one.

intersect(self, other)

Get the intersection with an other interval.

Parameters
otherIntervalInterval

Interval of the same dimension.

Returns
intervalInterval

An interval corresponding to the intersection of the current interval with otherInterval.

Examples

>>> import openturns as ot
>>> interval1 = ot.Interval([2.0, 3.0], [5.0, 8.0])
>>> interval2 = ot.Interval([1.0, 4.0], [6.0, 13.0])
>>> print(interval1.intersect(interval2))
[2, 5]
[4, 8]
isEmpty(self)

Check if the interval is empty.

Returns
isEmptybool

True if the interior of the interval is empty.

Examples

>>> import openturns as ot
>>> interval = ot.Interval([1.0, 2.0], [1.0, 2.0])
>>> interval.setFiniteLowerBound([True, False])
>>> print(interval.isEmpty())
False
isNumericallyEmpty(self)

Check if the interval is numerically empty.

Returns
isEmptybool

Flag telling whether the interval is numerically empty, i.e. if its numerical volume is inferior or equal to \epsilon (defined in the ResourceMap: \epsilon = Domain-SmallVolume).

Examples

>>> import openturns as ot
>>> interval = ot.Interval([1.0, 2.0], [1.0, 2.0])
>>> print(interval.isNumericallyEmpty())
True
join(self, other)

Get the smallest interval containing both the current interval and another one.

Parameters
otherIntervalInterval

Interval of the same dimension.

Returns
intervalInterval

Smallest interval containing both the current interval and otherInterval.

Examples

>>> import openturns as ot
>>> interval1 = ot.Interval([2.0, 3.0], [5.0, 8.0])
>>> interval2 = ot.Interval([1.0, 4.0], [6.0, 13.0])
>>> print(interval1.join(interval2))
[1, 6]
[3, 13]
numericallyContains(self, point)

Check if the given point is inside of the discretization of the interval.

Parameters
pointsequence of float

Point with the same dimension as the current domain’s dimension.

Returns
isInsidebool

Flag telling whether the point is inside the interval bounds, not taking into account whether bounds are finite or not.

setFiniteLowerBound(self, finiteLowerBound)

Tell for each component of the lower bound whether it is finite or not.

Parameters
flagssequence of bool

If the i^{th} element is False, the corresponding component of the lower bound is infinite. Otherwise, it is finite.

Examples

>>> import openturns as ot
>>> interval = ot.Interval(2)
>>> interval.setFiniteLowerBound([True, False])
>>> print(interval)
[0, 1]
]-inf (0), 1]
setFiniteUpperBound(self, finiteUpperBound)

Tell for each component of the upper bound whether it is finite or not.

Parameters
flagssequence of bool

If the i^{th} element is False, the corresponding component of the upper bound is infinite. Otherwise, it is finite.

Examples

>>> import openturns as ot
>>> interval = ot.Interval(2)
>>> interval.setFiniteUpperBound([True, False])
>>> print(interval)
[0, 1]
[0, (1) +inf[
setLowerBound(self, lowerBound)

Set the lower bound.

Parameters
lowerBoundsequence of float

Value of the lower bound.

Examples

>>> import openturns as ot
>>> interval = ot.Interval(2)
>>> interval.setLowerBound([-4, -5])
>>> print(interval)
[-4, 1]
[-5, 1]
setName(self, name)

Accessor to the object’s name.

Parameters
namestr

The name of the object.

setShadowedId(self, id)

Accessor to the object’s shadowed id.

Parameters
idint

Internal unique identifier.

setUpperBound(self, upperBound)

Set the upper bound.

Parameters
upperBoundsequence of float

Value of the upper bound.

Examples

>>> import openturns as ot
>>> interval = ot.Interval(2)
>>> interval.setUpperBound([4, 5])
>>> print(interval)
[0, 4]
[0, 5]
setVisibility(self, visible)

Accessor to the object’s visibility state.

Parameters
visiblebool

Visibility flag.