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

« back to all changes in this revision

Viewing changes to lib/src/Uncertainty/Algorithm/MetaModel/FunctionalChaos/LeastSquaresStrategy.cxx

  • 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:
3
3
 *  @file  LeastSquaresStrategy.cxx
4
4
 *  @brief An implementation of projection strategy as a leastSquares
5
5
 *
6
 
 *  (C) Copyright 2005-2007 EDF-EADS-Phimeca
 
6
 *  (C) Copyright 2005-2010 EDF-EADS-Phimeca
7
7
 *
8
8
 *  This library is free software; you can redistribute it and/or
9
9
 *  modify it under the terms of the GNU Lesser General Public
26
26
#include "LeastSquaresStrategy.hxx"
27
27
#include "OSS.hxx"
28
28
#include "PersistentObjectFactory.hxx"
29
 
#include "MonteCarloExperiment.hxx"
30
 
#include "LeastSquaresAlgorithm.hxx"
 
29
#include "PenalizedLeastSquaresAlgorithm.hxx"
31
30
 
32
31
namespace OpenTURNS
33
32
{
42
41
 
43
42
      static Base::Common::Factory<LeastSquaresStrategy> RegisteredFactory("LeastSquaresStrategy");
44
43
 
45
 
      typedef Base::Optim::LeastSquaresAlgorithm LeastSquaresAlgorithm;
 
44
      typedef Base::Optim::PenalizedLeastSquaresAlgorithm PenalizedLeastSquaresAlgorithm;
46
45
 
47
46
      /* Default constructor */
48
47
      LeastSquaresStrategy::LeastSquaresStrategy()
49
 
        : ProjectionStrategyImplementation(),
50
 
          p_weightedExperiment_(MonteCarloExperiment().clone()),
51
 
          inputSample_(0, 0),
52
 
          outputSample_(0, 0)
 
48
        : ProjectionStrategyImplementation()
53
49
      {
54
 
        // The leastSquares strategy impose its distribution to the weighted experiment
55
 
        p_weightedExperiment_->setDistribution(getMeasure());
 
50
        // Nothing to do
56
51
      }
57
52
 
58
53
      /* Parameter constructor */
59
54
      LeastSquaresStrategy::LeastSquaresStrategy(const Distribution & measure)
60
 
        : ProjectionStrategyImplementation(measure),
61
 
          p_weightedExperiment_(MonteCarloExperiment().clone()),
62
 
          inputSample_(0, 0),
63
 
          outputSample_(0, 0)
 
55
        : ProjectionStrategyImplementation(measure)
64
56
      {
65
 
        // The leastSquares strategy impose its distribution to the weighted experiment
66
 
        p_weightedExperiment_->setDistribution(getMeasure());
 
57
        // Nothing to do
67
58
      }
68
59
 
69
60
      /* Parameter constructor */
70
61
      LeastSquaresStrategy::LeastSquaresStrategy(const WeightedExperiment & weightedExperiment)
71
 
        : ProjectionStrategyImplementation(weightedExperiment.getDistribution()),
72
 
          p_weightedExperiment_(weightedExperiment.clone()),
73
 
          inputSample_(0, 0),
74
 
          outputSample_(0, 0)
 
62
        : ProjectionStrategyImplementation(weightedExperiment)
75
63
      {
76
 
        // The leastSquares strategy get its measure from the weighted experiment, nothing special to do
 
64
        // Nothing to do
77
65
      }
78
66
 
79
67
      /* Parameter constructor */
80
68
      LeastSquaresStrategy::LeastSquaresStrategy(const Distribution & measure,
81
69
                                                 const WeightedExperiment & weightedExperiment)
82
 
        : ProjectionStrategyImplementation(measure),
83
 
          p_weightedExperiment_(weightedExperiment.clone()),
84
 
          inputSample_(0, 0),
85
 
          outputSample_(0, 0)
 
70
        : ProjectionStrategyImplementation(measure, weightedExperiment)
86
71
      {
87
 
        // The leastSquares strategy impose the distribution of the weighted experiment
88
 
        p_weightedExperiment_->setDistribution(getMeasure());
 
72
        // Nothing to do
89
73
      }
90
74
 
91
75
      
95
79
        return new LeastSquaresStrategy(*this);
96
80
      }
97
81
 
98
 
      /* Measure accessor */
99
 
      void LeastSquaresStrategy::setMeasure(const Distribution & measure)
100
 
      {
101
 
        ProjectionStrategyImplementation::setMeasure(measure);
102
 
        // Set the measure as the distribution of the weighted experiment
103
 
        p_weightedExperiment_->setDistribution(getMeasure());
104
 
      }
105
 
 
106
 
      /* Experiment accessors */
107
 
      void LeastSquaresStrategy::setExperiment(const WeightedExperiment & weightedExperiment)
108
 
      {
109
 
        p_weightedExperiment_ = weightedExperiment.clone();
110
 
        p_weightedExperiment_->setDistribution(getMeasure());
111
 
      }
112
 
 
113
 
      WeightedExperiment LeastSquaresStrategy::getExperiment() const
114
 
      {
115
 
        return *p_weightedExperiment_;
116
 
      }
117
 
 
118
82
     /* String converter */
119
83
      String LeastSquaresStrategy::__repr__() const
120
84
      {
130
94
      void LeastSquaresStrategy::computeCoefficients(const NumericalMathFunction & function,
131
95
                                                     const NumericalMathFunctionCollection & partialBasis,
132
96
                                                     const Indices & indices,
133
 
                                                     const Indices & addedIndices,
134
 
                                                     const Indices & removedIndices)
 
97
                                                     const Indices & addedRanks,
 
98
                                                     const Indices & conservedRanks,
 
99
                                                     const Indices & removedRanks)
135
100
      {
136
101
        // If the input sample has not yet been generated
137
102
        // we have to generate it and to evaluate the model
138
103
        // upon this sample
139
104
        if (inputSample_.getSize() == 0)
140
105
          {
141
 
            inputSample_  = p_weightedExperiment_->generate();
 
106
            inputSample_  = p_weightedExperiment_->generate(weights_);
142
107
            outputSample_ = function(inputSample_);
143
108
          }
144
109
        // Compute the coefficients and the residual using the least square algorithm
145
 
        LeastSquaresAlgorithm algo(inputSample_, outputSample_, p_weightedExperiment_->getWeight(), partialBasis);
 
110
        PenalizedLeastSquaresAlgorithm algo(inputSample_, outputSample_, weights_, partialBasis);
146
111
        alpha_k_p_ = algo.getCoefficients();
147
112
        residual_p_ = algo.getResidual();
148
113
      }
149
114
 
150
115
 
151
116
      /* Method save() stores the object through the StorageManager */
152
 
      void LeastSquaresStrategy::save(const StorageManager::Advocate & adv) const
 
117
      void LeastSquaresStrategy::save(StorageManager::Advocate & adv) const
153
118
      {
154
119
        ProjectionStrategyImplementation::save(adv);
155
120
      }
156
121
 
157
122
 
158
123
      /* Method load() reloads the object from the StorageManager */
159
 
      void LeastSquaresStrategy::load(const StorageManager::Advocate & adv)
 
124
      void LeastSquaresStrategy::load(StorageManager::Advocate & adv)
160
125
      {
161
126
        ProjectionStrategyImplementation::load(adv);
162
127
      }