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.
where are the aGrUM ticks, and is distributed according to the OpenTURNS distribution.
- Parameters:
- distribution
openturns.Distribution
An continuous 1-d distribution.
- v
pyAgrum.DiscretizedVariable
A discrete variable.
- distribution
- Returns:
- pot
pyAgrum.Potential
The resulting potential.
- pot
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
oropenturns.UserDefined
.- Parameters:
- p
pyAgrum.Potential
A potential with one variable.
- p
- Returns:
- distribution
openturns.Distribution
A distribution.
- 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:
- p
pyAgrum.Potential
The potential.
- p
- Returns:
- distribution
openturns.Distribution
A distribution.
- 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)