test1.cpp

Go to the documentation of this file.
00001 #include "indii/fmri/hemodynamic/FlowBalloonModel.hpp"
00002 #include "indii/fmri/hemodynamic/BOLDCalculator.hpp"
00003 #include "indii/ml/ode/AdaptiveRungeKutta.hpp"
00004 
00005 #include <iostream>
00006 #include <string.h>
00007 
00008 using namespace std;
00009 using namespace indii::fmri::hemodynamic;
00010 using namespace indii::ml::ode;
00011 
00012 /**
00013  * @file test1.cpp
00014  *
00015  * Basic test of FlowBalloonModel.
00016  *
00017  * This test configures a FlowBalloonModel with parameters and
00018  * functions set according to the first experiment in Buxton et
00019  * al. (1998). Results are output on stdout, tab delimited, with
00020  * columns representing:
00021  *
00022  * \li \f$t\f$; time
00023  * \li \f$f_{in}(t)\f$
00024  * \li \f$f_{out}(t)\f$
00025  * \li \f$CMRO_2(t) = \frac{E(t)}{E_0}f_{in}(t)\f$ (Buxton et al. 2004).
00026  * \li \f$q\f$
00027  * \li \f$v\f$
00028  * \li \f$y\f$; BOLD response (%)
00029  *
00030  * Results are as follows:
00031  *
00032  * \image html test1.png "Results, c.f. Buxton et al. (1998), Figure 1"
00033  * \image latex test1.eps "Results, c.f. Buxton et al. (1998), Figure 1"
00034  */
00035 
00036 /**
00037  * \f$\tau_0\f$
00038  */
00039 static const double TAU_0 = 2.0;
00040 
00041 /**
00042  * \f$E_0\f$
00043  */
00044 static const double E_0 = 0.4;
00045 
00046 /**
00047  * \f$V_0\f$
00048  */
00049 static const double V_0 = 0.01;
00050 
00051 /**
00052  * \f$\alpha\f$
00053  */
00054 static const double ALPHA = 0.5;
00055 
00056 /**
00057  * Duration of simulation (s).
00058  */
00059 static const double END = 20.0;
00060 
00061 /**
00062  * \f$f_{in}(t)\f$; Trapezoidal function with a rise time of 4 s,
00063  * duration of 4 s and fall time of 4 s.
00064  */
00065 double F_IN(double t, const double y[], void* o) {
00066   double f;
00067   if (t < 4) {
00068     f = (0.7/4.0)*t + 1;
00069   } else if (t < 8) {
00070     f = 1.7;
00071   } else if (t < 12) {
00072     f = (-0.7/4.0)*(t - 8) + 1.7;
00073   } else {
00074     f = 1.0;
00075   }
00076   return f;
00077 }
00078 
00079 /**
00080  * @brief \f$f_{out}(t) = \frac{7}{3}v - \frac{4}{3}\f$;
00081  *
00082  * i.e. linear relative to \f$v\f$ with a gradient of
00083  * \f$\frac{7}{3}\f$, \f$f_{out} = 1\f$ when \f$v = 1\f$.
00084  */
00085 double F_OUT(double t, const double y[], void* o) {
00086   return (7.0/3.0)*y[FlowBalloonModel::V] - 4.0/3.0;
00087 }
00088 
00089 /**
00090  * Run tests.
00091  */
00092 int main(int argc, const char* argv[]) {
00093   FlowBalloonModel balloonModel;
00094   BOLDCalculator boldCalculator(&balloonModel);
00095   AdaptiveRungeKutta ode(&balloonModel, balloonModel.suggestInitialState());
00096 
00097   /* set up balloon model */
00098   balloonModel.setFunction(FlowBalloonModel::F_IN, F_IN);
00099   balloonModel.setFunction(FlowBalloonModel::F_OUT, F_OUT);
00100   balloonModel.setParameter(FlowBalloonModel::TAU_0, TAU_0);
00101   balloonModel.setParameter(FlowBalloonModel::E_0, E_0);
00102   balloonModel.setParameter(FlowBalloonModel::V_0, V_0);
00103   balloonModel.setParameter(FlowBalloonModel::ALPHA, ALPHA);
00104 
00105   double cmro2;
00106 
00107   double t = 0.0;
00108   while (t < END) {
00109     cmro2 = balloonModel.getFunction(FlowBalloonModel::E) /
00110         balloonModel.getParameter(FlowBalloonModel::E_0) *
00111         balloonModel.getFunction(FlowBalloonModel::F_IN);
00112     cout << t << "\t";
00113     cout << balloonModel.getFunction(FlowBalloonModel::F_IN) << "\t";
00114     cout << balloonModel.getFunction(FlowBalloonModel::F_OUT) << "\t";
00115     cout << cmro2 << "\t";
00116     cout << ode.getVariable(FlowBalloonModel::Q) << "\t";
00117     cout << ode.getVariable(FlowBalloonModel::V) << "\t";
00118     cout << boldCalculator.calculate(ode.getState()) * 100.0 << "\t";
00119     cout << endl;
00120 
00121     t = ode.step(END);
00122   }
00123 
00124   return 0;
00125 }

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