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

« back to all changes in this revision

Viewing changes to lib/src/Uncertainty/Algorithm/IsoProbabilisticTransformation/MarginalTransformation/MarginalTransformationFunction.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  MarginalTransformationFunction.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-06-26 13:50:17 +0200 (jeu, 26 jun 2008) $
24
 
 *  Id:      $Id: MarginalTransformationFunction.cxx 862 2008-06-26 11:50:17Z dutka $
25
 
 */
26
 
#include "MarginalTransformationFunction.hxx"
27
 
 
28
 
namespace OpenTURNS {
29
 
 
30
 
  namespace Uncertainty {
31
 
 
32
 
    namespace Algorithm {
33
 
 
34
 
 
35
 
 
36
 
      CLASSNAMEINIT(MarginalTransformationFunction);
37
 
 
38
 
      /* Parameter constructor */
39
 
      MarginalTransformationFunction::MarginalTransformationFunction(const DistributionCollection & distributionCollection,
40
 
                                                                     const String & name):
41
 
        NumericalMathEvaluationImplementation(name),
42
 
        distributionCollection_(distributionCollection)
43
 
      {
44
 
        Description description;
45
 
        UnsignedLong size(distributionCollection.getSize());
46
 
        for (UnsignedLong i = 0; i < size; ++i)
47
 
          {
48
 
            OSS oss;
49
 
            oss << "x" << i;
50
 
            description.add(oss);
51
 
          }
52
 
        for (UnsignedLong i = 0; i < size; ++i)
53
 
          {
54
 
            OSS oss;
55
 
            oss << "y" << i;
56
 
            description.add(oss);
57
 
          }
58
 
        setDescription(description);
59
 
      }
60
 
 
61
 
      /* Virtual constructor */
62
 
      MarginalTransformationFunction * MarginalTransformationFunction::clone() const
63
 
      {
64
 
        return new MarginalTransformationFunction(*this);
65
 
      }
66
 
 
67
 
      /* Evaluation */
68
 
      MarginalTransformationFunction::NumericalPoint MarginalTransformationFunction::operator () (const NumericalPoint & in) const
69
 
        throw (InvalidArgumentException, InternalException)
70
 
      {
71
 
        UnsignedLong dimension(getOutputNumericalPointDimension());
72
 
        NumericalPoint result(dimension);
73
 
        // Apply CDF over the components
74
 
        for (UnsignedLong i = 0; i < dimension; ++i)
75
 
          {
76
 
            result[i] = distributionCollection_[i].computeCDF(NumericalPoint(1, in[i]));
77
 
          }
78
 
        return result;
79
 
      }
80
 
 
81
 
      /* Gradient according to the marginal parameters. */
82
 
      MarginalTransformationFunction::Matrix MarginalTransformationFunction::parametersGradient(const NumericalPoint & in) const
83
 
      {
84
 
        NumericalPoint parameters(getParameters());
85
 
        UnsignedLong parametersDimension(parameters.getDimension());
86
 
        UnsignedLong inputDimension(getInputNumericalPointDimension());
87
 
        Matrix result(parametersDimension, inputDimension);
88
 
        UnsignedLong rowIndex(0);
89
 
        for (UnsignedLong j = 0; j < inputDimension; ++j)
90
 
          {
91
 
            NumericalPoint marginalCDFGradient(distributionCollection_[j].computeCDFGradient(NumericalPoint(1, in[j])));
92
 
            UnsignedLong marginalParametersDimension(marginalCDFGradient.getDimension());
93
 
            for (UnsignedLong i = 0; i < marginalParametersDimension; ++i)
94
 
              {
95
 
                result(rowIndex, j) = marginalCDFGradient[i];
96
 
                rowIndex++;
97
 
              }
98
 
          }
99
 
        return result;
100
 
      }
101
 
 
102
 
      /* Accessor for input point dimension */
103
 
      UnsignedLong MarginalTransformationFunction::getInputNumericalPointDimension() const
104
 
        throw(InternalException)
105
 
      {
106
 
        return distributionCollection_.getSize();
107
 
      }
108
 
 
109
 
      /* Accessor for output point dimension */
110
 
      UnsignedLong MarginalTransformationFunction::getOutputNumericalPointDimension() const
111
 
        throw(InternalException)
112
 
      {
113
 
        return distributionCollection_.getSize();
114
 
      }
115
 
 
116
 
      /* String converter */
117
 
      String MarginalTransformationFunction::str() const
118
 
      {
119
 
        OSS oss;
120
 
        oss << "class=" << MarginalTransformationFunction::GetClassName()
121
 
            << " description=" << getDescription()
122
 
            << " marginals=" << distributionCollection_;                   
123
 
        return oss;
124
 
      }
125
 
 
126
 
    } /* namespace Algorithm */
127
 
  } /* namespace Uncertainty */
128
 
} /* namespace OpenTURNS */
129