1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
#! /usr/bin/env python
import openturns as ot
ot.TESTPREAMBLE()
ot.ResourceMap.SetAsUnsignedInteger("RandomMixture-DefaultMaxSize", 4000000)
ot.TTY.ShowColors(False)
# Test fusion of Dirac with no other atoms: should be a unique Dirac(5.8)
d = ot.RandomMixture(
[ot.Dirac(1.0), ot.Dirac(2.0), ot.Dirac(3.0)], [0.5, 0.6, 0.7], 2.0
)
print("d=", d)
# Test fusion of Dirac with other atoms: the Dirac should be merged into
# the constant: 5 + Exponential(lambda=1,gamma=0)
d = ot.RandomMixture([ot.Dirac(1.0), ot.Dirac(2.0), ot.Exponential()], 2.0)
print("d=", d)
# Test flatten RandomMixture atoms: the RandomMixture should have 4 atoms.
d = ot.RandomMixture(
[
ot.Gumbel(),
ot.RandomMixture([ot.Logistic(), ot.WeibullMin()], [0.5, 1.5], 3.0),
ot.Frechet(1.0, 4.0),
],
[2.0, 3.0, 4.0],
2.0,
)
print("d=", d)
# Test merge of Normal atoms:
d = ot.RandomMixture(
[ot.Normal(1.0, 8.0), ot.Logistic(), ot.Normal(2.0, 1.0)], [0.5, 2.5, 3.0], 2.0
)
print("d=", d)
# Test merge of Exponential, Gamma and ChiSquare atoms
d = ot.RandomMixture(
[
ot.Exponential(1.0, 1.0),
ot.Exponential(1.5, -1.0),
ot.Exponential(2.0, 1.0),
ot.Gamma(4.0, 2.0, -1.0),
ot.Gamma(3.0, 1.0, 3.0),
ot.ChiSquare(4.0),
],
[1.0, 1.5, 1.0, 2.0, 2.0, 0.5],
2.0,
)
print("d=", d)
# Test merge of Uniform atoms
d = ot.RandomMixture(
[
ot.Uniform(0.0, 1.0),
ot.Uniform(0.0, 1.0),
ot.Uniform(1.0, 3.0),
ot.Uniform(-1.0, 4.0),
ot.Uniform(2.0, 3.0),
],
[1.0, 1.0, 2.0, 3.0, 4.0],
2.0,
)
print("d=", d)
# Test merge of Bernoulli and Binomial atoms
# Deactivate the fusion of discrete atoms
ot.ResourceMap.SetAsUnsignedInteger("RandomMixture-MaximumSupportSize", 0)
d = ot.RandomMixture(
[
ot.Bernoulli(0.5),
ot.Bernoulli(0.5),
ot.Bernoulli(0.1),
ot.Binomial(4, 0.5),
ot.Binomial(6, 0.5),
ot.Binomial(3, 0.1),
],
[1.0, 1.5, 2.0, 1.0, 4.0, 2.0],
2.0,
)
print("d=", d)
# Test merge of Poisson atoms
# Deactivate the fusion of discrete atoms
ot.ResourceMap.SetAsUnsignedInteger("RandomMixture-MaximumSupportSize", 0)
d = ot.RandomMixture(
[
ot.Poisson(3.0),
ot.Poisson(2.0),
ot.Poisson(6.0),
ot.Poisson(10.0),
ot.Poisson(4.0),
],
[1.0, 2.0, 3.0, 2.0, 1.0],
2.0,
)
print("d=", d)
# Test merge of discrete and continuous atoms
# Deactivate the fusion of discrete atoms
ot.ResourceMap.SetAsUnsignedInteger("RandomMixture-MaximumSupportSize", 0)
# more continuous atoms
d = ot.RandomMixture(
[ot.Logistic(), ot.Binomial(2, 0.5), ot.Uniform()], [1.0, 2.0, 3.0], 2.0
)
print("d=", d)
# more discrete atoms
d = ot.RandomMixture(
[ot.Bernoulli(0.1), ot.Binomial(2, 0.5), ot.Uniform()], [1.0, 2.0, 3.0], 2.0
)
print("d=", d)
# same number of continuous and discrete atoms
d = ot.RandomMixture(
[ot.Logistic(), ot.Bernoulli(0.1), ot.Binomial(2, 0.5), ot.Uniform()],
[1.0, 2.0, 3.0, 4.0],
2.0,
)
print("d=", d)
# Test the fusion of discrete atoms
ot.Log.Show(ot.Log.DBG)
print("\n")
# All the atoms have a too large support
ot.ResourceMap.SetAsUnsignedInteger("RandomMixture-MaximumSupportSize", 1)
d = ot.RandomMixture(
[ot.Binomial(2, 0.1), ot.Binomial(3, 0.5), ot.Poisson(), ot.Geometric()],
[1.0, 2.0, 3.0, 4.0],
2.0,
)
print("d=", d)
print("\n")
# Some atoms have a too large support, no pending aggregated discrete
ot.ResourceMap.SetAsUnsignedInteger("RandomMixture-MaximumSupportSize", 15)
d = ot.RandomMixture(
[ot.Binomial(2, 0.1), ot.Binomial(3, 0.5), ot.Poisson(), ot.Geometric()],
[1.0, 2.0, 3.0, 4.0],
2.0,
)
print("d=", d)
print("\n")
# Some atoms have a too large support, a pending aggregated discrete
ot.ResourceMap.SetAsUnsignedInteger("RandomMixture-MaximumSupportSize", 15)
d = ot.RandomMixture(
[
ot.Binomial(2, 0.1),
ot.Binomial(3, 0.5),
ot.Poisson(),
ot.Binomial(2, 0.1),
ot.Binomial(3, 0.5),
],
[1.0, 2.0, 3.0, 4.0, 5.0],
2.0,
)
print("d=", d)
print("\n")
# All the atoms can be merged
ot.ResourceMap.SetAsUnsignedInteger("RandomMixture-MaximumSupportSize", 100)
d = ot.RandomMixture(
[ot.Bernoulli(0.1), ot.Bernoulli(0.2), ot.Bernoulli(0.3), ot.Bernoulli(0.4)],
[1.0, 2.0, 3.0, 4.0],
2.0,
)
print("d=", d)
|