AutoCorrelatorHarness.cpp

Go to the documentation of this file.
00001 #include "DoubleWell.hpp"
00002 
00003 #include "indii/ml/ode/AutoCorrelator.hpp"
00004 #include "indii/ml/sde/StochasticAdaptiveRungeKutta.hpp"
00005 
00006 #include <iostream>
00007 #include <fstream>
00008 
00009 namespace aux = indii::ml::aux;
00010 
00011 /**
00012  * @file AutoCorrelatorHarness.cpp
00013  *
00014  * Test of AutoCorrelator with DoubleWell model.
00015  *
00016  * This test calculates the autocorrelation of DoubleWell using
00017  * indii::ml::ode::AutoCorrelator.
00018  *
00019  * Results are as follows:
00020  *
00021  * @image html AutoCorrelatorHarness.png "Results"
00022  * @image latex AutoCorrelatorHarness.eps "Results"
00023  */
00024 
00025 /**
00026  * Dimensionality of the process.
00027  */
00028 const unsigned int M = 1;
00029 
00030 /**
00031  * Number of sample trajectories.
00032  */
00033 const unsigned int N = 1;
00034 
00035 /**
00036  * Time length of each trajectory.
00037  */
00038 const double LENGTH = 1200.0;
00039 
00040 /**
00041  * Autocorrelation step.
00042  */
00043 const double DELTA = 1.0;
00044 
00045 /**
00046  * Autocorrelation steps between convergence checks.
00047  */
00048 const unsigned int STEPS = 10;
00049 
00050 /**
00051  * Run tests.
00052  */
00053 int main(int argc, const char* argv[]) {
00054   unsigned int i;
00055   aux::vector y(M);
00056   bool hasConverged;
00057   std::ofstream fout("results/AutoCorrelatorHarness.out");
00058 
00059   DoubleWell model;
00060   indii::ml::sde::StochasticAdaptiveRungeKutta<> solver(&model);
00061   solver.setErrorBounds(1.0e-3, 1.0e-2);
00062 
00063   for (i = 0; i < N; i++) {
00064     y(0) = aux::Random::uniform(-1.0, 1.0);
00065 
00066     solver.setTime(0.0);
00067     solver.setState(y);
00068     solver.setStepSize(1.0e-4);
00069 
00070     indii::ml::ode::AutoCorrelator autocor(&solver, DELTA);
00071 
00072     while (solver.getTime() < LENGTH) {
00073       hasConverged = autocor.step(STEPS);    
00074 
00075       fout << solver.getTime() << '\t';
00076       fout << autocor.getAutoCorrelation()(0,0) << '\t';
00077       if (hasConverged) {
00078         fout << 1;
00079       } else {
00080         fout << 0;
00081       }
00082       fout << std::endl;
00083     }
00084     fout << std::endl;
00085   }
00086 
00087   return 0;
00088 }
00089 

Generated on Wed Dec 17 14:56:36 2008 for dysii SDE Test Suite by  doxygen 1.5.3