Utils

class otagrum.Utils(*args, **kwargs)

Utility functions

Methods

Discretize(*args)

Discretize a continuous distribution.

FromMarginal(pot)

Convert an 1-d probability table to a distribution.

FromPotential(pot)

Convert an n-d probability table to a distribution.

__init__(*args, **kwargs)
static Discretize(*args)

Discretize a continuous distribution.

Compute a probability table according to the domains defined in a discretized aGrUM variable and a continuous OpenTURNS distribution.

\big\{ p_i \big\} = \big\{ \Prob{t_i < X \leq t_{i+1}}, i \in \left[ 1, n \right] \big\}

where $t_i$ are the aGrUM ticks, and $X$ is distributed according to the OpenTURNS distribution.

Parameters:
distributionopenturns.Distribution

An continuous 1-d distribution.

vpyAgrum.DiscretizedVariable

A discrete variable.

Returns:
potpyAgrum.Potential

The resulting potential.

Examples

>>> import pyAgrum as gum
>>> import openturns as ot
>>> import otagrum
>>> height = gum.DiscretizedVariable('Height', 'plant growth', [0.0, 10.0, 20.0, 30.0])
>>> height_dist = ot.Normal(18.0, 8.0)
>>> pot = otagrum.Utils.Discretize(height_dist, height)
static FromMarginal(pot)

Convert an 1-d probability table to a distribution.

Converts an univariate aGrUM probability table to an OpenTURNS distribution, either openturns.Histogram or openturns.UserDefined.

Parameters:
ppyAgrum.Potential

A potential with one variable.

Returns:
distributionopenturns.Distribution

A distribution.

Examples

>>> import pyAgrum as gum
>>> import otagrum
>>> light = gum.LabelizedVariable('Light', 'quality of light', 0).addLabel('Dim').addLabel('Bright')
>>> pot = gum.Potential().add(light)
>>> pot[:]= [0.25, 0.75]
>>> str(otagrum.Utils.FromMarginal(pot))
'UserDefined({x = [0], p = 0.25}, {x = [1], p = 0.75})'
static FromPotential(pot)

Convert an n-d probability table to a distribution.

Converts a multivariate aGrUM probability table to an OpenTURNS distribution, using openturns.MixedHistogramUserDefined

Parameters:
ppyAgrum.Potential

The potential.

Returns:
distributionopenturns.Distribution

A distribution.

Examples

>>> import pyAgrum as gum
>>> import otagrum
>>> light = gum.LabelizedVariable('Light', 'light', 0).addLabel('Dim').addLabel('Bright')
>>> moisture = gum.LabelizedVariable('Moisture', 'moisture', 0).addLabel('Dry').addLabel('Wet')
>>> pot = gum.Potential().add(light).add(moisture)
>>> pot[{'Light': 'Dim',    'Moisture': 'Dry'}] = 0.3
>>> pot[{'Light': 'Dim',    'Moisture': 'Wet'}] = 0.2
>>> pot[{'Light': 'Bright', 'Moisture': 'Dry'}] = 0.1
>>> pot[{'Light': 'Bright', 'Moisture': 'Wet'}] = 0.4
>>> dist = otagrum.Utils.FromPotential(pot)