test7.cpp

Go to the documentation of this file.
00001 #include "indii/fmri/hemodynamic/NeuralBalloonModel.hpp"
00002 #include "indii/fmri/hemodynamic/FlowBalloonModel.hpp"
00003 #include "indii/fmri/hemodynamic/BOLDCalculator.hpp"
00004 #include "indii/ml/ode/AdaptiveRungeKutta.hpp"
00005 #include "indii/ml/aux/vector.hpp"
00006 
00007 #include <iostream>
00008 #include <fstream>
00009 #include <string.h>
00010 #include <math.h>
00011 
00012 namespace aux = indii::ml::aux;
00013 
00014 using namespace std;
00015 using namespace indii::fmri::hemodynamic;
00016 using namespace indii::ml::ode;
00017 
00018 /**
00019  * @file test7.cpp
00020  *
00021  * Test of jump features.
00022  *
00023  * This test uses a default NeuralBalloonModel with a driving neural activity
00024  * function \f$u(t)\f$ consisting of a 1 s long burst of activity followed by
00025  * no activity. The model is simulated for 60s, then reset to its state at the
00026  * 5s mark and simulated again for the remaining time. The idea is to ensure
00027  * that use of setState() and setTime() achieve consistent results with
00028  * running the model from time zero.
00029  *
00030  * Results are output into files \c results/test7.out and \c
00031  * results/test7_repeat.out, tab delimited, with columns representing:
00032  *
00033  * \li \f$t\f$; time
00034  * \li \f$u(t)\f$
00035  * \li \f$q\f$
00036  * \li \f$v\f$
00037  * \li \f$f\f$
00038  * \li \f$s\f$
00039  * \li \f$y\f$; BOLD response
00040  *
00041  * Results are as follows:
00042  *
00043  * \image html test7.png "Results"
00044  * \image latex test7.eps "Results"
00045  *
00046  * The original simulation is plotted with a dotted line in each
00047  * case. Starting from the 5s mark, the repeated simulation is plotted with a
00048  * solid line, which should exactly overlay the dotted line for the remainder
00049  * of the simulation.
00050  */
00051 
00052 /**
00053  * Duration of simulation (s).
00054  */
00055 static const double END = 60.0;
00056 static const double JUMP = 5.0;
00057 
00058 /**
00059  * \f$u(t)\f$; 1 for 1 s, then 0.
00060  */
00061 double U(double t, const double y[], void* o) {
00062   double u;
00063   if (t < 1.0) {
00064     u = 1.0;
00065   } else {
00066     u = 0.0;
00067   }
00068   return u;
00069 }
00070 
00071 /**
00072  * Run tests.
00073  */
00074 int main(int argc, const char* argv[]) {
00075   ofstream first("results/test7.out");
00076   ofstream repeat("results/test7_repeat.out");
00077 
00078   NeuralBalloonModel balloonModel;
00079   BOLDCalculator boldCalculator(&balloonModel);
00080   AdaptiveRungeKutta ode(&balloonModel, balloonModel.suggestInitialState());
00081 
00082   /* set up balloon model */
00083   balloonModel.setFunction(NeuralBalloonModel::U, U);
00084 
00085   double t_jump;
00086   aux::vector y_jump(4);
00087   double t = 0.0;
00088   while (t < JUMP) {
00089     first << t << "\t";
00090     first << balloonModel.getFunction(NeuralBalloonModel::U) << "\t";
00091     first << ode.getVariable(FlowBalloonModel::Q) << "\t";
00092     first << ode.getVariable(FlowBalloonModel::V) << "\t";
00093     first << ode.getVariable(NeuralBalloonModel::F) << "\t";
00094     first << ode.getVariable(NeuralBalloonModel::S) << "\t";
00095     first << boldCalculator.calculate(ode.getState()) * 100.0 << "\t";
00096     first << endl;
00097     t = ode.step(JUMP);
00098   }
00099   t_jump = ode.getTime();
00100   y_jump = ode.getState();
00101   while (t < END) {
00102     first << t << "\t";
00103     first << balloonModel.getFunction(NeuralBalloonModel::U) << "\t";
00104     first << ode.getVariable(FlowBalloonModel::Q) << "\t";
00105     first << ode.getVariable(FlowBalloonModel::V) << "\t";
00106     first << ode.getVariable(NeuralBalloonModel::F) << "\t";
00107     first << ode.getVariable(NeuralBalloonModel::S) << "\t";
00108     first << boldCalculator.calculate(ode.getState()) * 100.0 << "\t";
00109     first << endl;
00110     t = ode.step(END);
00111   }
00112   ode.setTime(t_jump);
00113   ode.setState(y_jump);
00114   t = ode.getTime();
00115   while (t < END) {
00116     repeat << t << "\t";
00117     repeat << balloonModel.getFunction(NeuralBalloonModel::U) << "\t";
00118     repeat << ode.getVariable(FlowBalloonModel::Q) << "\t";
00119     repeat << ode.getVariable(FlowBalloonModel::V) << "\t";
00120     repeat << ode.getVariable(NeuralBalloonModel::F) << "\t";
00121     repeat << ode.getVariable(NeuralBalloonModel::S) << "\t";
00122     repeat << boldCalculator.calculate(ode.getState()) * 100.0 << "\t";
00123     repeat << endl;
00124     t = ode.step(END);
00125   }
00126 
00127   return 0;
00128 }

Generated on Mon Aug 13 19:51:39 2007 for fmrii Hemodynamic Models Test Suite by  doxygen 1.5.2