9 #include <boost/bind.hpp>
14 #include "NetCDFTools.h"
16 #include "C1dInvGaConf.h"
24 C1DMTSynthData &MTModel, gplib::rmat &DataCovar, gplib::rvec &modelerrors,
25 gplib::rvec ¶meterthresholds)
27 const size_t nmodelparms = parameterthresholds.size();
28 const size_t nlayers = nmodelparms / 4;
29 size_t eigenvindex = 0;
31 gplib::rvec svalratios = svals;
32 svalratios /= svals(0);
33 cout <<
"Joint Singular Values : " << svals << endl;
34 gplib::rmat ModelCovar;
35 cout <<
"Model errors: " << modelerrors << endl;
36 while (sum(modelerrors) < sum(parameterthresholds))
38 cout <<
"Ratio: " << svalratios(eigenvindex) << endl;
40 cout <<
"Accum Model Errors: " << sum(modelerrors) << endl;
41 cout <<
"Accum Threshold Errors: " << sum(parameterthresholds) << endl;
45 for (
size_t i = 0; i < nlayers; ++i)
46 modelerrors(i) = 2.3025 * MTModel.GetResistivities().at(i) * sqrt(
48 for (
size_t i = nlayers; i < nmodelparms; ++i)
50 currerr = sqrt(ModelCovar(i, i));
51 modelerrors(i) = currerr;
62 cout <<
"Data name base: ";
64 RecData.GetData(datanamebase +
".rec");
66 MTData.GetData(datanamebase +
".mtt");
69 Configuration.GetData(
"1dinvga.conf");
71 MTRecObjective JointObjective(MTData, RecData, Configuration.shift,
72 Configuration.omega, Configuration.sigma, Configuration.cc,
73 Configuration.slowness);
75 cout <<
"RF weight: ";
78 JointObjective.SetRecWeight(rfweight);
79 JointObjective.GetRecObjective().SetPoisson(Configuration.poisson);
80 JointObjective.GetRecObjective().SetTimeWindow(Configuration.starttime,
81 Configuration.endtime);
82 JointObjective.GetRecObjective().SetErrorLevel(Configuration.recerror);
83 JointObjective.GetRecObjective().SetFitExponent(
84 Configuration.recfitexponent);
86 cout <<
"Model name base: ";
89 RecModel.GetData(modelnamebase +
"_rec.mod");
90 C1DMTSynthData MTModel;
91 MTModel.readmodel(modelnamebase +
"_mt.mod");
93 const size_t nmodelparms = RecModel.SVelocity.size() * 3;
94 const size_t nlayers = RecModel.SVelocity.size();
95 gplib::rvec JointModelVector(nmodelparms);
96 for (
size_t i = 0; i < nlayers; ++i)
98 JointModelVector(i) = log10(MTModel.GetResistivities().at(i));
99 JointModelVector(i + nlayers) = RecModel.Thickness.at(i);
100 JointModelVector(i + 2 * nlayers) = RecModel.SVelocity.at(i);
103 gplib::rvec varfactor(nmodelparms);
104 double errorratio = 0.1;
105 cout <<
"Relative Error for Model parameters; ";
107 double JointOldRMS = JointObjective.CalcPerformance(JointModelVector);
109 cout <<
"RMS: " << JointOldRMS << endl;
111 for (
size_t i = 0; i < nmodelparms; ++i)
117 JointAnalyser.
SetModel(JointModelVector);
120 ofstream evals(
"jointevals.plot");
121 for (
size_t i = 0; i < svals.size(); ++i)
122 evals << svals(i) << endl;
127 gplib::rvec modelerrors(nmodelparms);
128 for (
size_t i = 0; i < nmodelparms; ++i)
129 modelerrors(i) = 0.0;
131 gplib::rvec parameterthresholds = JointModelVector;
132 for (
size_t i = 0; i < nlayers; ++i)
133 parameterthresholds(i) = pow(10, parameterthresholds(i)) * varfactor(i);
134 for (
size_t i = nlayers; i < nmodelparms; ++i)
135 parameterthresholds(i) *= varfactor(i);
137 parameterthresholds *= errorratio;
139 const size_t nrecdata = RecData.GetData().size();
140 const size_t nmtdata = MTData.GetMTData().size();
142 C1DMTObjective::datafuncvector_t ErrorFunctions =
143 JointObjective.GetMTObjective().GetErrorFunctions();
144 const size_t nerrorfuncs = ErrorFunctions.size();
145 gplib::rmat DataCovar(nrecdata + nerrorfuncs * nmtdata, nrecdata
146 + nerrorfuncs * nmtdata);
147 fill_n(DataCovar.data().begin(), DataCovar.size1() * DataCovar.size2(), 0.0);
148 for (
size_t e = 0; e < nerrorfuncs; ++e)
150 for (
size_t i = 0; i < nmtdata; ++i)
152 DataCovar(i + e * nmtdata, i + e * nmtdata) = gplib::pow2(
153 ErrorFunctions.at(e)(&MTData.GetMTData().at(i)));
157 for (
size_t i = nmtdata * nerrorfuncs; i < nmtdata * nerrorfuncs + nrecdata; ++i)
159 DataCovar(i, i) = gplib::pow2(RecData.GetData().at(i - nmtdata
160 * nerrorfuncs) * Configuration.recerror);
163 ofstream recerrors(
"jointerrors");
167 cout <<
"SVD Threshold (negative for automatic): ";
169 if (svdthreshold < 0.0)
172 parameterthresholds);
181 for (
size_t i = 0; i < nlayers; ++i)
182 modelerrors(i) = 2.3025 * MTModel.GetResistivities().at(i) * sqrt(
184 for (
size_t i = nlayers; i < nmodelparms; ++i)
186 currerr = sqrt(ModelCovar(i, i));
187 modelerrors(i) = currerr;
190 std::vector<double> thickerr, svelerr, reserr;
192 for (
int i = 0; i < nlayers; ++i)
194 reserr.push_back(modelerrors(i));
195 thickerr.push_back(modelerrors(i + nlayers));
196 svelerr.push_back(modelerrors(i + nlayers * 2));
199 cout <<
"Final Accum Model Errors: " << sum(modelerrors) << endl;
200 cout <<
"Accum Threshold Errors: " << sum(parameterthresholds) << endl;
201 WriteMatrixAsNetCDF(
"jointcovar.nc", ModelCovar);
209 RecModel.SetThickErrors(thickerr);
210 RecModel.SetSVelErrors(svelerr);
211 RecModel.PlotVelWithErrors(
"recerr.plot");
212 MTModel.SetResistivityErrors(reserr);
213 MTModel.SetThicknessErrors(thickerr);
214 MTModel.writeplot(
"mterr.plot");
gplib::rmat GetModelCorrelation(const gplib::rmat &DataCovar)
void SetupMTFitParameters(const tConfObject &Configuration, C1DMTObjective &Objective)
gplib::rmat GetModelNullspace()
void SetVariationFactor(const gplib::rvec varfac)
gplib::rvec GetSingularValues()
void SetModel(const gplib::rvec &TheModel)
gplib::rmat GetModelCovariance(const gplib::rmat &DataCovar)
The calculation of the Model Covariance is based on Menke, p. 122 formula 7.37.
const gplib::rmat & GetSensitivityMatrix()
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
void DetermineEvalThreshold(ModelAnalysis &JointAnalyser, C1DMTSynthData &MTModel, gplib::rmat &DataCovar, gplib::rvec &modelerrors, gplib::rvec ¶meterthresholds)
const gplib::rmat & GetSensitivityInverse() const