queso-0.53.0
GslVector.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
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. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 //--------------------------------------------------------------------------
25 
26 #ifndef UQ_GSL_VECTOR_H
27 #define UQ_GSL_VECTOR_H
28 
33 #include <queso/Defines.h>
34 #include <queso/Vector.h>
35 #include <gsl/gsl_vector.h>
36 
37 namespace QUESO {
38 
48 class GslVector : public Vector
49 {
50 public:
51 
53 
54 
55  GslVector(const BaseEnvironment& env, const Map& map);
56  GslVector(const BaseEnvironment& env, const Map& map, double value);
57  GslVector(const BaseEnvironment& env, double d1, double d2, const Map& map); // MATLAB linspace
58 
60  GslVector(const GslVector& v, double start, double end);
61  GslVector(const GslVector& y);
62 
64  ~GslVector();
66 
68 
69  GslVector& operator= (const GslVector& rhs);
71 
73  GslVector& operator*=(double a);
74 
76  GslVector& operator/=(double a);
77 
79  GslVector& operator*=(const GslVector& rhs);
80 
82  GslVector& operator/=(const GslVector& rhs);
83 
85  GslVector& operator+=(const GslVector& rhs);
86 
88  GslVector& operator-=(const GslVector& rhs);
90 
92 
93 
95  double& operator[](unsigned int i);
96 
98 
100  const double& operator[](unsigned int i) const;
102 
104 
105  unsigned int sizeLocal () const;
107 
109  unsigned int sizeGlobal () const;
111 
113 
114  double norm2Sq () const;
116 
118  double norm2 () const;
119 
121  double norm1 () const;
122 
124  double normInf () const;
125 
127  double sumOfComponents () const;
129 
131 
132  void cwSet (double value);
134 
136  void cwSetGaussian (double mean, double stdDev);
137 
139  void cwSetGaussian (const GslVector& meanVec, const GslVector& stdDevVec);
140 
142  void cwSetUniform (const GslVector& aVec, const GslVector& bVec);
143 
145  void cwSetBeta (const GslVector& alpha, const GslVector& beta);
146 
148  void cwSetGamma (const GslVector& a, const GslVector& b);
149 
151  void cwSetInverseGamma(const GslVector& alpha, const GslVector& beta);
152 
154  void cwSetConcatenated(const GslVector& v1, const GslVector& v2);
155 
157  void cwSetConcatenated(const std::vector<const GslVector* >& vecs);
158 
160  void cwSet (unsigned int initialPos, const GslVector& vec);
161 
163  void cwExtract (unsigned int initialPos, GslVector& vec) const;
164 
166  void cwInvert ();
167 
169  void cwSqrt ();
171 
173 
174  void print (std::ostream& os) const;
177 
179  void sort ();
180 
181  void matlabDiff (unsigned int firstPositionToStoreDiff, double valueForRemainderPosition, GslVector& outputVec) const;
182  void matlabLinearInterpExtrap(const GslVector& x1Vec, const GslVector& y1Vec, const GslVector& x2Vec);
183  void mpiBcast (int srcRank, const MpiComm& bcastComm);
184  void mpiAllReduce (RawType_MPI_Op mpiOperation, const MpiComm& opComm, GslVector& resultVec) const;
185  void mpiAllQuantile (double probability, const MpiComm& opComm, GslVector& resultVec) const;
186  void subWriteContents (const std::string& varNamePrefix,
187  const std::string& fileName,
188  const std::string& fileType,
189  const std::set<unsigned int>& allowedSubEnvIds) const;
190  void subReadContents (const std::string& fileName,
191  const std::string& fileType,
192  const std::set<unsigned int>& allowedSubEnvIds);
193 
195 
196  bool atLeastOneComponentSmallerThan (const GslVector& rhs) const;
198 
200  bool atLeastOneComponentBiggerThan (const GslVector& rhs) const;
201 
203  bool atLeastOneComponentSmallerOrEqualThan(const GslVector& rhs) const;
204 
206  bool atLeastOneComponentBiggerOrEqualThan (const GslVector& rhs) const;
208 
209  // Necessary for GslMatrix::invertMultiply() and GslMatrix::setRow/Column
210  gsl_vector* data () const;
211 
213 
214  double getMaxValue () const;
216 
218  double getMinValue () const;
219 
221  int getMaxValueIndex () const;
222 
224  int getMinValueIndex () const;
225 
227  void getMaxValueAndIndex( double& value, int& index );
228 
230  void getMinValueAndIndex( double& value, int& index );
231 
233  GslVector abs() const;
235 private:
237 
238  GslVector();
239 
241  void copy (const GslVector& src);
242 
244  gsl_vector* m_vec;
245 };
246 
247 // Comments in this part of file don't appear in the doxygen docs.
248 
249 GslVector operator/ ( double a, const GslVector& x );
250 GslVector operator/ (const GslVector& x, const GslVector& y );
251 GslVector operator* ( double a, const GslVector& x );
252 GslVector operator* (const GslVector& x, const GslVector& y );
253 double scalarProduct(const GslVector& x, const GslVector& y );
254 GslVector operator+ (const GslVector& x, const GslVector& y );
255 GslVector operator- (const GslVector& x, const GslVector& y );
256 bool operator== (const GslVector& lhs, const GslVector& rhs);
257 std::ostream& operator<< (std::ostream& os, const GslVector& obj);
258 
259 } // End namespace QUESO
260 
261 #endif // UQ_GSL_VECTOR_H
GslMatrix operator*(double a, const GslMatrix &mat)
Definition: GslMatrix.C:1972
Class for vector operations (virtual).
Definition: Vector.h:47
double sumOfComponents() const
Returns the sum of the components of the vector.
Definition: GslVector.C:327
int getMaxValueIndex() const
This function returns the index of the maximum value in the vector this.
Definition: GslVector.C:1064
bool atLeastOneComponentSmallerOrEqualThan(const GslVector &rhs) const
This function returns true if at least one component of this is smaller than or equal to the respecti...
Definition: GslVector.C:1020
GslVector & operator+=(const GslVector &rhs)
Stores in this the coordinate-wise addition of this and rhs.
Definition: GslVector.C:211
void cwSetGaussian(double mean, double stdDev)
This function sets component-wise Gaussian random variates, with mean mean and standard deviation std...
Definition: GslVector.C:350
GslVector abs() const
This function returns absolute value of elements in this.
Definition: GslVector.C:1094
void cwExtract(unsigned int initialPos, GslVector &vec) const
This function sets the values of this starting at position initialPos ans saves them in vector vec...
Definition: GslVector.C:508
double getMaxValue() const
Returns the maximum value in the vector this.
Definition: GslVector.C:1052
bool atLeastOneComponentSmallerThan(const GslVector &rhs) const
This function returns true if at least one component of this is smaller than the respective component...
Definition: GslVector.C:988
double getMinValue() const
Returns minimum value in the vector this.
Definition: GslVector.C:1058
bool atLeastOneComponentBiggerThan(const GslVector &rhs) const
This function returns true if at least one component of this is bigger than the respective component ...
Definition: GslVector.C:1004
MPI_Op RawType_MPI_Op
Definition: MpiComm.h:41
bool atLeastOneComponentBiggerOrEqualThan(const GslVector &rhs) const
This function returns true if at least one component of this is bigger than or equal to the respectiv...
Definition: GslVector.C:1036
void getMinValueAndIndex(double &value, int &index)
This function returns minimum value in the vector this and its the index.
Definition: GslVector.C:1085
void cwSqrt()
This function returns component-wise the square-root of this.
Definition: GslVector.C:533
unsigned int sizeGlobal() const
Returns the global length of this vector.
Definition: GslVector.C:279
double & operator[](unsigned int i)
Element access method (non-const).
Definition: GslVector.C:230
GslVector & operator*=(double a)
Stores in this the coordinate-wise multiplication of this and a.
Definition: GslVector.C:166
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:253
void cwSetConcatenated(const GslVector &v1, const GslVector &v2)
This function concatenates GslVector v1 and GslVector v2 into this.
Definition: GslVector.C:461
void cwSetInverseGamma(const GslVector &alpha, const GslVector &beta)
This function returns a random variate from the inverse gamma distribution with vector parameters alp...
Definition: GslVector.C:448
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
void getMaxValueAndIndex(double &value, int &index)
This function returns maximum value in the vector this and its the index.
Definition: GslVector.C:1076
GslVector operator/(double a, const GslVector &x)
Definition: GslVector.C:1117
GslMatrix operator+(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2012
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:244
The QUESO MPI Communicator Class.
Definition: MpiComm.h:75
void cwSetBeta(const GslVector &alpha, const GslVector &beta)
This function returns a random variate from the beta distribution, with vector parameters alpha and b...
Definition: GslVector.C:378
double scalarProduct(const GslVector &x, const GslVector &y)
Definition: GslVector.C:1150
void matlabDiff(unsigned int firstPositionToStoreDiff, double valueForRemainderPosition, GslVector &outputVec) const
Definition: GslVector.C:544
double norm2() const
Returns the 2-norm (Euclidean norm) of the vector.
Definition: GslVector.C:293
void cwInvert()
This function inverts component-wise the element values of this.
Definition: GslVector.C:522
void mpiBcast(int srcRank, const MpiComm &bcastComm)
Definition: GslVector.C:647
const BaseEnvironment & env() const
Definition: Vector.C:54
Class for vector operations using GSL library.
Definition: GslVector.h:48
GslVector & operator=(const GslVector &rhs)
Copies values from vector rhs to this.
Definition: GslVector.C:150
void cwSet(double value)
Component-wise sets all values to this with value.
Definition: GslVector.C:339
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
void mpiAllReduce(RawType_MPI_Op mpiOperation, const MpiComm &opComm, GslVector &resultVec) const
Definition: GslVector.C:702
void cwSetUniform(const GslVector &aVec, const GslVector &bVec)
This function sets component-wise a number uniformly distributed in the range of elements of [aVec...
Definition: GslVector.C:369
GslVector & operator-=(const GslVector &rhs)
Stores in this the coordinate-wise subtraction of this by rhs.
Definition: GslVector.C:220
int getMinValueIndex() const
This function returns the index of the minimum value in the vector this.
Definition: GslVector.C:1070
~GslVector()
Destructor.
Definition: GslVector.C:144
void sort()
This function sorts the elements of the vector this in ascending numerical order. ...
Definition: GslVector.C:639
void subReadContents(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds)
Definition: GslVector.C:855
const Map & map() const
Definition: Vector.C:61
GslVector & operator/=(double a)
Stores in this the coordinate-wise division of this by a.
Definition: GslVector.C:175
GslMatrix operator-(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2019
GslVector()
Default Constructor.
double norm1() const
Returns the 1-norm of the vector.
Definition: GslVector.C:299
gsl_vector * data() const
Definition: GslVector.C:982
void copy(const GslVector &src)
This function copies the elements of the vector src into this.
Definition: GslVector.C:242
A class for partitioning vectors and matrices.
Definition: Map.h:49
void mpiAllQuantile(double probability, const MpiComm &opComm, GslVector &resultVec) const
Definition: GslVector.C:723
void matlabLinearInterpExtrap(const GslVector &x1Vec, const GslVector &y1Vec, const GslVector &x2Vec)
Definition: GslVector.C:569
void print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream &lt;&lt; operator inherited from the Object class...
Definition: GslVector.C:755
double normInf() const
Returns the infinity-norm (maximum norm) of the vector.
Definition: GslVector.C:312
void cwSetGamma(const GslVector &a, const GslVector &b)
This function returns a random variate from the gamma distribution with vector parameters a and b...
Definition: GslVector.C:435
double norm2Sq() const
Returns the 2-norm squared of this vector.
Definition: GslVector.C:287
bool operator==(const GslVector &lhs, const GslVector &rhs)
Definition: GslVector.C:1181
void subWriteContents(const std::string &varNamePrefix, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
Definition: GslVector.C:815

Generated on Thu Jun 11 2015 13:52:31 for queso-0.53.0 by  doxygen 1.8.5