-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initiated a new chaper for sensitivity analysis
- Loading branch information
1 parent
fc3e05d
commit dd4ba59
Showing
8 changed files
with
499 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <cmath> | ||
#include <fstream> | ||
#include <iomanip> // for setprecision | ||
|
||
#include <queso/GslVector.h> | ||
#include <queso/GslMatrix.h> | ||
#include <sensitivity_mc.h> | ||
|
||
template<class P_V, class P_M, class Q_V, class Q_M> | ||
Qoi_mc<P_V, P_M, Q_V, Q_M>::Qoi_mc(const char * prefix, | ||
const QUESO::VectorSet<P_V, P_M> & domainSet, | ||
const QUESO::VectorSet<Q_V, Q_M> & imageSet) | ||
: QUESO::BaseVectorFunction<P_V, P_M, Q_V, Q_M>(prefix, domainSet, imageSet), | ||
x_loc(3) | ||
{ | ||
} | ||
|
||
template<class P_V, class P_M, class Q_V, class Q_M> | ||
Qoi_mc<P_V, P_M, Q_V, Q_M>::~Qoi_mc() | ||
{ | ||
// Deconstruct here | ||
} | ||
|
||
template<class P_V, class P_M, class Q_V, class Q_M> | ||
void | ||
Qoi_mc<P_V, P_M, Q_V, Q_M>::compute(const P_V & domainVector, | ||
const P_V * domainDirection, | ||
Q_V & imageVector, QUESO::DistArray<P_V *> * gradVectors, | ||
QUESO::DistArray<P_M *> * hessianMatrices, | ||
QUESO::DistArray<P_V *> * hessianEffects) const | ||
{ | ||
if (domainVector.sizeLocal() != 2) { | ||
queso_error_msg("domainVector does not have size 2"); | ||
} | ||
if (imageVector.sizeLocal() != 1) { | ||
queso_error_msg("imageVector does not have size 1"); | ||
} | ||
|
||
qoi_samples.open ("c_qoi_samplesAi.txt", std::fstream::in | std::fstream::out | std::fstream::app); | ||
|
||
// ----Generate Qoi using samples from a text files ------------- | ||
count++; | ||
samples.open ("./files_sense/c_samples_Ai.txt", std::fstream::in | std::fstream::out | std::fstream::app); | ||
|
||
int cou = 1; | ||
|
||
while (samples >> mf >> cf){ | ||
if (cou == count){ | ||
m = mf; | ||
c = cf; | ||
break; | ||
} | ||
cou++; | ||
} | ||
|
||
// ------- Generate Qoi using pseudo-random MC samples ------------ | ||
// std::cout << "m = " << domainVector[0] << std::endl; | ||
// m = domainVector[0]; // Sample of the RV 'line slope' | ||
// c = domainVector[1]; // Sample of the RV 'y-intercept' | ||
double y_obs = 0.0; | ||
y_obs = m*x_loc + c; | ||
|
||
qoi_samples << std::setprecision(4) << y_obs << "\t\t" << m << "\t\t" << c << std::endl; | ||
|
||
imageVector[0] = y_obs; | ||
qoi_samples.close(); | ||
samples.close(); | ||
} | ||
|
||
template class Qoi_mc<QUESO::GslVector, QUESO::GslMatrix, QUESO::GslVector, | ||
QUESO::GslMatrix>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef QUESO_EXAMPLE_SENSITIVITY_MC_H | ||
#define QUESO_EXAMPLE_SENSITIVITY_MC_H | ||
|
||
#include <queso/VectorFunction.h> | ||
#include <queso/DistArray.h> | ||
#include <fstream> | ||
|
||
template<class P_V = QUESO::GslVector, class P_M = QUESO::GslMatrix, | ||
class Q_V = QUESO::GslVector, class Q_M = QUESO::GslMatrix> | ||
class Qoi_mc : public QUESO::BaseVectorFunction<P_V, P_M, Q_V, Q_M> | ||
{ | ||
public: | ||
Qoi_mc(const char * prefix, const QUESO::VectorSet<P_V, P_M> & domainSet, | ||
const QUESO::VectorSet<Q_V, Q_M> & imageSet); | ||
virtual ~Qoi_mc(); | ||
virtual void compute(const P_V & domainVector, const P_V * domainDirection, | ||
Q_V & imageVector, QUESO::DistArray<P_V *> * gradVectors, | ||
QUESO::DistArray<P_M *> * hessianMatrices, | ||
QUESO::DistArray<P_V *> * hessianEffects) const; | ||
|
||
private: | ||
double x_loc; | ||
mutable double m,c,mf,cf,count; | ||
mutable std::fstream qoi_samples; | ||
mutable std::fstream samples; | ||
|
||
}; | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.