6 #include <boost/numeric/ublas/io.hpp>
7 #include <boost/function.hpp>
8 #include <boost/bind.hpp>
14 namespace ublas = boost::numeric::ublas;
19 C1DMTObjective::C1DMTObjective(
const MTStation &LocalMTData) :
27 ErrorLevels.push_back(0.01);
28 FitparametersSet =
false;
37 ErrorFunctions(Old.ErrorFunctions), ErrorLevels(Old.ErrorLevels),
38 FitparametersSet(Old.FitparametersSet),
MTData(Old.
MTData)
47 DataFunctions.resize(source.DataFunctions.size());
48 ErrorFunctions.resize(source.ErrorFunctions.size());
49 ErrorLevels.resize(source.ErrorLevels.size());
50 copy(source.DataFunctions.begin(), source.DataFunctions.end(),
51 DataFunctions.begin());
52 copy(source.ErrorFunctions.begin(), source.ErrorFunctions.end(),
53 ErrorFunctions.begin());
54 copy(source.ErrorLevels.begin(), source.ErrorLevels.end(),
56 MTData = source.MTData;
57 FitparametersSet = source.FitparametersSet;
74 if (TheDataV.size() != TheErrorV.size() || TheDataV.size()
75 != TheErrLevel.size())
77 "Vectors of fit parameters have incompatible size !");
81 DataFunctions.resize(TheDataV.size());
82 ErrorFunctions.resize(TheErrorV.size());
83 ErrorLevels.resize(TheErrLevel.size());
84 copy(TheDataV.begin(), TheDataV.end(), DataFunctions.begin());
85 copy(TheErrorV.begin(), TheErrorV.end(), ErrorFunctions.begin());
86 copy(TheErrLevel.begin(), TheErrLevel.end(), ErrorLevels.begin());
87 FitparametersSet =
true;
97 const datafunc_t TheErrorFunc,
const double TheErrLevel)
99 if (!FitparametersSet)
101 DataFunctions.clear();
102 ErrorFunctions.clear();
104 DataFunctions.push_back(TheDataFunc);
105 ErrorFunctions.push_back(TheErrorFunc);
106 ErrorLevels.push_back(TheErrLevel);
107 FitparametersSet =
true;
111 DataFunctions.push_back(TheDataFunc);
112 ErrorFunctions.push_back(TheErrorFunc);
113 ErrorLevels.push_back(TheErrLevel);
123 double returnvalue = 0;
125 if (!FitparametersSet)
127 FitparametersSet =
true;
129 <<
"Warning errorlevel and Fitparameters not set, using hardcoded default ! "
131 cerr <<
"You should change your program !" << endl;
140 CalcSynthData(member);
143 unsigned int datacount = 0;
144 double currdata = 0.0;
145 typedef vector<MTTensor>::const_iterator tensorit_t;
146 typedef datafuncvector_t::iterator funcit_t;
150 funcit_t dfuncit = DataFunctions.begin();
151 funcit_t efuncit = ErrorFunctions.begin();
153 std::vector<double>::const_iterator elevelit = ErrorLevels.begin();
154 const unsigned int ndata = DataFunctions.size()
161 for (; dfuncit != DataFunctions.end(); ++dfuncit, ++efuncit, ++elevelit)
163 for (tensorit_t datait = MTData.
GetMTData().begin(), synthit =
165 < MTData.
GetMTData().end(); ++datait, ++synthit)
170 currdata = (*dfuncit)(&*datait);
171 const double currpredicted = (*dfuncit)(&*synthit);
172 const double currerror = (*efuncit)(&*datait);
173 const double errorlevel = *elevelit;
174 returnvalue +=
CalcMisfit(currdata, currpredicted, currerror,
175 errorlevel, datacount);
void AppendFitParameters(const datafunc_t TheDataFunc, const datafunc_t TheErrorFunc, const double TheErrLevel)
boost::function< double(const MTTensor *const )> datafunc_t
A function that returns a real valued quantity calculated from an MT impedance tensor.
ublas::vector< double > ttranscribed
This only adds a few plotting functions to GeneralObjective to define a common interface.
C1DMTObjective(const MTStation &LocalMTData)
We need data to fit for any objective function, so we want it as constructor parameter, but no implicit conversion.
int GetFitExponent()
Get the Fit exponent.
double CalcMisfit(const double measured, const double predicted, const double measerror, const double errorlevel, const int index)
The class MTStation is used to store the transfer functions and related information for a MT-site...
virtual ~C1DMTObjective()
double GetRMS()
Get the current RMS.
C1DMTObjective & operator=(const C1DMTObjective &source)
tdata & SetSynthData()
Only derived classes can write access the Synthetic data.
tmisfit & SetMisfit()
Only derived classes can write access the Misfit.
std::vector< datafunc_t > datafuncvector_t
A vector of MT data functions. This is used to store the types of data to fit.
PlottableObjective & operator=(const PlottableObjective &source)
void SetFitParameters(const datafuncvector_t TheDataV, const datafuncvector_t TheErrorV, const std::vector< double > TheErrLevel)
function to set the parameters that determine the type of fit
const std::vector< MTTensor > & GetMTData() const
Get the full vector of Tensor elements read only.
virtual MTStation & GetMTSynth()=0
virtual double PostParallel(const ttranscribed &member)
All calculation has been done in SafeParallel we only return the stored result.
virtual void SafeParallel(const ttranscribed &member)
Calc misfit for a model given by member.
trealdata GetFrequencies() const
return the available frequencies in a single vector
C1DMTObjective is the base class for MT misfit calculations from 1D models, it provides common functi...
void SetRMS(const double x)
void SetFrequencies(const trealdata &freqs)
Set the frequencies of the tensor elements, invalidates the previously stored impedance data...
The basic exception class for all errors that arise in gplib.