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

« back to all changes in this revision

Viewing changes to lib/src/Uncertainty/Algorithm/IsoProbabilisticTransformation/MarginalTransformation/InverseMarginalTransformationEvaluation.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2008-11-18 06:32:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20081118063222-pa0qncclrerrqkg2
Tags: 0.12.2-1
* New upstream release
* Bug fix: "New upstream release available (0.12.2)", thanks to Jerome
  Robert (Closes: #506005).
* Applied patch by J. Robert.
* debian/control: build-depends on libxml2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//                                               -*- C++ -*-
 
2
/**
 
3
 *  @file  InverseMarginalTransformationEvaluation.cxx
 
4
 *  @brief Class for the Nataf transformation evaluation for elliptical
 
5
 *
 
6
 *  (C) Copyright 2005-2007 EDF-EADS-Phimeca
 
7
 *
 
8
 *  This library is free software; you can redistribute it and/or
 
9
 *  modify it under the terms of the GNU Lesser General Public
 
10
 *  License as published by the Free Software Foundation; either
 
11
 *  version 2.1 of the License.
 
12
 *
 
13
 *  This library is distributed in the hope that it will be useful
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 *  Lesser General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU Lesser General Public
 
19
 *  License along with this library; if not, write to the Free Software
 
20
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
21
 *
 
22
 *  @author: $LastChangedBy: dutka $
 
23
 *  @date:   $LastChangedDate: 2008-10-31 11:52:04 +0100 (ven 31 oct 2008) $
 
24
 *  Id:      $Id: InverseMarginalTransformationEvaluation.cxx 995 2008-10-31 10:52:04Z dutka $
 
25
 */
 
26
#include "InverseMarginalTransformationEvaluation.hxx"
 
27
 
 
28
namespace OpenTURNS {
 
29
 
 
30
  namespace Uncertainty {
 
31
 
 
32
    namespace Algorithm {
 
33
 
 
34
 
 
35
 
 
36
      CLASSNAMEINIT(InverseMarginalTransformationEvaluation);
 
37
 
 
38
      /* Parameter constructor */
 
39
      InverseMarginalTransformationEvaluation::InverseMarginalTransformationEvaluation(const DistributionCollection & distributionCollection):
 
40
        NumericalMathEvaluationImplementation(),
 
41
        distributionCollection_(distributionCollection)
 
42
      {
 
43
        Description description;
 
44
        UnsignedLong size(distributionCollection.getSize());
 
45
        for (UnsignedLong i = 0; i < size; ++i)
 
46
          {
 
47
            OSS oss;
 
48
            oss << "x" << i;
 
49
            description.add(oss);
 
50
          }
 
51
        for (UnsignedLong i = 0; i < size; ++i)
 
52
          {
 
53
            OSS oss;
 
54
            oss << "y" << i;
 
55
            description.add(oss);
 
56
          }
 
57
        setDescription(description);
 
58
      }
 
59
 
 
60
      /* Virtual constructor */
 
61
      InverseMarginalTransformationEvaluation * InverseMarginalTransformationEvaluation::clone() const
 
62
      {
 
63
        return new InverseMarginalTransformationEvaluation(*this);
 
64
      }
 
65
 
 
66
      /* Evaluation */
 
67
      InverseMarginalTransformationEvaluation::NumericalPoint InverseMarginalTransformationEvaluation::operator () (const NumericalPoint & in) const
 
68
        throw (InvalidArgumentException, InternalException)
 
69
      {
 
70
        UnsignedLong dimension(getOutputNumericalPointDimension());
 
71
        NumericalPoint result(dimension);
 
72
        // Apply quantile over the components
 
73
        for (UnsignedLong i = 0; i < dimension; ++i)
 
74
          {
 
75
            result[i] = distributionCollection_[i].computeQuantile(in[i])[0];
 
76
          }
 
77
        return result;
 
78
      }
 
79
 
 
80
      /*
 
81
       * Gradient according to the marginal parameters.
 
82
       * F(Q(y, p), p) = Id
 
83
       * F:RxRp->R
 
84
       * Q:RxRp->R
 
85
       * dF/dp = dF/dx(Q(y, p), p) . dQ/dp(y, p) + dF/dp(Q(y, p), p)
 
86
       *       = f(Q(y, p), p) . dQ/dp(y, p) + dF/dp(Q(y, p), p)
 
87
       *       = 0
 
88
       * => dQ/dp(y, p) = - dF/dp(Q(y, p), p) / f(Q(y, p), p)
 
89
       */
 
90
      InverseMarginalTransformationEvaluation::Matrix InverseMarginalTransformationEvaluation::parametersGradient(const NumericalPoint & in) const
 
91
      {
 
92
        const NumericalPoint parameters(getParameters());
 
93
        const UnsignedLong parametersDimension(parameters.getDimension());
 
94
        const UnsignedLong inputDimension(getInputNumericalPointDimension());
 
95
        Matrix result(parametersDimension, inputDimension);
 
96
        UnsignedLong rowIndex(0);
 
97
        for (UnsignedLong j = 0; j < inputDimension; ++j)
 
98
          {
 
99
            const NumericalPoint x(distributionCollection_[j].computeQuantile(in[j]));
 
100
            const NumericalPoint marginalCDFGradient(distributionCollection_[j].computeCDFGradient(x));
 
101
            const NumericalScalar pdf(distributionCollection_[j].computePDF(x));
 
102
            const NumericalPoint marginalQuantileGradient((-1.0 / pdf) * marginalCDFGradient);
 
103
            const UnsignedLong marginalParametersDimension(marginalCDFGradient.getDimension());
 
104
            for (UnsignedLong i = 0; i < marginalParametersDimension; ++i)
 
105
              {
 
106
                result(rowIndex, j) = marginalQuantileGradient[i];
 
107
                rowIndex++;
 
108
              }
 
109
          }
 
110
        return result;
 
111
      }
 
112
 
 
113
      /* Accessor for input point dimension */
 
114
      UnsignedLong InverseMarginalTransformationEvaluation::getInputNumericalPointDimension() const
 
115
        throw(InternalException)
 
116
      {
 
117
        return distributionCollection_.getSize();
 
118
      }
 
119
 
 
120
      /* Accessor for output point dimension */
 
121
      UnsignedLong InverseMarginalTransformationEvaluation::getOutputNumericalPointDimension() const
 
122
        throw(InternalException)
 
123
      {
 
124
        return distributionCollection_.getSize();
 
125
      }
 
126
 
 
127
      /* String converter */
 
128
      String InverseMarginalTransformationEvaluation::str() const
 
129
      {
 
130
        OSS oss;
 
131
        oss << "class=" << InverseMarginalTransformationEvaluation::GetClassName();                   
 
132
        return oss;
 
133
      }
 
134
 
 
135
    } /* namespace Algorithm */
 
136
  } /* namespace Uncertainty */
 
137
} /* namespace OpenTURNS */
 
138