~ubuntu-branches/ubuntu/maverick/openturns/maverick

« back to all changes in this revision

Viewing changes to python/test/t_CorrelationAnalysis_sobol.py

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2010-05-10 17:27:55 UTC
  • mfrom: (1.1.4 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100510172755-cb5ynskknqqi5rhp
Tags: 0.13.2-2ubuntu1
* Merge with Debian testing. No changes left.
* ubuntu_fix-python-2.6.patch: fix detection of python 2.6 libs, to not use
  LOCALMODLIBS. This pulls a dependency on SSL and makes the package FTBFS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
try :
9
9
 
10
 
                dimension = 3;
11
 
                sampleSize = 1000;
12
 
 
13
 
                # we create an analytical function
14
 
                input = Description(dimension);
15
 
                input[0] = "x0";
16
 
                input[1] = "x1";
17
 
                input[2] = "x2";
18
 
                print "input=", input
19
 
                
20
 
                foutput = Description(1);
21
 
                foutput[0] = "f0";
22
 
                print "output=", foutput
23
 
 
24
 
                formulas = Description(foutput.getSize());
25
 
                formulas[0] = "sin(x0)+7*sin(x1)^2+0.1*x2^4*sin(x0)";
26
 
                
27
 
                analytical = NumericalMathFunction(input, foutput, formulas);
28
 
                print "analytical=", analytical
29
 
 
30
 
                # we create a collection of uniform distributions over [-Pi; Pi[
31
 
                aCollection = DistributionCollection();
32
 
                for i in range(dimension) :
33
 
                        aCollection.add(Distribution(Uniform(-pi, +pi)));
34
 
 
35
 
                # we create an independent copula
36
 
                aCopula = IndependentCopula(aCollection.getSize());
37
 
                aCopula.setName("an independent copula");
38
 
 
39
 
                # we create one distribution object
40
 
                aDistribution = ComposedDistribution(aCollection, Copula(aCopula));
41
 
                aDistribution.setName("a uniform distribution");
42
 
 
43
 
                # we create two input samples for the function
44
 
                firstInputSample = aDistribution.getNumericalSample(sampleSize);
45
 
                secondInputSample = aDistribution.getNumericalSample(sampleSize);
46
 
 
47
 
        # Choose which indices to compute
48
 
                indiceParameters = CorrelationAnalysisSobolIndiceParameters();
49
 
                # Choose to compute indices until order 3 (requires computation of inferior order indices)
50
 
                indiceParameters.setMaximumOrder(3);
51
 
                # Choose to compute total order indices
52
 
                indiceParameters.setTotalIndiceComputation(True);
53
 
 
54
 
                # Compute the Sobol' indices
55
 
                myResult = CorrelationAnalysis.SobolIndice(indiceParameters, firstInputSample, secondInputSample, analytical);
56
 
 
57
 
        # Retrieve the indices from result according to the selected indices via indiceParameters
58
 
                # firstOrderIndice[i] is the first order indice of variable i
59
 
                firstOrderIndice = NumericalPoint(myResult.getFirstOrderIndice());
60
 
                # secondOrderIndice(i, j) is the second order indice for both variables i and j (i not equal to j)
61
 
                secondOrderIndice = SymmetricMatrix(myResult.getSecondOrderIndice());
62
 
                # thirdOrderIndice(i, j, k) is the indice for the subset of variables {i, j, k} (i, j and k are different)
63
 
                thirdOrderIndice = SymmetricTensor(myResult.getThirdOrderIndice());
64
 
                 # totalOrder[i] is the total indice for variable i
65
 
                totalOrderIndice = NumericalPoint(myResult.getTotalOrderIndice());
66
 
 
67
 
                # stream out the indices
68
 
                print "first order indices=", firstOrderIndice;
69
 
                print "second order indices=", secondOrderIndice;
70
 
                print "third order indices=", thirdOrderIndice;
71
 
                print "total order indices=", totalOrderIndice;
 
10
    dimension = 3;
 
11
    sampleSize = 1000;
 
12
 
 
13
    # we create an analytical function
 
14
    input = Description(dimension);
 
15
    input[0] = "x0";
 
16
    input[1] = "x1";
 
17
    input[2] = "x2";
 
18
    print "input=", input
 
19
 
 
20
    foutput = Description(1);
 
21
    foutput[0] = "f0";
 
22
    print "output=", foutput
 
23
 
 
24
    formulas = Description(foutput.getSize());
 
25
    formulas[0] = "sin(x0)+7*sin(x1)^2+0.1*x2^4*sin(x0)";
 
26
 
 
27
    analytical = NumericalMathFunction(input, foutput, formulas);
 
28
    print "analytical=", analytical
 
29
 
 
30
    # we create a collection of uniform distributions over [-Pi; Pi[
 
31
    aCollection = DistributionCollection();
 
32
    for i in range(dimension) :
 
33
        aCollection.add(Distribution(Uniform(-pi, +pi)));
 
34
 
 
35
    # we create an independent copula
 
36
    aCopula = IndependentCopula(aCollection.getSize());
 
37
    aCopula.setName("an independent copula");
 
38
 
 
39
    # we create one distribution object
 
40
    aDistribution = ComposedDistribution(aCollection, Copula(aCopula));
 
41
    aDistribution.setName("a uniform distribution");
 
42
 
 
43
    # we create two input samples for the function
 
44
    firstInputSample = aDistribution.getNumericalSample(sampleSize);
 
45
    secondInputSample = aDistribution.getNumericalSample(sampleSize);
 
46
 
 
47
    # Choose which indices to compute
 
48
    indiceParameters = CorrelationAnalysisSobolIndiceParameters();
 
49
    # Choose to compute indices until order 3 (requires computation of inferior order indices)
 
50
    indiceParameters.setMaximumOrder(3);
 
51
    # Choose to compute total order indices
 
52
    indiceParameters.setTotalIndiceComputation(True);
 
53
 
 
54
    # Compute the Sobol' indices
 
55
    myResult = CorrelationAnalysis.SobolIndice(indiceParameters, firstInputSample, secondInputSample, analytical);
 
56
 
 
57
    # Retrieve the indices from result according to the selected indices via indiceParameters
 
58
    # firstOrderIndice[i] is the first order indice of variable i
 
59
    firstOrderIndice = NumericalPoint(myResult.getFirstOrderIndice());
 
60
    # secondOrderIndice(i, j) is the second order indice for both variables i and j (i not equal to j)
 
61
    secondOrderIndice = SymmetricMatrix(myResult.getSecondOrderIndice());
 
62
    # thirdOrderIndice(i, j, k) is the indice for the subset of variables {i, j, k} (i, j and k are different)
 
63
    thirdOrderIndice = SymmetricTensor(myResult.getThirdOrderIndice());
 
64
    # totalOrder[i] is the total indice for variable i
 
65
    totalOrderIndice = NumericalPoint(myResult.getTotalOrderIndice());
 
66
 
 
67
    # stream out the indices
 
68
    print "first order indices=", repr(firstOrderIndice);
 
69
    print "second order indices=", repr(secondOrderIndice);
 
70
    print "third order indices=", repr(thirdOrderIndice);
 
71
    print "total order indices=", repr(totalOrderIndice);
72
72
 
73
73
except :
74
74
  import sys