5 #include "CLevanisoConf.h"
8 #include <boost/bind.hpp>
10 #include <boost/shared_ptr.hpp>
14 using namespace gplib;
18 void misfit(
double *p,
double *x,
int m,
int n,
void *data)
20 const unsigned int nlayers = m / 4;
21 const unsigned int nparam = m;
23 for (
int i = 0; i < nparam; ++i)
31 const unsigned int nelements =
MTObjective->GetMisfit().size();
32 for (
size_t i = 0; i < nelements; ++i)
42 string version =
"$Id: levaniso.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
44 cout <<
"Program " << version << endl;
45 cout <<
" Levenberg Marquardt to MT data for 1D anisotropic structure"
47 cout <<
" look at levaniso.conf for configuration and setup " << endl;
48 cout <<
" output files will be of the form " << endl;
49 cout <<
" best_lev + ending " << endl;
66 boost::shared_ptr<PTensor1DMTObjective> PTObjective(
74 boost::shared_ptr<Aniso1DMTObjective> AnisoObjective(
82 const int nparams = nlayers * 4;
87 mtmember.begin() + nlayers);
89 mtmember.begin() + 2 * nlayers);
91 Configuration.startstrike.end(), mtmember.begin() + 3 * nlayers);
92 double startfit =
MTObjective->CalcPerformance(mtmember);
94 cout <<
"Start misfit: " << startfit << endl;
97 double *p =
new double[nparams];
98 double *lb =
new double[nparams];
99 double *ub =
new double[nparams];
108 cerr <<
"One weight has to be > 0 !";
112 double opts[LM_OPTS_SZ], info[LM_INFO_SZ];
114 opts[0] = LM_INIT_MU;
118 opts[4] = LM_DIFF_DELTA;
120 for (
int i = 0; i < nlayers; ++i)
126 for (
int i = 0; i < nlayers; ++i)
132 for (
int i = 0; i < nlayers; ++i)
138 for (
int i = 0; i < nlayers; ++i)
145 for (
int i = 0; i < n; i++)
148 double ret = dlevmar_bc_dif(
misfit, p, x, nparams, n, lb, ub,
150 cout <<
"Levenberg-Marquardt returned " << ret <<
" in " << info[5]
151 <<
"iter, reason " << info[6] << endl;
153 cout << endl <<
" Minimization info:" << endl;
154 for (
int i = 0; i < LM_INFO_SZ; ++i)
155 cout << info[i] <<
" ";
159 for (
int i = 0; i < nparams; ++i)
164 double mtdiff =
MTObjective->CalcPerformance(mtbest);
166 cout <<
"MT-Fit: " << mtdiff << endl;
167 ostringstream filename;
168 filename <<
"best_lev";
170 cout <<
" Saved as : " << filename.str() << endl;
172 MTObjective->WriteModel(filename.str() +
"_mt.mod");
173 MTObjective->WritePlot(filename.str() +
"_mt.plot");
181 cerr << e.what() << endl;
void SetupMTFitParameters(const tConfObject &Configuration, C1DMTObjective &Objective)
ublas::vector< double > ttranscribed
This is a special objective function to fit phase tensor MT data.
boost::shared_ptr< PlottableObjective > MTObjective
CLevanisoConf Configuration
virtual void GetData(const std::string filename)
read in data from file, determines format by ending
The class MTStation is used to store the transfer functions and related information for a MT-site...
void GetData(const std::string &filename)
void misfit(double *p, double *x, int m, int n, void *data)
The basic exception class for all errors that arise in gplib.