perturbmt.cpp

Go to the documentation of this file.
00001 #include "GradFunc.h"
00002 #include "UniformRNG.h"
00003 #include "convert.h"
00004 #include "C1DMTSynthData.h"
00005 #include "C1DMTObjective.h"
00006 #include "C1dInvGaConf.h"
00007 #include "NetCDFTools.h"
00008 #include "netcdfcpp.h"
00009 #include "MTFitSetup.h"
00010 #include <iostream>
00011 #include <fstream>
00012 #include <boost/bind.hpp>
00013 #include "VecMat.h"
00014 #include <algorithm>
00015 #include <string>
00016 
00017 using namespace std;
00018 
00019 int main()
00020   {
00021     C1dInvGaConf Configuration;
00022     Configuration.GetData("1dinvga.conf");
00023 
00024     CMTStation MTData;
00025     string datanamebase;
00026     cout << "Data name base: ";
00027     cin >> datanamebase;
00028     MTData.GetData(datanamebase + ".mtt");
00029 
00030     C1DMTObjective MTObjective(MTData);
00031     SetupMTFitParameters(Configuration, MTObjective);
00032     string modelnamebase;
00033     cout << "Model name base: ";
00034     cin >> modelnamebase;
00035     C1DMTSynthData MTModel;
00036     MTModel.readmodel(modelnamebase + "_mt.mod");
00037 
00038     ublas::vector<double> MTModelVector = MTModel.GetModelVector();
00039 
00040     double MTOldRMS = MTObjective.CalcPerformance(MTModelVector);
00041     ublas::vector<double> OldData(MTObjective.GetSynthData());
00042     ModelAnalysis MTAnalyser(MTObjective);
00043     MTAnalyser.SetModel(MTModelVector);
00044 
00045     cout << "MT Singular Values : " << MTAnalyser.GetSingularValues() << endl;
00046     //cout << "MT Analysis R: " << MTAnalyser.GetModelResolution() << endl;
00047     //cout << "MT Analysis Null: " << MTAnalyser.GetModelNullspace() << endl;
00048     cout << "Relative SVD Threshold: ";
00049     double svdthreshold = 0.0;
00050     cin >> svdthreshold;
00051     MTAnalyser.SetRelativeSVDThreshold(svdthreshold);
00052     ublas::vector<double> MTProjection(MTModelVector),
00053         MTPerturb(MTModelVector), MTNewModel(MTModelVector);
00054 
00055     UniformRNG Random;
00056     double MTNewRMS = MTOldRMS;
00057     cout << "Original RMS : " << MTOldRMS << endl;
00058     const int maxit = 20;
00059     int currit = 0;
00060     MTPerturb *= 0.0;
00061     for (int i = 0; i < MTPerturb.size(); ++i)
00062       MTPerturb(i) = Random.GetNumber(-1., 1.);
00063     MTNewModel = MTModelVector;
00064     while (std::abs(MTNewRMS - MTOldRMS) / MTOldRMS < 0.05 && currit < maxit)
00065       {
00066         MTProjection = prod(MTAnalyser.GetModelNullspace(), MTPerturb);
00067         MTNewModel += MTProjection;
00068         MTNewRMS = MTObjective.CalcPerformance(MTNewModel);
00069         cout << "MT New RMS: " << MTNewRMS << endl;
00070         ++currit;
00071       }
00072 
00073     MTObjective.WriteData("new.mtt");
00074 
00075     MTObjective.WritePlot("new_mt.plot");
00076 
00077     MTObjective.WriteModel("new_mt.mod");
00078     cout << "MT OldRMS: " << MTOldRMS << " MT NewRMS: " << MTNewRMS << endl;
00079 
00080     cout << "MT Old Model: " << MTModelVector << endl;
00081     cout << "MT New Model: " << MTNewModel << endl;
00082 
00083     WriteMatrixAsNetCDF("mtres.nc", MTAnalyser.GetModelResolution());
00084     WriteMatrixAsNetCDF("mtnull.nc", MTAnalyser.GetModelNullspace());
00085   }

Generated on Tue May 4 16:52:14 2010 for GPLIB++ by  doxygen 1.5.8