GPLIB++
mtcovar.cpp
Go to the documentation of this file.
1 #include "C1DMTObjective.h"
2 #include "GradFunc.h"
3 #include "convert.h"
4 #include "C1DMTSynthData.h"
5 #include "netcdfcpp.h"
6 #include <iostream>
7 #include <fstream>
8 #include <boost/bind.hpp>
9 #include "VecMat.h"
10 #include "Adaptors.h"
11 #include <algorithm>
12 #include <string>
13 #include "NetCDFTools.h"
14 #include "MTFitSetup.h"
15 #include "C1dInvGaConf.h"
16 using namespace std;
17 
18 int main()
19  {
20  C1dInvGaConf Configuration;
21  Configuration.GetData("1dinvga.conf");
22  CMTStation MTData;
23  string datanamebase;
24  cout << "Data name base: ";
25  cin >> datanamebase;
26  MTData.GetData(datanamebase + ".mtt");
27 
28  C1DMTObjective MTObjective(MTData);
29  SetupFitParameters(Configuration, MTObjective);
30 
31  string modelnamebase;
32  cout << "Model name base: ";
33  cin >> modelnamebase;
34  C1DMTSynthData MTModel;
35  MTModel.readmodel(modelnamebase + "_mt.mod");
36 
37  gplib::rvec MTModelVector(2 * MTModel.GetThicknesses().size());
38  for (int i = 0; i < MTModel.GetThicknesses().size(); ++i)
39  {
40  MTModelVector(i) = log10(MTModel.GetResistivities().at(i));
41  MTModelVector(i + MTModel.GetThicknesses().size())
42  = MTModel.GetThicknesses().at(i);
43  }
44 
45  double MTOldRMS = MTObjective.CalcPerformance(MTModelVector);
46  cout << "RMS: " << MTOldRMS << endl;
47  gplib::rvec OldData(MTObjective.GetSynthData());
48 
49  ModelAnalysis MTAnalyser(MTObjective);
50  MTAnalyser.SetModel(MTModelVector);
51  ofstream evals("mtevals.plot");
52  for (int i = 0; i < MTAnalyser.GetSingularValues().size(); ++i)
53  evals << i << " " << MTAnalyser.GetSingularValues()(i) << endl;
54  cout << "MT Singular Values : " << MTAnalyser.GetSingularValues() << endl;
55  cout << "Relative SVD Threshold: ";
56  double svdthreshold = 0.0;
57  cin >> svdthreshold;
58 
59  MTAnalyser.SetRelativeSVDThreshold(svdthreshold);
60 
61  gplib::rmat DataCovar(2 * MTData.GetMTData().size(), 2
62  * MTData.GetMTData().size());
63  fill_n(DataCovar.data().begin(), DataCovar.size1() * DataCovar.size2(), 0.0);
64  const size_t length = MTData.GetMTData().size();
65  for (int i = 0; i < length; ++i)
66  {
67  DataCovar(i, i) = MTData.GetMTData().at(i).GetdBerd()
68  * MTData.GetMTData().at(i).GetdBerd();
69  DataCovar(i + length, i + length) = MTData.GetMTData().at(i).GetdBerd()
70  * MTData.GetMTData().at(i).GetdBerd();
71  }
72  gplib::rmat ModelCovar = MTAnalyser.GetModelCovariance(DataCovar);
73  WriteMatrixAsNetCDF("mtcovar.nc", ModelCovar);
74  WriteMatrixAsNetCDF("mtsens.nc", MTAnalyser.GetSensitivityMatrix());
75  ofstream mterrors("mterrors");
76  for (int i = 0; i < MTModel.GetThicknesses().size(); ++i)
77  {
78  //mterrors << sqrt(2.3025 * pow(10,MTModel.GetResistivities().at(i)) * ModelCovar(i,i)) << endl;
79  mterrors << sqrt(ModelCovar(i, i)) << endl;
80  }
81  for (int i = MTModel.GetThicknesses().size(); i < 2
82  * MTModel.GetThicknesses().size(); ++i)
83  mterrors << sqrt(ModelCovar(i, i)) << endl;
84 
85  }
boost::shared_ptr< PlottableObjective > MTObjective
Definition: cadianiso.cpp:16
int main()
Definition: mtcovar.cpp:18
CMTStation MTData
Definition: cadijoint.cpp:15
The class ModelAnalysis is used to calculate resolution matrix, nullspace and other parameters for mo...
Definition: GradFunc.h:20
CLevanisoConf Configuration
Definition: cadianiso.cpp:17