GPLIB++
Multi1DRecObjective.cpp
Go to the documentation of this file.
1 #include "Multi1DRecObjective.h"
2 #include <cassert>
3 #include <algorithm>
4 #include <numeric>
5 #include <boost/bind.hpp>
6 #include "FatalException.h"
7 #include "convert.h"
8 #include <iostream>
9 using namespace std;
10 
11 namespace gplib
12  {
13  void Multi1DRecObjective::SetTimeWindow(const double start,
14  const double end)
15  {
16  for_each(Objectives.begin(), Objectives.end(), boost::bind(
17  &C1DRecObjective::SetTimeWindow, _1, start, end));
18  }
19 
20  void Multi1DRecObjective::SetPoisson(const double ratio)
21  {
22  for_each(Objectives.begin(), Objectives.end(), boost::bind(
23  &C1DRecObjective::SetPoisson, _1, ratio));
24  }
25 
26  void Multi1DRecObjective::AddRecFunction(boost::shared_ptr<
27  const SeismicDataComp> TheRecData, int myshift,
28  double mysigma, double myc, double myslowness,
29  RecCalc::trfmethod method, double errorlevel,
30  bool normalized, ResPkModel::WaveType InWave)
31  {
32  boost::shared_ptr<C1DRecObjective> Obj(new C1DRecObjective(TheRecData,
33  myshift, mysigma, myc, myslowness, method, normalized, InWave));
34  Obj->SetErrorLevel(errorlevel);
35  Objectives.push_back(Obj);
36 
37  }
38 
39  void Multi1DRecObjective::AddAbsVelFunction(boost::shared_ptr<
40  const SeismicDataComp> TheRecData, SurfaceWaveData &AbsVel,
41  const int myshift, const double mysigma, const double myc,
42  const double myslowness, const RecCalc::trfmethod method,
43  const double errorlevel, const bool normalized,
44  const double absvelweight, const double recweight)
45  {
46  boost::shared_ptr<AbsVelRecObjective> Obj(new AbsVelRecObjective(
47  TheRecData, AbsVel, myshift, mysigma, myc, myslowness, method,
48  normalized));
49  Obj->SetErrorLevel(errorlevel);
50  Obj->SetAbsVelWeight(absvelweight);
51  Obj->SetRecWeight(recweight);
52  Objectives.push_back(Obj);
53  }
54 
55  void Multi1DRecObjective::PreParallel(const ttranscribed &member)
56  {
57  if (Objectives.empty())
58  throw FatalException(
59  "In Multi1DRecObjective: No Objective functions set !");
60  const size_t nobjs = Objectives.size();
61  for (size_t i = 0; i < nobjs; ++i)
62  {
63  Objectives.at(i)->SetParallelID(GetParallelID() + stringify(i));
64 
65  }
66  for_each(Objectives.begin(), Objectives.end(), boost::bind(
67  &C1DRecObjective::PreParallel, _1, member));
68  }
69  double Multi1DRecObjective::PostParallel(const ttranscribed &member)
70  {
71 
72  std::vector<double> values;
73  const size_t nobjs = Objectives.size();
74  for (size_t i = 0; i < nobjs; ++i)
75  {
76  Objectives.at(i)->SetParallelID(GetParallelID() + stringify(i));
77 
78  }
79  transform(Objectives.begin(), Objectives.end(), back_inserter(values),
80  boost::bind(&C1DRecObjective::PostParallel, _1, member));
81  double sumsquares = inner_product(values.begin(), values.end(),
82  values.begin(), 0.0);
83  //copy(values.begin(),values.end(),ostream_iterator<double>(cout," "));
84  //cout << " " << sqrt(sumsquares/values.size()) << endl;
85  return sqrt(sumsquares / values.size());
86  }
87  void Multi1DRecObjective::SafeParallel(const ttranscribed &member)
88  {
89  const size_t nobjs = Objectives.size();
90  for (size_t i = 0; i < nobjs; ++i)
91  {
92  Objectives.at(i)->SetParallelID(GetParallelID() + stringify(i));
93 
94  }
95  for_each(Objectives.begin(), Objectives.end(), boost::bind(
96  &C1DRecObjective::SafeParallel, _1, member));
97  }
98 
99  void Multi1DRecObjective::WriteData(const std::string &filename)
100  {
101  const size_t nobjs = Objectives.size();
102  for (size_t i = 0; i < nobjs; ++i)
103  {
104  Objectives.at(i)->WriteData(filename + stringify(i));
105 
106  }
107  //for_each(Objectives.begin(), Objectives.end(), boost::bind(
108  // &C1DRecObjective::WriteData, _1, filename));
109  }
110 
111  void Multi1DRecObjective::WriteModel(const std::string &filename)
112  {
113  Objectives.front()->WriteModel(filename); //all models are the same, so we only write the first
114  }
115 
116  void Multi1DRecObjective::WritePlot(const std::string &filename)
117  {
118  Objectives.front()->WritePlot(filename); //all models are the same, so we only plot the first
119  }
120 
121  Multi1DRecObjective::Multi1DRecObjective()
122  {
123  }
124 
125  Multi1DRecObjective::~Multi1DRecObjective()
126  {
127  }
128 
129  Multi1DRecObjective::Multi1DRecObjective(const Multi1DRecObjective &Old)
130  {
131  const size_t nobjs = Old.Objectives.size();
132  Objectives.clear();
133  for (size_t i = 0; i < nobjs; ++i)
134  {
135  boost::shared_ptr<C1DRecObjective> Obj(
136  Old.Objectives.at(i)->clone());
137  Objectives.push_back(Obj);
138  }
139  }
140 
141  Multi1DRecObjective& Multi1DRecObjective::operator=(
142  const Multi1DRecObjective& source)
143  {
144  if (this == &source)
145  return *this;
146  const size_t nobjs = source.Objectives.size();
147  Objectives.clear();
148  for (size_t i = 0; i < nobjs; ++i)
149  {
150  boost::shared_ptr<C1DRecObjective> Obj(
151  source.Objectives.at(i)->clone());
152  Objectives.push_back(Obj);
153  }
154  return *this;
155  }
156  }
trfmethod
There are several ways to calculate receiver functions.
Definition: RecCalc.h:18
ublas::vector< double > ttranscribed
Definition: gentypes.h:21
This class is used to model several receiver functions simultaneously.
A class to read, write and store fundamental mode surface wave dispersion data.
This objective function calculates the weighted misfit for a receiver function and the corresponding ...
Calculate the misfit between observed receiver function for a given 1D model by calculating a synthet...
The basic exception class for all errors that arise in gplib.