00001 #include "DoubleWell.hpp"
00002
00003 #include "indii/ml/ode/EquilibriumSampler.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
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 const unsigned int M = 1;
00026
00027
00028
00029
00030 const unsigned int N = 1;
00031
00032
00033
00034
00035 const unsigned int P = 1200;
00036
00037
00038
00039
00040 const double BURN = 20.0;
00041
00042
00043
00044
00045 const double INTERVAL = 1.0;
00046
00047
00048
00049
00050 const unsigned int RES = 100;
00051
00052
00053
00054
00055 const double LOWER = -1.5;
00056
00057
00058
00059
00060 const double UPPER = 1.5;
00061
00062
00063
00064
00065 int main(int argc, const char* argv[]) {
00066 unsigned int i, j;
00067 aux::vector y(M);
00068 double s;
00069 std::ofstream fout("results/EquilibriumSamplerHarness.out");
00070
00071 DoubleWell model;
00072 indii::ml::sde::StochasticAdaptiveRungeKutta<> solver(&model);
00073 solver.setErrorBounds(1.0e-3, 1.0e-2);
00074
00075 for (i = 0; i < N; i++) {
00076 y(0) = aux::Random::uniform(-1.0, 1.0);
00077
00078 solver.setTime(0.0);
00079 solver.setState(y);
00080 solver.setStepSize(1.0e-4);
00081
00082 indii::ml::ode::EquilibriumSampler stationary(&solver, BURN, INTERVAL);
00083 std::vector<unsigned int> counts(RES);
00084 for (j = 0; j < RES; j++) {
00085 counts[i] = 0;
00086 }
00087
00088 for (j = 0; j < P; j++) {
00089 s = stationary.sample()(0);
00090 if (s > LOWER && s < UPPER) {
00091 counts[(int)floor((s - LOWER) / (UPPER - LOWER) * RES)]++;
00092 }
00093 }
00094
00095 for (j = 0; j < RES; j++) {
00096 fout << LOWER + (UPPER - LOWER) * j / RES << '\t';
00097 fout << counts[j] << std::endl;
00098 }
00099 fout << std::endl;
00100 }
00101
00102 return 0;
00103 }
00104