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
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 static const double END = 60.0;
00056 static const double JUMP = 5.0;
00057
00058
00059
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
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
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 }