00001 #include "indii/fmri/hemodynamic/LogFlowBalloonModel.hpp"
00002 #include "indii/fmri/hemodynamic/LogBOLDCalculator.hpp"
00003 #include "indii/ml/ode/AdaptiveRungeKutta.hpp"
00004
00005 #include <iostream>
00006 #include <string.h>
00007 #include <math.h>
00008
00009 using namespace std;
00010 using namespace indii::fmri::hemodynamic;
00011 using namespace indii::ml::ode;
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 static const double TAU_0 = 2.0;
00040
00041
00042
00043
00044 static const double E_0 = 0.4;
00045
00046
00047
00048
00049 static const double V_0 = 0.01;
00050
00051
00052
00053
00054 static const double ALPHA = 0.5;
00055
00056
00057
00058
00059 static const double END = 20.0;
00060
00061
00062
00063
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 double F_OUT(double t, const double y[], void* o) {
00080 double v = exp(y[LogFlowBalloonModel::LN_V]);
00081
00082 return 0.7/8.0 * pow((v - 1.0)*2.0/0.3, 3.0) + 1.0;
00083 }
00084
00085
00086
00087
00088 int main(int argc, const char* argv[]) {
00089 LogFlowBalloonModel balloonModel;
00090 LogBOLDCalculator boldCalculator(&balloonModel);
00091 AdaptiveRungeKutta ode(&balloonModel, balloonModel.suggestInitialState());
00092
00093
00094 balloonModel.setFunction(LogFlowBalloonModel::F_IN, F_IN);
00095 balloonModel.setFunction(LogFlowBalloonModel::F_OUT, F_OUT);
00096 balloonModel.setParameter(LogFlowBalloonModel::TAU_0, TAU_0);
00097 balloonModel.setParameter(LogFlowBalloonModel::E_0, E_0);
00098 balloonModel.setParameter(LogFlowBalloonModel::V_0, V_0);
00099 balloonModel.setParameter(LogFlowBalloonModel::ALPHA, ALPHA);
00100
00101
00102 double cmro2;
00103
00104 double t = 0.0;
00105 while (t < END) {
00106 cmro2 = balloonModel.getFunction(LogFlowBalloonModel::E) /
00107 balloonModel.getParameter(LogFlowBalloonModel::E_0) *
00108 balloonModel.getFunction(LogFlowBalloonModel::F_IN);
00109 cout << t << "\t";
00110 cout << balloonModel.getFunction(LogFlowBalloonModel::F_IN) << "\t";
00111 cout << balloonModel.getFunction(LogFlowBalloonModel::F_OUT) << "\t";
00112 cout << cmro2 << "\t";
00113 cout << ode.getVariable(LogFlowBalloonModel::LN_Q) << "\t";
00114 cout << ode.getVariable(LogFlowBalloonModel::LN_V) << "\t";
00115 cout << boldCalculator.calculate(ode.getState()) * 100.0 << "\t";
00116 cout << endl;
00117 t = ode.step(END);
00118 }
00119
00120 return 0;
00121 }