queso-0.52.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 
56 
57  GslVector();
58 
59  GslVector(const BaseEnvironment& env, const Map& map);
60  GslVector(const BaseEnvironment& env, const Map& map, double value);
61  GslVector(const BaseEnvironment& env, double d1, double d2, const Map& map); // MATLAB linspace
62 
64  GslVector(const GslVector& v, double start, double end);
65  GslVector(const GslVector& y);
66 
68  ~GslVector();
70 
72 
73  GslVector& operator= (const GslVector& rhs);
75 
77  GslVector& operator*=(double a);
78 
80  GslVector& operator/=(double a);
81 
83  GslVector& operator*=(const GslVector& rhs);
84 
86  GslVector& operator/=(const GslVector& rhs);
87 
89  GslVector& operator+=(const GslVector& rhs);
90 
92  GslVector& operator-=(const GslVector& rhs);
94 
96 
97 
99  double& operator[](unsigned int i);
100 
102 
104  const double& operator[](unsigned int i) const;
106 
108 
109  unsigned int sizeLocal () const;
111 
113  unsigned int sizeGlobal () const;
115 
117 
118  double norm2Sq () const;
120 
122  double norm2 () const;
123 
125  double norm1 () const;
126 
128  double normInf () const;
129 
131  double sumOfComponents () const;
133 
135 
136  void cwSet (double value);
138 
140  void cwSetGaussian (double mean, double stdDev);
141 
143  void cwSetGaussian (const GslVector& meanVec, const GslVector& stdDevVec);
144 
146  void cwSetUniform (const GslVector& aVec, const GslVector& bVec);
147 
149  void cwSetBeta (const GslVector& alpha, const GslVector& beta);
150 
152  void cwSetGamma (const GslVector& a, const GslVector& b);
153 
155  void cwSetInverseGamma(const GslVector& alpha, const GslVector& beta);
156 
158  void cwSetConcatenated(const GslVector& v1, const GslVector& v2);
159 
161  void cwSetConcatenated(const std::vector<const GslVector* >& vecs);
162 
164  void cwSet (unsigned int initialPos, const GslVector& vec);
165 
167  void cwExtract (unsigned int initialPos, GslVector& vec) const;
168 
170  void cwInvert ();
171 
173  void cwSqrt ();
175 
177 
178  void print (std::ostream& os) const;
181 
183  void sort ();
184 
185  void matlabDiff (unsigned int firstPositionToStoreDiff, double valueForRemainderPosition, GslVector& outputVec) const;
186  void matlabLinearInterpExtrap(const GslVector& x1Vec, const GslVector& y1Vec, const GslVector& x2Vec);
187  void mpiBcast (int srcRank, const MpiComm& bcastComm);
188  void mpiAllReduce (RawType_MPI_Op mpiOperation, const MpiComm& opComm, GslVector& resultVec) const;
189  void mpiAllQuantile (double probability, const MpiComm& opComm, GslVector& resultVec) const;
190  void subWriteContents (const std::string& varNamePrefix,
191  const std::string& fileName,
192  const std::string& fileType,
193  const std::set<unsigned int>& allowedSubEnvIds) const;
194  void subReadContents (const std::string& fileName,
195  const std::string& fileType,
196  const std::set<unsigned int>& allowedSubEnvIds);
197 
199 
200  bool atLeastOneComponentSmallerThan (const GslVector& rhs) const;
202 
204  bool atLeastOneComponentBiggerThan (const GslVector& rhs) const;
205 
207  bool atLeastOneComponentSmallerOrEqualThan(const GslVector& rhs) const;
208 
210  bool atLeastOneComponentBiggerOrEqualThan (const GslVector& rhs) const;
212 
213  // Necessary for GslMatrix::invertMultiply() and GslMatrix::setRow/Column
214  gsl_vector* data () const;
215 
217 
218  double getMaxValue () const;
220 
222  double getMinValue () const;
223 
225  int getMaxValueIndex () const;
226 
228  int getMinValueIndex () const;
229 
231  void getMaxValueAndIndex( double& value, int& index );
232 
234  void getMinValueAndIndex( double& value, int& index );
235 
237  GslVector abs() const;
239 private:
240 
242  void copy (const GslVector& src);
243 
245  gsl_vector* m_vec;
246 };
247 
248 // Comments in this part of file don't appear in the doxygen docs.
249 
250 GslVector operator/ ( double a, const GslVector& x );
251 GslVector operator/ (const GslVector& x, const GslVector& y );
252 GslVector operator* ( double a, const GslVector& x );
253 GslVector operator* (const GslVector& x, const GslVector& y );
254 double scalarProduct(const GslVector& x, const GslVector& y );
255 GslVector operator+ (const GslVector& x, const GslVector& y );
256 GslVector operator- (const GslVector& x, const GslVector& y );
257 bool operator== (const GslVector& lhs, const GslVector& rhs);
258 std::ostream& operator<< (std::ostream& os, const GslVector& obj);
259 
260 } // End namespace QUESO
261 
262 #endif // UQ_GSL_VECTOR_H
double normInf() const
Returns the infinity-norm (maximum norm) of the vector.
Definition: GslVector.C:408
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:556
bool operator==(const GslVector &lhs, const GslVector &rhs)
Definition: GslVector.C:1394
void getMaxValueAndIndex(double &value, int &index)
This function returns maximum value in the vector this and its the index.
Definition: GslVector.C:1286
GslMatrix operator*(double a, const GslMatrix &mat)
Definition: GslMatrix.C:2354
GslMatrix operator-(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2404
GslVector & operator-=(const GslVector &rhs)
Stores in this the coordinate-wise subtraction of this by rhs.
Definition: GslVector.C:304
GslMatrix operator+(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2397
GslVector abs() const
This function returns absolute value of elements in this.
Definition: GslVector.C:1304
int getMinValueIndex() const
This function returns the index of the minimum value in the vector this.
Definition: GslVector.C:1280
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:1224
double norm2Sq() const
Returns the 2-norm squared of this vector.
Definition: GslVector.C:383
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
void cwSet(double value)
Component-wise sets all values to this with value.
Definition: GslVector.C:435
double getMaxValue() const
Returns the maximum value in the vector this.
Definition: GslVector.C:1262
~GslVector()
Destructor.
Definition: GslVector.C:213
void matlabDiff(unsigned int firstPositionToStoreDiff, double valueForRemainderPosition, GslVector &outputVec) const
Definition: GslVector.C:676
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:187
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:537
void mpiAllReduce(RawType_MPI_Op mpiOperation, const MpiComm &opComm, GslVector &resultVec) const
Definition: GslVector.C:861
void mpiBcast(int srcRank, const MpiComm &bcastComm)
Definition: GslVector.C:797
A class for partitioning vectors and matrices.
Definition: Map.h:49
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:343
GslVector()
Default Constructor.
Definition: GslVector.C:32
GslVector & operator/=(double a)
Stores in this the coordinate-wise division of this by a.
Definition: GslVector.C:250
void sort()
This function sorts the elements of the vector this in ascending numerical order. ...
Definition: GslVector.C:789
double scalarProduct(const GslVector &x, const GslVector &y)
Definition: GslVector.C:1360
GslVector operator/(double a, const GslVector &x)
Definition: GslVector.C:1327
double norm2() const
Returns the 2-norm (Euclidean norm) of the vector.
Definition: GslVector.C:389
double & operator[](unsigned int i)
Element access method (non-const).
Definition: GslVector.C:317
MPI_Op RawType_MPI_Op
Definition: MpiComm.h:41
Class for vector operations using GSL library.
Definition: GslVector.h:48
double getMinValue() const
Returns minimum value in the vector this.
Definition: GslVector.C:1268
void subWriteContents(const std::string &varNamePrefix, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
Definition: GslVector.C:983
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:474
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:245
The QUESO MPI Communicator Class.
Definition: MpiComm.h:75
void copy(const GslVector &src)
This function copies the elements of the vector src into this.
Definition: GslVector.C:329
int getMaxValueIndex() const
This function returns the index of the maximum value in the vector this.
Definition: GslVector.C:1274
const Map & map() const
Definition: Vector.C:143
void mpiAllQuantile(double probability, const MpiComm &opComm, GslVector &resultVec) const
Definition: GslVector.C:885
double norm1() const
Returns the 1-norm of the vector.
Definition: GslVector.C:395
GslVector & operator=(const GslVector &rhs)
Copies values from vector rhs to this.
Definition: GslVector.C:219
void cwSetGaussian(double mean, double stdDev)
This function sets component-wise Gaussian random variates, with mean mean and standard deviation std...
Definition: GslVector.C:446
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:923
void cwSetConcatenated(const GslVector &v1, const GslVector &v2)
This function concatenates GslVector v1 and GslVector v2 into this.
Definition: GslVector.C:575
void matlabLinearInterpExtrap(const GslVector &x1Vec, const GslVector &y1Vec, const GslVector &x2Vec)
Definition: GslVector.C:707
void subReadContents(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds)
Definition: GslVector.C:1029
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:465
const BaseEnvironment & env() const
Definition: Vector.C:136
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:1243
void cwInvert()
This function inverts component-wise the element values of this.
Definition: GslVector.C:654
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:1186
unsigned int sizeGlobal() const
Returns the global length of this vector.
Definition: GslVector.C:372
double sumOfComponents() const
Returns the sum of the components of the vector.
Definition: GslVector.C:423
void getMinValueAndIndex(double &value, int &index)
This function returns minimum value in the vector this and its the index.
Definition: GslVector.C:1295
GslVector & operator+=(const GslVector &rhs)
Stores in this the coordinate-wise addition of this and rhs.
Definition: GslVector.C:292
gsl_vector * data() const
Definition: GslVector.C:1180
void cwSqrt()
This function returns component-wise the square-root of this.
Definition: GslVector.C:665
Class for vector operations (virtual).
Definition: Vector.h:47
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:634
GslVector & operator*=(double a)
Stores in this the coordinate-wise multiplication of this and a.
Definition: GslVector.C:238
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:1205

Generated on Thu Apr 23 2015 19:30:54 for queso-0.52.0 by  doxygen 1.8.5