Пример #1
0
    def _computePValuesPermutation(self):

        W_obs = self._computeWeightMatrix(self.Y)
        self.PValuesPermutation = ot.Point()

        N_permutations = ot.KPermutationsDistribution(
            self.n, self.n).getSample(self.PermutationBootstrapSize)
        permuted_values = [[int(x) for x in N_permutations[j]]
                           for j in range(self.PermutationBootstrapSize)]

        for dim in range(self.d):
            HSIC_obs = self._computeHSICIndex(self.X[:, dim], self.Y,
                                              self.CovX[dim], self.CovY, W_obs)
            HSIC_l = []
            for perm in permuted_values:
                Y_p = self.Y[perm]

                W = self._computeWeightMatrix(Y_p)

                HSIC_l.append(
                    self._computeHSICIndex(self.X[:, dim], Y_p, self.CovX[dim],
                                           self.CovY, W))

            p = np.count_nonzero(np.array(HSIC_l) > HSIC_obs) / (
                self.PermutationBootstrapSize + 1)

            self.PValuesPermutation.add(p)
        return 0
Пример #2
0
import openturns as ot
from matplotlib import pyplot as plt
from openturns.viewer import View
if (ot.KPermutationsDistribution().__class__.__name__ == 'ComposedDistribution'
    ):
    correlation = ot.CorrelationMatrix(2)
    correlation[1, 0] = 0.25
    aCopula = ot.NormalCopula(correlation)
    marginals = [ot.Normal(1.0, 2.0), ot.Normal(2.0, 3.0)]
    distribution = ot.ComposedDistribution(marginals, aCopula)
elif (ot.KPermutationsDistribution().__class__.__name__ ==
      'CumulativeDistributionNetwork'):
    distribution = ot.CumulativeDistributionNetwork(
        [ot.Normal(2), ot.Dirichlet([0.5, 1.0, 1.5])],
        ot.BipartiteGraph([[0, 1], [0, 1]]))
else:
    distribution = ot.KPermutationsDistribution()
dimension = distribution.getDimension()
if dimension <= 2:
    if distribution.getDimension() == 1:
        distribution.setDescription(['$x$'])
        pdf_graph = distribution.drawPDF()
        cdf_graph = distribution.drawCDF()
        fig = plt.figure(figsize=(10, 4))
        plt.suptitle(str(distribution))
        pdf_axis = fig.add_subplot(121)
        cdf_axis = fig.add_subplot(122)
        View(pdf_graph, figure=fig, axes=[pdf_axis], add_legend=False)
        View(cdf_graph, figure=fig, axes=[cdf_axis], add_legend=False)
    else:
        distribution.setDescription(['$x_1$', '$x_2$'])
Пример #3
0
#backends = ["MuParser"]

ot.ResourceMap.SetAsUnsignedInteger('SymbolicParserExprTk-MaxNodeDepth',
                                    100000)

size = 1000

N = 1000
X = ["x" + str(i) for i in range(N)]

P = 10
nb_factors_generator = ot.Binomial(P - 1, 0.5)
# Create the generators once and for all
indices_generator = list()
for k in range(P):
    indices_generator.append(ot.KPermutationsDistribution(k + 1, N))

for j in range(17):
    print("#" * 50)
    M = 2**j
    print("M=", M)
    t0 = time()
    print("Create formula...")
    formula = ''
    for i in range(M):
        K = int(nb_factors_generator.getRealization()[0])
        factor = ''
        indices = indices_generator[K].getRealization()
        for j in range(K + 1):
            factor += X[int(indices[j])]
            if j < K:
Пример #4
0
import openturns as ot
from matplotlib import pyplot as plt
from openturns.viewer import View
if ot.KPermutationsDistribution().__class__.__name__ == 'ComposedDistribution':
    correlation = ot.CorrelationMatrix(2)
    correlation[1, 0] = 0.25
    aCopula = ot.NormalCopula(correlation)
    marginals = [ot.Normal(1.0, 2.0), ot.Normal(2.0, 3.0)]
    distribution = ot.ComposedDistribution(marginals, aCopula)
elif ot.KPermutationsDistribution().__class__.__name__ == 'CumulativeDistributionNetwork':
    distribution = ot.CumulativeDistributionNetwork([ot.Normal(2),ot.Dirichlet([0.5, 1.0, 1.5])], ot.BipartiteGraph([[0,1], [0,1]]))
elif ot.KPermutationsDistribution().__class__.__name__ == 'Histogram':
    distribution = ot.Histogram([-1.0, 0.5, 1.0, 2.0], [0.45, 0.4, 0.15])
else:
    distribution = ot.KPermutationsDistribution()
dimension = distribution.getDimension()
if dimension == 1:
    distribution.setDescription(['$x$'])
    pdf_graph = distribution.drawPDF()
    cdf_graph = distribution.drawCDF()
    fig = plt.figure(figsize=(10, 4))
    plt.suptitle(str(distribution))
    pdf_axis = fig.add_subplot(121)
    cdf_axis = fig.add_subplot(122)
    View(pdf_graph, figure=fig, axes=[pdf_axis], add_legend=False)
    View(cdf_graph, figure=fig, axes=[cdf_axis], add_legend=False)
elif dimension == 2:
    distribution.setDescription(['$x_1$', '$x_2$'])
    pdf_graph = distribution.drawPDF()
    fig = plt.figure(figsize=(10, 5))
    plt.suptitle(str(distribution))
# %%
import openturns as ot

# %%
# In this short example we present a simple way to mix the lines of a sample
# thanks to the :class:`~openturns.KPermutationsDistribution` class.

# %%
# We first define a small sample of size :math:`N` based on a standard unit gaussian distribution.
distribution = ot.Normal()
N = 5
sample = distribution.getSample(N)

# %%
# We print the sample :
print(sample)

# %%
# A new set of randomly mixed indices is a realization of a permutation of N elements amongst N :
#
mixingDistribution = ot.KPermutationsDistribution(N, N)
newIndices = mixingDistribution.getSample(1)[0, :]

# %%
# The new indices will be these ones :
print("New indices : ", newIndices)

# %%
# Eventually the randomized sample is
print(sample[[int(i) for i in newIndices]])
import openturns as ot
from matplotlib import pyplot as plt
from openturns.viewer import View
if ot.KPermutationsDistribution().__class__.__name__ == 'Bernoulli':
    distribution = ot.Bernoulli(0.7)
elif ot.KPermutationsDistribution().__class__.__name__ == 'Binomial':
    distribution = ot.Binomial(5, 0.2)
elif ot.KPermutationsDistribution(
).__class__.__name__ == 'ComposedDistribution':
    copula = ot.IndependentCopula(2)
    marginals = [ot.Uniform(1.0, 2.0), ot.Normal(2.0, 3.0)]
    distribution = ot.ComposedDistribution(marginals, copula)
elif ot.KPermutationsDistribution(
).__class__.__name__ == 'CumulativeDistributionNetwork':
    coll = [ot.Normal(2), ot.Dirichlet([0.5, 1.0, 1.5])]
    distribution = ot.CumulativeDistributionNetwork(
        coll, ot.BipartiteGraph([[0, 1], [0, 1]]))
elif ot.KPermutationsDistribution().__class__.__name__ == 'Histogram':
    distribution = ot.Histogram([-1.0, 0.5, 1.0, 2.0], [0.45, 0.4, 0.15])
elif ot.KPermutationsDistribution().__class__.__name__ == 'KernelMixture':
    kernel = ot.Uniform()
    sample = ot.Normal().getSample(5)
    bandwith = [1.0]
    distribution = ot.KernelMixture(kernel, bandwith, sample)
elif ot.KPermutationsDistribution(
).__class__.__name__ == 'MaximumDistribution':
    coll = [
        ot.Uniform(2.5, 3.5),
        ot.LogUniform(1.0, 1.2),
        ot.Triangular(2.0, 3.0, 4.0)
    ]