StochasticAdaptiveEulerMaruyamaHarness.cpp

Go to the documentation of this file.
00001 #include "DoubleWell.hpp"
00002 
00003 #include "indii/ml/sde/StochasticAdaptiveEulerMaruyama.hpp"
00004 
00005 #include <iostream>
00006 #include <fstream>
00007 
00008 namespace aux = indii::ml::aux;
00009 
00010 /**
00011  * @file StochasticAdaptiveEulerMaruyamaHarness.cpp
00012  *
00013  * Test of StochasticAdaptiveEulerMaruyama with DoubleWell model.
00014  *
00015  * This test simulates a number of trajectories from DoubleWell using
00016  * indii::ml::sde::StochasticAdaptiveEulerMaruyama, plotting each.
00017  *
00018  * Results are as follows:
00019  *
00020  * \image html StochasticAdaptiveEulerMaruyamaHarness.png "Results"
00021  * \image latex StochasticAdaptiveEulerMaruyamaHarness.eps "Results"
00022  */
00023 
00024 /**
00025  * Dimensionality of the process.
00026  */
00027 const unsigned int M = 1;
00028 
00029 /**
00030  * Number of sample trajectories.
00031  */
00032 const unsigned int N = 1;
00033 
00034 /**
00035  * Time length of each trajectory.
00036  */
00037 const double LENGTH = 600.0;
00038 
00039 /**
00040  * Run tests.
00041  */
00042 int main(int argc, const char* argv[]) {
00043   double t;
00044   aux::vector y(M);
00045   unsigned int i;
00046   std::ofstream fout("results/StochasticAdaptiveEulerMaruyamaHarness.out");
00047 
00048   DoubleWell model;
00049   indii::ml::sde::StochasticAdaptiveEulerMaruyama<> solver(&model);
00050 
00051   solver.setErrorBounds(1.0e-3, 1.0e-2);
00052   for (i = 0; i < N; i++) {
00053     t = 0.0;
00054     y(0) = aux::Random::uniform(-1.0, 1.0);
00055 
00056     solver.setTime(t);
00057     solver.setState(y);
00058     solver.setStepSize(1.0e-4);
00059 
00060     while (t < LENGTH) {
00061       t = solver.step(LENGTH);
00062       y = solver.getState();
00063 
00064       fout << t << '\t' << y(0) << std::endl;
00065     }
00066     fout << std::endl;
00067   }
00068 
00069   return 0;
00070 }
00071 

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