4
4
* @brief Implementation of the box experiment plane
6
* (C) Copyright 2005-2007 EDF-EADS-Phimeca
6
* (C) Copyright 2005-2010 EDF-EADS-Phimeca
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
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 $
27
27
#include "OTprivate.hxx"
29
#include "Collection.hxx"
29
#include "Indices.hxx"
31
31
namespace OpenTURNS {
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)
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());
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)
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 */
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];
108
108
/** Specific levels accessor */
109
void Box::setLevels(const NumericalPoint & levels) throw(InvalidArgumentException)
109
void Box::setLevels(const NumericalPoint & levels) /* throw(InvalidArgumentException) */
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++)
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";
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);