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 
00020 
00021 int main()
00022 {
00023         C1dInvGaConf Configuration;
00024         Configuration.GetData("1dinvga.conf");
00025         
00026         CMTStation MTData;
00027         string datanamebase;
00028         cout << "Data name base: ";
00029         cin >> datanamebase;
00030         MTData.GetData(datanamebase+".mtt");
00031         
00032         
00033         C1DMTObjective MTObjective(MTData);
00034         SetupMTFitParameters(Configuration,MTObjective);
00035         string modelnamebase;
00036         cout << "Model name base: ";
00037         cin >> modelnamebase;
00038         C1DMTSynthData MTModel;
00039         MTModel.readmodel(modelnamebase+"_mt.mod");
00040         
00041 
00042         ublas::vector<double> MTModelVector = MTModel.GetModelVector();
00043         
00044         double MTOldRMS = MTObjective.CalcPerformance(MTModelVector);
00045         ublas::vector<double> OldData(MTObjective.GetSynthData());
00046         ModelAnalysis MTAnalyser(MTObjective);
00047         MTAnalyser.SetModel(MTModelVector);
00048         
00049         
00050         cout << "MT Singular Values : " << MTAnalyser.GetSingularValues() << endl;
00051         //cout << "MT Analysis R: " << MTAnalyser.GetModelResolution() << endl;
00052         //cout << "MT Analysis Null: " << MTAnalyser.GetModelNullspace() << endl;
00053         cout << "Relative SVD Threshold: ";
00054         double svdthreshold = 0.0;
00055         cin >> svdthreshold;
00056         MTAnalyser.SetRelativeSVDThreshold(svdthreshold);
00057         ublas::vector<double> MTProjection(MTModelVector), MTPerturb(MTModelVector), MTNewModel(MTModelVector);
00058         
00059         UniformRNG Random;
00060         double MTNewRMS = MTOldRMS;
00061         cout << "Original RMS : " << MTOldRMS << endl;
00062         const int maxit = 20;
00063         int currit = 0;
00064         MTPerturb *=0.0;
00065         for (int i = 0; i < MTPerturb.size(); ++i)
00066                         MTPerturb(i) = Random.GetNumber(-1.,1.);
00067         MTNewModel = MTModelVector;
00068         while (fabs(MTNewRMS - MTOldRMS)/MTOldRMS < 0.05 && currit < maxit)
00069         {
00070                 MTProjection = prod(MTAnalyser.GetModelNullspace(),MTPerturb);
00071                 MTNewModel += MTProjection;
00072                 MTNewRMS = MTObjective.CalcPerformance(MTNewModel);
00073                 cout << "MT New RMS: " << MTNewRMS << endl;
00074                 ++currit;
00075         }
00076         
00077         MTObjective.WriteData("new.mtt");
00078         
00079         MTObjective.WritePlot("new_mt.plot");
00080         
00081         MTObjective.WriteModel("new_mt.mod");
00082         cout << "MT OldRMS: " << MTOldRMS <<  " MT NewRMS: " << MTNewRMS << endl;
00083         
00084         cout << "MT Old Model: " << MTModelVector << endl;
00085         cout << "MT New Model: " << MTNewModel << endl;
00086         
00087         WriteMatrixAsNetCDF("mtres.nc",MTAnalyser.GetModelResolution());
00088         WriteMatrixAsNetCDF("mtnull.nc",MTAnalyser.GetModelNullspace());
00089 }

Generated on Fri Jul 4 15:30:21 2008 for GPLIB++ by  doxygen 1.5.5