# Output sample with squared exponential covariance
Cov2 = ot.SquaredExponential(1)
Cov2.setScale(Y.computeStandardDeviation())
covarianceModelCollection.add(Cov2)

# We choose an estimator type :
#  - unbiased: HSICUStat;
#   - biased: HSICVStat.
#
estimatorType = ot.HSICUStat()

# We define a distance function for the weights
#  For the TSA, the critical domain is [5,+inf].
interval = ot.Interval(5, float('inf'))
g = ot.DistanceToDomainFunction(interval)

stdDev = Y.computeStandardDeviation()[0]
foo = ot.SymbolicFunction(["x", "s"], ["exp(-x/s)"])
g2 = ot.ParametricFunction(foo, [1], [0.1 * stdDev])

# The filter function
filterFunction = ot.ComposedFunction(g2, g)

# We eventually build the HSIC object!
TSA = ot.HSICEstimatorTargetSensitivity(covarianceModelCollection, X, Y,
                                        estimatorType, filterFunction)

# We get the R2-HSIC
R2HSIC = TSA.getR2HSICIndices()
ott.assert_almost_equal(R2HSIC, [0.26863688, 0.00468423, 0.00339962])
示例#2
0
# %%
# Defining a filter function
# ^^^^^^^^^^^^^^^^^^^^^^^^^^
#
# We define a filter function on the output variable for the target
# analysis. In this example we use the function :math:`\exp{(-d/s)}` where :math:`d` is the distance
# to a well-chosen interval.

# %%
# We first define a critical domain: in our case that is the :math:`[5,+\infty[` interval.
criticalDomain = ot.Interval(5, float('inf'))

# %%
# We have access to the distance to this  domain thanks to the
# :class:`~openturns.DistanceToDomainFunction` class.
dist2criticalDomain = ot.DistanceToDomainFunction(criticalDomain)

# %%
# We define the parameters in our function from the output sample
s = 0.1 * Y.computeStandardDeviation()[0]

# %%
# We now define our filter function by composition of the parametrized function and
# the distance function.
f = ot.SymbolicFunction(["x", "s"], ["exp(-x/s)"])
phi = ot.ParametricFunction(f, [1], [s])
filterFunction = ot.ComposedFunction(phi, dist2criticalDomain)

# %%
# We choose an unbiased estimator
estimatorType = ot.HSICUStat()
示例#3
0
#! /usr/bin/env python

import openturns as ot
import openturns.testing as ott

ot.TESTPREAMBLE()

# distance function from an Interval of dimension 0
singleton = ot.Interval()
assert singleton.computeDistance([])==0.0
assert ot.DistanceToDomainFunction(singleton)([])==ot.Point([0.0])

# distance function from an Interval
box = ot.Interval([1.2,0.7], [2.0, 1.0])
distance = ot.DistanceToDomainFunction(box)

point1 = ot.Point([1.5, 0.8])
assert box.computeDistance(point1)==0.0
distance_to_point1 = distance(point1)
assert distance_to_point1==ot.Point([0.0])

point2 = ot.Point([1.1, 0.8])
ott.assert_almost_equal(box.computeDistance(point2), 0.1, 1e-12, 0.0)
distance_to_point2 = distance(point2)
ott.assert_almost_equal(distance_to_point2, ot.Point([0.1]), 1e-12, 0.0)

sample = ot.Sample([point1, point2])
ott.assert_almost_equal(box.computeDistance(sample), ot.Sample([[0.0], [0.1]]), 1e-12, 0.0)
ott.assert_almost_equal(distance(sample), ot.Sample([[0.0], [0.1]]), 1e-12, 0.0)

# distance function from a DomainUnion of Intervals