# Possible evaluation of Sobol indices directly from the FunctionalChaosAlgorithm?

**URL:** <https://openturns.discourse.group/t/possible-evaluation-of-sobol-indices-directly-from-the-functionalchaosalgorithm/207>\
**Category:** Python usage\
**Tags:** polynomial-chaos, sensitivity-analysis\
**Created:** [May 10, 2022, 2:52pm UTC](https://openturns.discourse.group/t/possible-evaluation-of-sobol-indices-directly-from-the-functionalchaosalgorithm/207 "2022-05-10T14:52:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SarahIaquinta](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/sarahiaquinta/32/240_2.png) [@SarahIaquinta](https://openturns.discourse.group/u/SarahIaquinta)\
**Post date:** [May 10, 2022, 2:52pm UTC](https://openturns.discourse.group/t/possible-evaluation-of-sobol-indices-directly-from-the-functionalchaosalgorithm/207/1 "2022-05-10T14:52:28Z")

</div>

Hello,  
Is there a way to compute the Sobol indices directly from the `FunctionalChaosAlgorithm` class?  
Regards,  
Sarah

---

<div class="post-metadata">

**Author:** ![sofianehaddad](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/sofianehaddad/32/46_2.png) [@sofianehaddad](https://openturns.discourse.group/u/sofianehaddad)\
**Post date:** [May 11, 2022, 9:36am UTC](https://openturns.discourse.group/t/possible-evaluation-of-sobol-indices-directly-from-the-functionalchaosalgorithm/207/2 "2022-05-11T09:36:16Z")

</div>

Hello,

`FunctionalChaosAlgorithm ` allows to compute a Polynomial Chaos Expansion (PCE) model. A small post processing of the result provides the given `Sobol` indices

Here a basic example:

```python
import openturns as ot
from math import pi
import openturns.viewer as otv
ot.RandomGenerator.SetSeed(0)
formula = ['sin(X1) + 7. * sin(X2)^2 + 0.1 * X3^4 * sin(X1)']
input_names = ['X1', 'X2', 'X3']
g = ot.SymbolicFunction(input_names, formula)
distributionList = [ot.Uniform(-pi, pi)] * 3
distribution = ot.ComposedDistribution(distributionList)
N = 100
inputTrain = distribution.getSample(N)
outputTrain = g(inputTrain)
chaosalgo = ot.FunctionalChaosAlgorithm(inputTrain, outputTrain)
chaosalgo.run()
result = chaosalgo.getResult()
chaosSI = ot.FunctionalChaosSobolIndices(result)
print( chaosSI.summary() )
first_order = [chaosSI.getSobolIndex(k) for k in range(3)]
total_order = [chaosSI.getSobolTotalIndex(k) for k in range(3)]

```

Have a look also at [this example](https://openturns.github.io/openturns/latest/auto_meta_modeling/polynomial_chaos_metamodel/plot_chaos_ishigami.html?highlight=sobolindices) or [this one](https://openturns.github.io/openturns/latest/auto_reliability_sensitivity/sensitivity_analysis/plot_functional_chaos_sensitivity.html?highlight=functionalchaossobolindices) for more details

---

<div class="post-metadata">

**Author:** ![SarahIaquinta](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/sarahiaquinta/32/240_2.png) [@SarahIaquinta](https://openturns.discourse.group/u/SarahIaquinta)\
**Post date:** [May 11, 2022, 11:58am UTC](https://openturns.discourse.group/t/possible-evaluation-of-sobol-indices-directly-from-the-functionalchaosalgorithm/207/3 "2022-05-11T11:58:16Z")

</div>

Hi Sofiane,  
Thank you so much! This is very helpful!  
Sarah
