00001 #include "Multi1DRecObjective.h"
00002 #include <cassert>
00003 #include <algorithm>
00004 #include <numeric>
00005 #include <boost/bind.hpp>
00006 #include "FatalException.h"
00007 #include "convert.h"
00008 #include <iostream>
00009 using namespace std;
00010
00011 namespace gplib
00012 {
00013 void Multi1DRecObjective::SetTimeWindow(const double start,
00014 const double end)
00015 {
00016 for_each(Objectives.begin(), Objectives.end(), boost::bind(
00017 &C1DRecObjective::SetTimeWindow, _1, start, end));
00018 }
00019
00020 void Multi1DRecObjective::SetPoisson(const double ratio)
00021 {
00022 for_each(Objectives.begin(), Objectives.end(), boost::bind(
00023 &C1DRecObjective::SetPoisson, _1, ratio));
00024 }
00025
00026 void Multi1DRecObjective::AddRecFunction(boost::shared_ptr<
00027 const SeismicDataComp> TheRecData, const int myshift,
00028 const double mysigma, const double myc, const double myslowness,
00029 const RecCalc::trfmethod method, const double errorlevel,
00030 const bool normalized)
00031 {
00032 boost::shared_ptr<C1DRecObjective> Obj(new C1DRecObjective(TheRecData,
00033 myshift, mysigma, myc, myslowness, method, normalized));
00034 Obj->SetErrorLevel(errorlevel);
00035 Objectives.push_back(Obj);
00036
00037 }
00038
00039 void Multi1DRecObjective::AddAbsVelFunction(boost::shared_ptr<
00040 const SeismicDataComp> TheRecData, SurfaceWaveData &AbsVel,
00041 const int myshift, const double mysigma, const double myc,
00042 const double myslowness, const RecCalc::trfmethod method,
00043 const double errorlevel, const bool normalized,
00044 const double absvelweight, const double recweight)
00045 {
00046 boost::shared_ptr<AbsVelRecObjective> Obj(new AbsVelRecObjective(
00047 TheRecData, AbsVel, myshift, mysigma, myc, myslowness, method,
00048 normalized));
00049 Obj->SetErrorLevel(errorlevel);
00050 Obj->SetAbsVelWeight(absvelweight);
00051 Obj->SetRecWeight(recweight);
00052 Objectives.push_back(Obj);
00053 }
00054
00055 void Multi1DRecObjective::PreParallel(const ttranscribed &member)
00056 {
00057 if (Objectives.empty())
00058 throw FatalException(
00059 "In Multi1DRecObjective: No Objective functions set !");
00060 const size_t nobjs = Objectives.size();
00061 for (size_t i = 0; i < nobjs; ++i)
00062 {
00063 Objectives.at(i)->SetParallelID(GetParallelID() + stringify(i));
00064
00065 }
00066 for_each(Objectives.begin(), Objectives.end(), boost::bind(
00067 &C1DRecObjective::PreParallel, _1, member));
00068 }
00069 double Multi1DRecObjective::PostParallel(const ttranscribed &member)
00070 {
00071
00072 std::vector<double> values;
00073 const size_t nobjs = Objectives.size();
00074 for (size_t i = 0; i < nobjs; ++i)
00075 {
00076 Objectives.at(i)->SetParallelID(GetParallelID() + stringify(i));
00077
00078 }
00079 transform(Objectives.begin(), Objectives.end(), back_inserter(values),
00080 boost::bind(&C1DRecObjective::PostParallel, _1, member));
00081 double sumsquares = inner_product(values.begin(), values.end(),
00082 values.begin(), 0.0);
00083
00084
00085 return sqrt(sumsquares / values.size());
00086 }
00087 void Multi1DRecObjective::SafeParallel(const ttranscribed &member)
00088 {
00089 const size_t nobjs = Objectives.size();
00090 for (size_t i = 0; i < nobjs; ++i)
00091 {
00092 Objectives.at(i)->SetParallelID(GetParallelID() + stringify(i));
00093
00094 }
00095 for_each(Objectives.begin(), Objectives.end(), boost::bind(
00096 &C1DRecObjective::SafeParallel, _1, member));
00097 }
00098
00099 void Multi1DRecObjective::WriteData(const std::string &filename)
00100 {
00101 const size_t nobjs = Objectives.size();
00102 for (size_t i = 0; i < nobjs; ++i)
00103 {
00104 Objectives.at(i)->WriteData(filename + stringify(i));
00105
00106 }
00107
00108
00109 }
00110
00111 void Multi1DRecObjective::WriteModel(const std::string &filename)
00112 {
00113 Objectives.front()->WriteModel(filename);
00114 }
00115
00116 void Multi1DRecObjective::WritePlot(const std::string &filename)
00117 {
00118 Objectives.front()->WritePlot(filename);
00119 }
00120
00121 Multi1DRecObjective::Multi1DRecObjective()
00122 {
00123 }
00124
00125 Multi1DRecObjective::~Multi1DRecObjective()
00126 {
00127 }
00128
00129 Multi1DRecObjective::Multi1DRecObjective(const Multi1DRecObjective &Old)
00130 {
00131 const size_t nobjs = Old.Objectives.size();
00132 Objectives.clear();
00133 for (size_t i = 0; i < nobjs; ++i)
00134 {
00135 boost::shared_ptr<C1DRecObjective> Obj(
00136 Old.Objectives.at(i)->clone());
00137 Objectives.push_back(Obj);
00138 }
00139 }
00140
00141 Multi1DRecObjective& Multi1DRecObjective::operator=(
00142 const Multi1DRecObjective& source)
00143 {
00144 if (this == &source)
00145 return *this;
00146 const size_t nobjs = source.Objectives.size();
00147 Objectives.clear();
00148 for (size_t i = 0; i < nobjs; ++i)
00149 {
00150 boost::shared_ptr<C1DRecObjective> Obj(
00151 source.Objectives.at(i)->clone());
00152 Objectives.push_back(Obj);
00153 }
00154 return *this;
00155 }
00156 }