Permalink
Browse files

Code cleanups.

Added license
Made comments linebreak save

Signed-off-by: Schellenberger <schellenberger@inb.uni-luebeck.de>
  • Loading branch information...
1 parent f5a83cf commit d8682171acd5293922a3ffc3b91aad5af58d577c @miscco committed Apr 24, 2014
Showing with 365 additions and 173 deletions.
  1. +31 −8 Main.cpp
  2. +25 −2 ODE.h
  3. +72 −27 Stimulation.h
  4. +55 −43 Thalamic_Column.cpp
  5. +97 −75 Thalamic_Column.h
  6. +40 −18 Thalamus.cpp
  7. +23 −0 macros.h
  8. +22 −0 saves.h
View
@@ -1,3 +1,25 @@
+/*
+* Copyright (c) 2014 Michael Schellenberger Costa
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+* THE SOFTWARE.
+*/
+
/****************************************************************************************************/
/* Main file for compilation tests */
/* The Simulation requires the following boost libraries: Preprocessor */
@@ -11,10 +33,11 @@
/****************************************************************************************************/
/* Fixed simulation settings */
/****************************************************************************************************/
-extern const int T = 60;
-extern const int res = 1E4;
-extern const double dt = 1E3/res;
-extern const double h = sqrt(dt);
+extern const int T = 30; /* Simulation length s */
+extern const int res = 1E4; /* number of iteration steps per s */
+extern const int red = res/100; /* number of iterations that is saved */
+extern const double dt = 1E3/res; /* duration of a timestep in ms */
+extern const double h = sqrt(dt); /* squareroot of dt for SRK iteration */
/****************************************************************************************************/
/* end */
/****************************************************************************************************/
@@ -24,20 +47,20 @@ extern const double h = sqrt(dt);
/* Main simulation routine */
/****************************************************************************************************/
int main(void) {
- // Initializing the populations;
+ /* Initialize the populations */
Thalamic_Column Thalamus;
- // takes the time of the simulation
+ /* Takes the time of the simulation */
time_t start,end;
time (&start);
- // simulation
+ /* Simulation */
for (int t=0; t< T*res; ++t) {
ODE (Thalamus);
}
time (&end);
- // time consumed by the simulation
+ /* Time consumed by the simulation */
double dif = difftime(end,start);
std::cout << "simulation done!\n";
std::cout << "took " << dif << " seconds" << "\n";
View
27 ODE.h
@@ -1,3 +1,25 @@
+/*
+* Copyright (c) 2014 Michael Schellenberger Costa
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+* THE SOFTWARE.
+*/
+
/****************************************************************************************************/
/* Implementation of the ODE solver */
/****************************************************************************************************/
@@ -8,11 +30,12 @@
/* Evaluation of SRK4 */
/****************************************************************************************************/
inline void ODE(Thalamic_Column& Thalamus) {
- // first calculating every ith RK moment
- // has to be in order, 1th moment first
+ /* First calculating every ith RK moment. Has to be in order, 1th moment first */
for (int i=1; i<=4; ++i) {
Thalamus.set_RK(i);
}
+
+ /* Add moments */
Thalamus.add_RK();
}
/****************************************************************************************************/
View
@@ -1,3 +1,25 @@
+/*
+* Copyright (c) 2014 Michael Schellenberger Costa
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+* THE SOFTWARE.
+*/
+
/****************************************************************************************************/
/* Implementation of the stimulation protocol */
/****************************************************************************************************/
@@ -9,32 +31,32 @@
/****************************************************************************************************/
class Stim {
public:
- /* empty constructor for compiling */
+ /* Empty constructor for compiling */
Stim(void);
Stim(Thalamic_Column& T, double* var)
{ Thalamus = &T;
setup(var);}
- /* setup with respect to stimulation mode */
+ /* Setup with respect to stimulation mode */
void setup (double* var_stim) {
extern const int onset;
extern const int res;
extern const int dt;
- /* mode of stimulation */
+ /* Mode of stimulation */
mode = (int) var_stim[0];
- /* scale the stimulation strength from s^-1 to ms^-1 */
+ /* Scale the stimulation strength from s^-1 to ms^-1 */
strength = var_stim[1] / 1000;
- /* scale duration from ms to dt */
+ /* Scale duration from ms to dt */
duration = (int) var_stim[2] * res / 1000;
- /* scale the ISI from s to ms^-1 */
+ /* Scale the ISI from s to ms^-1 */
ISI = (int) var_stim[3] * res;
- /* scale time to stimulus from ms to dt */
+ /* Scale time to stimulus from ms to dt */
time_to_stim= (int) var_stim[4] * res / 1000;
if(mode==1) {
@@ -47,33 +69,35 @@ class Stim {
void check_stim (int time) {
- /* check if stimulation should start */
+ /* Check if stimulation should start */
switch (mode) {
- /* no stimulation */
+ /* No stimulation */
default:
break;
- /* periodic stimulation */
+ /* Periodic stimulation */
case 1:
- /* check if time is reached */
+ /* Check if time is reached */
if(time == time_to_stim) {
- /* switch stimulation on */
+ /* Switch stimulation on */
stimulation_started = true;
Thalamus->set_input(strength);
- /* update the timer */
+ /* Update the timer */
time_to_stim += ISI;
+
+ /* Update the marker */
+ marker_stimulation.push_back(time - correction);
}
break;
-
}
- /* wait to switch the stimulation off */
+ /* Wait to switch the stimulation off */
if(stimulation_started) {
count_duration++;
- /* switch stimulation off */
+ /* Switch stimulation off */
if(count_duration==duration) {
stimulation_started = false;
count_duration = 0;
@@ -82,22 +106,38 @@ class Stim {
}
}
+ /* Create MATLAB container for marker storage */
+ mxArray* get_marker(void) {
+ mxArray* Marker = mxCreateDoubleMatrix(0, 0, mxREAL);
+ mxSetM(Marker, 1);
+ mxSetN(Marker, marker_stimulation.size());
+ mxSetData(Marker, mxMalloc(sizeof(double)*marker_stimulation.size()));
+ double* Pr_Marker = mxGetPr(Marker);
+ for(unsigned i=0; i<marker_stimulation.size(); ++i) {
+ Pr_Marker[i] = marker_stimulation[i];
+ }
+ return Marker;
+ }
+
private:
/* Stimulation parameters */
- /* stimulation strength */
+ /* Stimulation strength */
double strength = 0.0;
- /* duration of the stimulation */
+ /* Duration of the stimulation */
int duration = 500;
- /* inter stimulus intervall in case of periodic stimulation */
+ /* Inter stimulus intervall in case of periodic stimulation */
int ISI = 5E4;
- /* time until stimulus after minimum was found */
+ /* Threshold for phase dependent stimulation */
+ double threshold = -80;
+
+ /* Time until stimulus after minimum was found */
int time_to_stim = 5500;
- /* mode of stimulation */
+ /* Mode of stimulation */
/* 0 == none */
/* 1 == periodic */
int mode = 0;
@@ -106,18 +146,23 @@ class Stim {
/* Simulation on for TRUE and off for FALSE */
bool stimulation_started= false;
- /* onset in timesteps to correct the given time of the markers */
+ /* Threshold has been reached */
+ bool threshold_crossed = false;
+
+ /* Minimum found */
+ bool minimum_found = false;
+
+ /* Onset in timesteps to correct the given time of the markers */
int correction = 10000;
- /* counter for stimulation duration */
+ /* Counter for stimulation duration */
int count_duration = 0;
- /* counter after minimum */
- int count_to_start = 0;
-
- /* pointer to thalamic column */
+ /* Pointer to thalamic column */
Thalamic_Column* Thalamus;
+ /* Data containers */
+ std::vector<int> marker_stimulation;
};
/****************************************************************************************************/
/* end */
Oops, something went wrong.

0 comments on commit d868217

Please sign in to comment.