12 #include <boost/bind.hpp>
16 #include "C1dInvGaConf.h"
18 #include "NetCDFTools.h"
27 cout <<
"Data name base: ";
29 RecData.GetData(datanamebase +
".rec");
30 MTData.GetData(datanamebase +
".mtt");
33 Configuration.GetData(
"1dinvga.conf");
38 C1DRecObjective
RecObjective(RecData, Configuration.shift,
39 Configuration.omega, Configuration.sigma, Configuration.cc,
40 Configuration.slowness);
41 RecObjective.SetPoisson(Configuration.poisson);
42 RecObjective.SetTimeWindow(Configuration.starttime, Configuration.endtime);
43 RecObjective.SetErrorLevel(Configuration.recerror);
44 RecObjective.SetFitExponent(Configuration.recfitexponent);
46 cout <<
"Model name base: ";
49 C1DMTSynthData MTModel;
50 RecModel.GetData(modelnamebase +
"_rec.mod");
51 MTModel.readmodel(modelnamebase +
"_mt.mod");
53 gplib::rvec MTModelVector = MTModel.GetModelVector();
55 double MTOldRMS = MTObjective.CalcPerformance(MTModelVector);
56 gplib::rvec OldData(MTObjective.GetSynthData());
58 MTAnalyser.SetModel(MTModelVector);
60 cout <<
"MT Singular Values : " << MTAnalyser.GetSingularValues() << endl;
61 cout <<
"Relative SVD Threshold: ";
62 double svdthreshold = 0.0;
64 MTAnalyser.SetRelativeSVDThreshold(svdthreshold);
66 const size_t nrecmodelparms = RecModel.SVelocity.size() * 2;
67 const size_t nlayers = RecModel.SVelocity.size();
68 gplib::rvec RecModelVector(nrecmodelparms);
69 for (
int i = 0; i < nlayers; ++i)
71 RecModelVector(i) = RecModel.Thickness.at(i);
72 RecModelVector(i + nlayers) = RecModel.SVelocity.at(i);
74 double RecOldRMS = RecObjective.CalcPerformance(RecModelVector);
75 RecObjective.WriteData(
"old");
76 cout <<
"Saved old model " << endl << flush;
78 RecAnalyser.
SetModel(RecModelVector);
86 gplib::rvec MTProjection(MTModelVector), MTPerturb(MTModelVector),
87 MTNewModel(MTModelVector);
88 gplib::rvec RecProjection(RecModelVector), RecPerturb(RecModelVector),
89 RecNewModel(RecModelVector);
91 double MTNewRMS = MTOldRMS;
95 ublas::vector<double> Perturb(MTModelVector.size() / 2);
98 for (
int i = 0; i < Perturb.size(); ++i)
99 Perturb(i) = Random.GetNumber(-1., 1.);
101 for (
size_t i = 0; i < nlayers; ++i)
103 MTPerturb(i + nlayers) = Perturb(i);
104 RecPerturb(i) = -Perturb(i);
107 MTNewModel = MTModelVector;
108 const double rmsincrease = 0.05;
109 while (currit < maxit && std::abs(MTNewRMS - MTOldRMS) / MTOldRMS < rmsincrease)
111 for (
size_t i = nlayers; i < MTPerturb.size(); ++i)
112 MTPerturb(i) = Random.GetNumber(-1., 1.);
113 MTProjection = prod(MTAnalyser.GetModelNullspace(), MTPerturb);
114 MTNewModel = MTModelVector + MTProjection;
115 MTNewRMS = MTObjective.CalcPerformance(MTNewModel);
116 MTObjective.WritePlot(
"new_mt" + stringify(currit));
117 cout <<
"MT New RMS: " << MTNewRMS << endl;
121 double RecNewRMS = RecOldRMS;
122 RecNewModel = RecModelVector;
123 while (currit < maxit && std::abs(RecNewRMS - RecOldRMS) / RecOldRMS
126 for (
size_t i = 0; i < RecPerturb.size(); ++i)
127 RecPerturb(i) = Random.GetNumber(-1., 1.);
129 RecNewModel = RecModelVector + RecProjection;
131 RecNewRMS = RecObjective.CalcPerformance(RecNewModel);
132 RecObjective.WritePlot(
"new_rec" + stringify(currit));
133 cout <<
"Rec New RMS: " << RecNewRMS << endl;
137 RecObjective.WriteData(
"new.rec");
138 MTObjective.WriteData(
"new.mtt");
140 MTObjective.WritePlot(
"new_mt.plot");
141 RecObjective.WriteModel(
"new_rec.mod");
142 MTObjective.WriteModel(
"new_mt.mod");
143 cout <<
"MT OldRMS: " << MTOldRMS <<
" MT NewRMS: " << MTNewRMS << endl;
144 cout <<
"Rec OldRMS: " << RecOldRMS <<
" Rec NewRMS: " << RecNewRMS << endl;
145 cout <<
"MT Old Model: " << MTModelVector << endl;
146 cout <<
"MT New Model: " << MTNewModel << endl;
147 cout <<
"Rec Old Model: " << RecModelVector << endl;
148 cout <<
"Rec New Model: " << RecNewModel << endl;
150 WriteMatrixAsNetCDF(
"mtres.nc", MTAnalyser.GetModelResolution());
151 WriteMatrixAsNetCDF(
"mtnull.nc", MTAnalyser.GetModelNullspace());
void SetupMTFitParameters(const tConfObject &Configuration, C1DMTObjective &Objective)
gplib::rmat GetModelNullspace()
gplib::rvec GetSingularValues()
boost::shared_ptr< PlottableObjective > MTObjective
C1DRecObjective RecObjective(RecData, Configuration.shift, Configuration.omega, Configuration.sigma, Configuration.wlevel, Configuration.slowness)
void SetModel(const gplib::rvec &TheModel)
void SetRelativeSVDThreshold(const double t)
gplib::rmat GetModelResolution()
The class ModelAnalysis is used to calculate resolution matrix, nullspace and other parameters for mo...
CLevanisoConf Configuration