Interval

class Interval(*args)

Numerical interval.

Available constructors:

Interval(dim=0)

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

Parameters:

dim : int, 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, upperBound : float 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.

finiteLowerBound : sequence of bool of dimension dim

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

finiteUpperBound : sequence 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 substract 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]
>>> # Substraction
>>> print(interval1 - interval2)
[-4, 4]
[-10, 4]
>>> # Multiplication
>>> print(interval1 * 3)
[6, 15]
[9, 24]

Methods

contains(point) Check if the given point is inside of the domain.
getClassName() Accessor to the object’s name.
getDimension() Get the dimension of the domain.
getFiniteLowerBound() Tell for each component of the lower bound whether it is finite or not.
getFiniteUpperBound() Tell for each component of the upper bound whether it is finite or not.
getId() Accessor to the object’s id.
getLowerBound() Get the lower bound.
getName() Accessor to the object’s name.
getNumericalVolume() Get the volume of the domain.
getShadowedId() Accessor to the object’s shadowed id.
getUpperBound() Get the upper bound.
getVisibility() Accessor to the object’s visibility state.
getVolume() Get the geometric volume of the domain.
hasName() Test if the object is named.
hasVisibleName() Test if the object has a distinguishable name.
intersect(other) Get the intersection with an other interval.
isEmpty() Test whether the domain is empty or not.
isNumericallyEmpty() Check if the domain is numerically empty.
join(other) Get the smallest interval containing both the current interval and another one.
numericallyContains(point) Check if the given point is inside of the discretization of the domain.
setFiniteLowerBound(finiteLowerBound) Tell for each component of the lower bound whether it is finite or not.
setFiniteUpperBound(finiteUpperBound) Tell for each component of the upper bound whether it is finite or not.
setLowerBound(lowerBound) Set the lower bound.
setName(name) Accessor to the object’s name.
setShadowedId(id) Accessor to the object’s shadowed id.
setUpperBound(upperBound) Set the upper bound.
setVisibility(visible) Accessor to the object’s visibility state.
__init__(*args)

x.__init__(…) initializes x; see help(type(x)) for signature

contains(point)

Check if the given point is inside of the domain.

Parameters:

point : sequence of float

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

Returns:

isInside : bool

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

getClassName()

Accessor to the object’s name.

Returns:

class_name : str

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

getDimension()

Get the dimension of the domain.

Returns:

dim : int

Dimension of the domain.

getFiniteLowerBound()

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

Returns:

flags : BoolCollection

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()

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

Returns:

flags : BoolCollection

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()

Accessor to the object’s id.

Returns:

id : int

Internal unique identifier.

getLowerBound()

Get the lower bound.

Returns:

lowerBound : Point

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]
getName()

Accessor to the object’s name.

Returns:

name : str

The name of the object.

getNumericalVolume()

Get the volume of the domain.

Returns:

volume : float

Volume of the underlying mesh which is the discretization of the domain. For now, by default, it is equal to the geometrical volume.

getShadowedId()

Accessor to the object’s shadowed id.

Returns:

id : int

Internal unique identifier.

getUpperBound()

Get the upper bound.

Returns:

upperBound : Point

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()

Accessor to the object’s visibility state.

Returns:

visible : bool

Visibility flag.

getVolume()

Get the geometric volume of the domain.

Returns:

volume : float

Geometrical volume of the domain.

hasName()

Test if the object is named.

Returns:

hasName : bool

True if the name is not empty.

hasVisibleName()

Test if the object has a distinguishable name.

Returns:

hasVisibleName : bool

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

intersect(other)

Get the intersection with an other interval.

Parameters:

otherInterval : Interval

Interval of the same dimension.

Returns:

interval : Interval

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()

Test whether the domain is empty or not.

Returns:

isInside : bool

True if the interior of the geometric domain is empty.

isNumericallyEmpty()

Check if the domain is numerically empty.

Returns:

isInside : bool

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

Examples

>>> import openturns as ot
>>> domain = ot.Domain([1.0, 2.0], [1.0, 2.0]) 
>>> print(domain.isNumericallyEmpty())
True
join(other)

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

Parameters:

otherInterval : Interval

Interval of the same dimension.

Returns:

interval : Interval

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(point)

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

Parameters:

point : sequence of float

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

Returns:

isInside : bool

Flag telling whether the point is inside the discretized domain associated to the domain. For now, by default, the discretized domain is equal to the geometrical domain.

setFiniteLowerBound(finiteLowerBound)

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

Parameters:

flags : sequence 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(finiteUpperBound)

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

Parameters:

flags : sequence 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(lowerBound)

Set the lower bound.

Parameters:

lowerBound : sequence 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(name)

Accessor to the object’s name.

Parameters:

name : str

The name of the object.

setShadowedId(id)

Accessor to the object’s shadowed id.

Parameters:

id : int

Internal unique identifier.

setUpperBound(upperBound)

Set the upper bound.

Parameters:

upperBound : sequence 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(visible)

Accessor to the object’s visibility state.

Parameters:

visible : bool

Visibility flag.