mtanisoenum.cpp
Go to the documentation of this file.00001 #include <iostream>
00002 #include <fstream>
00003 #include <algorithm>
00004 #include <numeric>
00005 #include <sstream>
00006 #include <string>
00007 #include "UniformRNG.h"
00008 #include "gentypes.h"
00009 #include "PTensor1DMTObjective.h"
00010 #include "Aniso1DMTObjective.h"
00011 #include "PTensorMTStation.h"
00012 #include "MTStation.h"
00013 #include "Adaptors.h"
00014 #include "MTFitSetup.h"
00015 #include <boost/bind.hpp>
00016 #include <boost/shared_ptr.hpp>
00017 #include <boost/filesystem.hpp>
00018 #include <boost/date_time/posix_time/posix_time.hpp>
00019 #include <complex>
00020 #include "Util.h"
00021 #include "MTAnisoRoughness.h"
00022 #include "MTAnisoGAConf.h"
00023 #include "convert.h"
00024 enum tgatype {pareto,anneal};
00025 const int nobjective = 2;
00026 typedef boost::shared_ptr<GeneralObjective> pCGeneralObjective;
00027 using namespace std;
00028
00029
00030
00031 int main(int argc, char *argv[])
00032 {
00033 string version = "$Id: 1dinvga.cpp 1272 2007-07-03 23:17:36Z max $";
00034 cout << endl << endl;
00035 cout << "Program " << version << endl;
00036 cout << "Genetic algorithm to jointly invert seismic and MT data " << endl;
00037 cout << "look at 1dinvga.conf for configuration and setup " << endl;
00038 cout << "The root name of log-files can be overwritten by using " << endl;
00039 cout << "1dinvga newrootname " << endl;
00040
00041 MTAnisoGAConf Configuration;
00042
00043 try
00044 {
00045 Configuration.GetData("mtanisoga.conf");
00046
00047
00048 string outputbase;
00049
00050 if (argc > 1)
00051 outputbase = argv[1];
00052 else
00053 outputbase = Configuration.outputbase;
00054
00055
00056
00057 if ( (Configuration.thickbase.size() != Configuration.resbase.size()) ||
00058 (Configuration.thickbase.size() != Configuration.anisobase.size()) ||
00059 (Configuration.thickbase.size() != Configuration.strikebase.size()))
00060 {
00061 cerr << "Configuration of genes is not consistent ! ";
00062 return 100;
00063 }
00064
00065 string modelfile;
00066 cout << "Model file name: ";
00067 cin >> modelfile;
00068
00069 C1DAnisoMTSynthData StartModel;
00070 StartModel.ReadModel(modelfile);
00071 ttranscribed origmodel = StartModel.GetModelVector();
00072 const unsigned int nmodelparameters = origmodel.size();
00073 const unsigned int nsections = 4;
00074 const unsigned int nparmspersection = nmodelparameters/4;
00075 ttranscribed basevalues(nmodelparameters), steps(nmodelparameters),sizes(nmodelparameters);
00076
00077 copy(Configuration.resbase.begin(),Configuration.resbase.end(),basevalues.begin());
00078 copy(Configuration.thickbase.begin(),Configuration.thickbase.end(),basevalues.begin()+nparmspersection);
00079 copy(Configuration.anisobase.begin(),Configuration.anisobase.end(),basevalues.begin()+2*nparmspersection);
00080 copy(Configuration.strikebase.begin(),Configuration.strikebase.end(),basevalues.begin()+3*nparmspersection);
00081
00082 copy(Configuration.resstep.begin(),Configuration.resstep.end(),steps.begin());
00083 copy(Configuration.thickstep.begin(),Configuration.thickstep.end(),steps.begin()+nparmspersection);
00084 copy(Configuration.anisostep.begin(),Configuration.anisostep.end(),steps.begin()+2*nparmspersection);
00085 copy(Configuration.strikestep.begin(),Configuration.strikestep.end(),steps.begin()+3*nparmspersection);
00086
00087 copy(Configuration.ressizes.begin(),Configuration.ressizes.end(),sizes.begin());
00088 copy(Configuration.thicksizes.begin(),Configuration.thicksizes.end(),sizes.begin()+nparmspersection);
00089 copy(Configuration.anisosizes.begin(),Configuration.anisosizes.end(),sizes.begin()+2*nparmspersection);
00090 copy(Configuration.strikesizes.begin(),Configuration.strikesizes.end(),sizes.begin()+3*nparmspersection);
00091
00092 boost::shared_ptr<PlottableObjective> MTObjective;
00093
00094 if(Configuration.mtfit == "ptensor")
00095 {
00096 PTensorMTStation PTData;
00097 PTData.GetData(Configuration.ptensordata);
00098 boost::shared_ptr<PTensor1DMTObjective> PTObjective(new PTensor1DMTObjective(PTData));
00099 MTObjective = PTObjective;
00100 }
00101 else
00102 {
00103 MTStation MTData;
00104 MTData.GetData(Configuration.mtinputdata);
00105 boost::shared_ptr<Aniso1DMTObjective> AnisoObjective(new Aniso1DMTObjective(MTData));
00106 SetupMTFitParameters(Configuration,*AnisoObjective);
00107 MTObjective = AnisoObjective;
00108 }
00109
00110 ofstream misfitfile;
00111 ofstream gmtfile("plotenum");
00112 double misfit = 0;
00113 double delta = 0.1;
00114 gmtfile << "gmtset PAPER_MEDIA A0" << endl;
00115 gmtfile << "psbasemap -JX20 -R0/20/0/20 -G254 -K > plotenum.ps" << endl;
00116 for (unsigned int i= 0; i < nmodelparameters; ++i)
00117 {
00118 ttranscribed currmodel = origmodel;
00119 string misfitfilename = "misfit"+stringify(i);
00120 misfitfile.open(misfitfilename.c_str());
00121 currmodel(i) = basevalues(i);
00122 const unsigned int currsize = pow(2,sizes(i));
00123 double maxmisfit = -1;
00124 double minmisfit = 1e50;
00125 for (unsigned int j = 0; j < currsize; ++j)
00126 {
00127 misfit = MTObjective->CalcPerformance(currmodel);
00128 misfitfile << currmodel(i) << " " << misfit << endl;
00129 currmodel(i) += steps(i);
00130 maxmisfit = max(maxmisfit,misfit);
00131 minmisfit = min(minmisfit,misfit);
00132 }
00133 double minx = basevalues(i)-delta;
00134 double maxx = basevalues(i)+currsize*steps(i)+delta;
00135 string region = " -R"+stringify(minx)+"/"+stringify(maxx)+"/"+stringify(minmisfit*0.9)+"/"+stringify(maxmisfit*1.1);
00136 int xticks = ceil((maxx - minx)/10.);
00137 int yticks = ceil(maxmisfit/10);
00138 string ticks = " -B"+stringify(xticks)+"/"+stringify(yticks)+" ";
00139 string shiftstring;
00140 double xshift = 10;
00141 double yshift = 10;
00142 if ((i % nparmspersection) == 0 && i!=0)
00143 shiftstring = " -X-"+stringify(xshift*(nparmspersection-1))+" -Y"+stringify(yshift);
00144 else
00145 if (i!=0)
00146 shiftstring = " -X"+stringify(xshift);
00147 gmtfile << "psxy " + misfitfilename + " " + shiftstring+ " -JX7/7l " + region + ticks + " -O -K >> plotenum.ps" << endl;
00148 misfitfile.close();
00149 }
00150 }
00151 catch(CFatalException &e)
00152 {
00153 cerr << e.what() << endl;
00154 return -1;
00155 }
00156 }