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

« back to all changes in this revision

Viewing changes to lib/src/Uncertainty/Algorithm/Experiments/Box.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  Box.cxx
4
4
 *  @brief Implementation of the box experiment plane
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
20
20
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21
21
 *
22
22
 *  @author: $LastChangedBy: dutka $
23
 
 *  @date:   $LastChangedDate: 2009-05-28 14:47:53 +0200 (jeu. 28 mai 2009) $
24
 
 *  Id:      $Id: Box.cxx 1262 2009-05-28 12:47:53Z dutka $
 
23
 *  @date:   $LastChangedDate: 2010-02-04 16:44:49 +0100 (jeu. 04 févr. 2010) $
 
24
 *  Id:      $Id: Box.cxx 1473 2010-02-04 15:44:49Z dutka $
25
25
 */
26
26
#include <cmath>
27
27
#include "OTprivate.hxx"
28
28
#include "Box.hxx"
29
 
#include "Collection.hxx"
 
29
#include "Indices.hxx"
30
30
 
31
31
namespace OpenTURNS {
32
32
 
36
36
 
37
37
      CLASSNAMEINIT(Box);
38
38
 
39
 
      typedef Base::Type::Collection<UnsignedLong> UnsignedLongCollection;
 
39
      typedef Base::Type::Indices Indices;
40
40
 
41
41
      /* Default constructor */
42
42
      Box::Box(const String & name):
48
48
      /* Constructor with parameters */
49
49
      Box::Box(const NumericalPoint & levels,
50
50
               const String & name)
51
 
        throw(InvalidArgumentException):
52
 
        StratifiedExperiment(NumericalPoint(levels.getDimension(), 0.0), levels, name)
 
51
      /* throw(InvalidArgumentException) */
 
52
        : StratifiedExperiment(NumericalPoint(levels.getDimension(), 0.0), levels, name)
53
53
      {
54
54
        // Check if there is the same number of levels than the dimension of the experiment plane
55
55
        if (levels.getDimension() == 0) throw InvalidArgumentException(HERE) << "Error: the levels dimension must be > 0";
70
70
        /* Dimension of the realizations */
71
71
        const UnsignedLong dimension(center_.getDimension());
72
72
        /* Levels */
73
 
        UnsignedLongCollection levels(dimension);
 
73
        Indices levels(dimension);
74
74
        /* Convert NumericalScalar values to UnsignedLong values for the levels */
75
 
        for (UnsignedLong i = 0; i < dimension; i++) levels[i] = UnsignedLong(round(levels_[i])) + 2;
 
75
        for (UnsignedLong i = 0; i < dimension; ++i) levels[i] = UnsignedLong(round(levels_[i])) + 2;
76
76
        /* Size of the sample to be generated: levels[0] * ... * levels[dimension-1] */
77
77
        UnsignedLong size(levels[0]);
78
 
        for (UnsignedLong i = 1; i < dimension; i++) size *= levels[i];
 
78
        for (UnsignedLong i = 1; i < dimension; ++i) size *= levels[i];
79
79
        NumericalSample boxPlane(size, dimension);
80
80
        boxPlane.setName("Box plane");
81
81
        /* Indices would have stored the indices of the nested loops if we were able to code "dimension" nested loops dynamically */
82
 
        UnsignedLongCollection indices(dimension, 0);
83
 
        for (UnsignedLong flatIndex = 0; flatIndex < size; flatIndex++)
 
82
        Indices indices(dimension, 0);
 
83
        for (UnsignedLong flatIndex = 0; flatIndex < size; ++flatIndex)
84
84
          {
85
85
            NumericalPoint point(dimension, 0.0);
86
 
            for (UnsignedLong i = 0; i < dimension; i++) point[i] += indices[i] / (levels_[i] + 1.0);
 
86
            for (UnsignedLong i = 0; i < dimension; ++i) point[i] += indices[i] / (levels_[i] + 1.0);
87
87
            boxPlane[flatIndex] = point;
88
88
            /* Update the indices */
89
 
            indices[0]++;
 
89
            ++indices[0];
90
90
            /* Propagate the remainders */
91
 
            for (UnsignedLong i = 0; i < dimension - 1; i++) indices[i + 1] += (indices[i] == levels[i]);
 
91
            for (UnsignedLong i = 0; i < dimension - 1; ++i) indices[i + 1] += (indices[i] == levels[i]);
92
92
            /* Correction of the indices. The last index cannot overflow. */
93
 
            for (UnsignedLong i = 0; i < dimension - 1; i++) indices[i] = indices[i] % levels[i];
 
93
            for (UnsignedLong i = 0; i < dimension - 1; ++i) indices[i] = indices[i] % levels[i];
94
94
          }
95
95
        return boxPlane;
96
96
      } // generate()
106
106
      }
107
107
 
108
108
      /** Specific levels accessor */
109
 
      void Box::setLevels(const NumericalPoint & levels) throw(InvalidArgumentException)
 
109
      void Box::setLevels(const NumericalPoint & levels) /* throw(InvalidArgumentException) */
110
110
      {
111
111
        UnsignedLong dimension(center_.getDimension());
112
112
        UnsignedLong size(levels.getDimension());
113
113
        if (size != dimension) throw InvalidArgumentException(HERE) << "Error: levels dimension must equal center dimension for the Box design of experiment, here levels dimension=" << size << " and center dimension=" << dimension;
114
 
        for (UnsignedLong i = 0; i < dimension; i++)
115
 
          {
116
 
            if (levels[i] < 0.0) throw InvalidArgumentException(HERE) << "Error: levels values must be greater or equal to 0 for the Box design of experiment";
117
 
          }
 
114
        for (UnsignedLong i = 0; i < dimension; ++i) if (levels[i] < 0.0) throw InvalidArgumentException(HERE) << "Error: levels values must be greater or equal to 0 for the Box design of experiment";
118
115
        StratifiedExperiment::setLevels(levels);
119
116
      }
120
117