Permalink
Browse files

General code cleanup.

Removed dependency on boost libraries.
  • Loading branch information...
1 parent c8fb6e6 commit 1cba4bc319c9ce517108b6226c5f05aa41c477b8 @miscco committed Dec 29, 2015
Showing with 103 additions and 66 deletions.
  1. +2 −2 Cortical_Column.cpp
  2. +2 −15 Cortical_Column.h
  3. 0 saves.h → Data_Storage.h
  4. +8 −7 NM_TC.pro
  5. +81 −0 Random_Stream.h
  6. +5 −17 Stimulation.h
  7. +0 −3 TC.cpp
  8. +1 −4 TC_mex.cpp
  9. +2 −2 Thalamic_Column.cpp
  10. +2 −16 Thalamic_Column.h
View
@@ -44,10 +44,10 @@ void Cortical_Column::set_RNG(void) {
/* Create RNG for each stream */
for (int i=0; i<N; ++i){
/* Add the RNG for I_{l}*/
- MTRands.push_back({ENG(rand()), DIST (0.0, dphi*dt)});
+ MTRands.push_back(random_stream_normal(0.0, dphi*dt));
/* Add the RNG for I_{l,0} */
- MTRands.push_back({ENG(rand()), DIST (0.0, dt)});
+ MTRands.push_back(random_stream_normal(0.0, dt));
/* Get the random number for the first iteration */
Rand_vars.push_back(MTRands[2*i]());
View
@@ -34,23 +34,10 @@
#pragma once
#include <cmath>
#include <vector>
-#include <boost/random/mersenne_twister.hpp>
-#include <boost/random/normal_distribution.hpp>
-#include <boost/random/variate_generator.hpp>
+#include "Random_Stream.h"
#include "Thalamic_Column.h"
using std::vector;
-
class Thalamic_Column;
-/****************************************************************************************************/
-/* Typedefs for RNG */
-/****************************************************************************************************/
-typedef boost::mt11213b ENG; /* Mersenne Twister */
-typedef boost::normal_distribution<double> DIST; /* Normal Distribution */
-typedef boost::variate_generator<ENG,DIST> GEN; /* Variate generator */
-/****************************************************************************************************/
-/* end */
-/****************************************************************************************************/
-
/****************************************************************************************************/
/* Macro for vector initialization */
@@ -131,7 +118,7 @@ class Cortical_Column {
x = _INIT(0.0); /* derivative of y */
/* Random number generators */
- vector<GEN> MTRands;
+ vector<random_stream_normal> MTRands;
/* Container for noise */
vector<double> Rand_vars;
File renamed without changes.
View
@@ -6,15 +6,16 @@ CONFIG -= qt
TARGET = TC.cpp
SOURCES += Cortical_Column.cpp \
- TC.cpp \
- TC_mex.cpp \
+ TC.cpp \
+ TC_mex.cpp \
Thalamic_Column.cpp
-HEADERS += Cortical_Column.h \
- ODE.h \
- saves.h \
- Stimulation.h \
- Thalamic_Column.h
+HEADERS += Cortical_Column.h \
+ Data_Storage.h \
+ ODE.h \
+ Random_Stream.h \
+ Stimulation.h \
+ Thalamic_Column.h
QMAKE_CXXFLAGS += -std=c++11 -O3
View
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2015 University of Lübeck
+ *
+ * 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.
+ *
+ * AUTHORS: Michael Schellenberger Costa: mschellenbergercosta@gmail.com
+ * Stefanie Gareis: gareis@inb.uni-luebeck.de
+ *
+ */
+
+/****************************************************************************************************/
+/* Random number streams */
+/****************************************************************************************************/
+#pragma once
+#include <random>
+
+/****************************************************************************************************/
+/* Struct for normal distribution */
+/****************************************************************************************************/
+struct random_stream_normal
+{
+ /* Random number engine: Mersenne-Twister */
+ std::mt19937_64 mt;
+ /* Random number generator: Normal-distribution */
+ std::normal_distribution<double> norm_dist;
+
+ /* Constructors */
+ random_stream_normal(){}
+ random_stream_normal(double mean, double stddev)
+ : mt(rand()) , norm_dist(mean, stddev)
+ {}
+
+ /* Overwrites the function-call operator "( )" */
+ double operator( )(void) {
+ return norm_dist(mt);
+ }
+};
+/****************************************************************************************************/
+/* end */
+/****************************************************************************************************/
+
+/****************************************************************************************************/
+/* Struct for uniform int distribution */
+/****************************************************************************************************/
+struct random_stream_uniform_int
+{
+ /* Random number engine: Mersenne-Twister */
+ std::mt19937_64 mt;
+ /* Random number generator: Uniform integer-distribution */
+ std::uniform_int_distribution<> uniform_dist;
+
+ /* Constructors */
+ random_stream_uniform_int(){}
+ random_stream_uniform_int(double lower_bound, double upper_bound)
+ : mt(rand()) , uniform_dist(lower_bound, upper_bound)
+ {}
+
+ /* Overwrites the function-call operator "( )" */
+ double operator( )(void) {
+ return uniform_dist(mt);
+ }
+};
+/****************************************************************************************************/
+/* end */
+/****************************************************************************************************/
View
@@ -32,19 +32,11 @@
/* Implementation of the stimulation protocol */
/****************************************************************************************************/
#pragma once
-#include <boost/random/uniform_int_distribution.hpp>
+#include "Random_Stream.h"
#include "Cortical_Column.h"
#include "Thalamic_Column.h"
/****************************************************************************************************/
-/* Typedefs for RNG */
-/****************************************************************************************************/
-typedef boost::random::uniform_int_distribution<> DIST_int; /* Uniform integer distribution */
-/****************************************************************************************************/
-/* end */
-/****************************************************************************************************/
-
-/****************************************************************************************************/
/* Stimulation object */
/****************************************************************************************************/
class Stim {
@@ -151,11 +143,10 @@ class Stim {
Thalamic_Column* Thalamus;
/* Data containers */
- vector<int> marker_stimulation;
+ std::vector<int> marker_stimulation;
/* Random number generator in case of semi-periodic stimulation */
- ENG Generator;
- DIST_int Uniform_Distribution;
+ random_stream_uniform_int Rand_Uniform;
};
/****************************************************************************************************/
/* end */
@@ -205,10 +196,7 @@ void Stim::setup (double* var_stim) {
/* If ISI is random create RNG */
if (ISI_range != 0){
/* Create the generator */
- Generator = ENG(rand());
-
- /* Combine RNG with distribution */
- Uniform_Distribution = DIST_int(ISI-ISI_range, ISI+ISI_range);
+ Rand_Uniform = random_stream_uniform_int(ISI-ISI_range, ISI+ISI_range);
}
} else {
/* In case of phase dependent stimulation, time_to_stim is the time from minimum detection to start of stimulation */
@@ -246,7 +234,7 @@ void Stim::check_stim (int time) {
}
/* After last stimulus in event update the timer with respect to (random) ISI*/
else {
- time_to_stimuli += (ISI_range==0)? ISI : Uniform_Distribution(Generator);
+ time_to_stimuli += (ISI_range==0)? ISI : Rand_Uniform();
/* Reset the stimulus counter for next stimulation event */
count_stimuli = 1;
View
3 TC.cpp
@@ -30,12 +30,9 @@
/****************************************************************************************************/
/* Main file for compilation tests */
-/* The Simulation requires the following boost libraries: Random */
/****************************************************************************************************/
#include <iostream>
#include <ctime>
-#include "Cortical_Column.h"
-#include "Thalamic_Column.h"
#include "ODE.h"
View
@@ -32,16 +32,13 @@
/* Implementation of the simulation as MATLAB routine (mex compiler) */
/* mex command is given by: */
/* mex CXXFLAGS="\$CXXFLAGS -std=c++11" TC_mex.cpp Cortical_Column.cpp Thalamic_Column.cpp */
-/* The Simulation requires the following boost libraries: Random */
/****************************************************************************************************/
#include <ctime>
#include "mex.h"
#include "matrix.h"
-#include "Cortical_Column.h"
+#include "Data_Storage.h"
#include "ODE.h"
-#include "saves.h"
#include "Stimulation.h"
-#include "Thalamic_Column.h"
mxArray* GetMexArray(int N, int M);
/****************************************************************************************************/
View
@@ -44,8 +44,8 @@ void Thalamic_Column::set_RNG(void) {
/* Create RNG for each stream */
for (int i=0; i<N; ++i){
/* Add the RNG for I_{l} and I_{l,0}*/
- MTRands.push_back({ENG(rand()), DIST (0.0, dphi*dt)});
- MTRands.push_back({ENG(rand()), DIST (0.0, dt)});
+ MTRands.push_back(random_stream_normal(0.0, dphi*dt));
+ MTRands.push_back(random_stream_normal(0.0, dt));
/* Get the random number for the first iteration */
Rand_vars.push_back(MTRands[2*i]());
View
@@ -34,26 +34,12 @@
#pragma once
#include <cmath>
#include <vector>
-#include <boost/random/mersenne_twister.hpp>
-#include <boost/random/normal_distribution.hpp>
-#include <boost/random/variate_generator.hpp>
+#include "Random_Stream.h"
#include "Cortical_Column.h"
using std::vector;
-
class Cortical_Column;
/****************************************************************************************************/
-/* Typedefs for RNG */
-/****************************************************************************************************/
-typedef boost::mt11213b ENG; /* Mersenne Twister */
-typedef boost::normal_distribution<double> DIST; /* Normal Distribution */
-typedef boost::variate_generator<ENG,DIST> GEN; /* Variate generator */
-/****************************************************************************************************/
-/* end */
-/****************************************************************************************************/
-
-
-/****************************************************************************************************/
/* Macro for vector initialization */
/****************************************************************************************************/
#ifndef _INIT
@@ -158,7 +144,7 @@ class Thalamic_Column {
m_h2 = _INIT(0.0); /* activation of h channel bound with protein */
/* Random number generators */
- vector<GEN> MTRands;
+ vector<random_stream_normal> MTRands;
/* Container for noise */
vector<double> Rand_vars;

0 comments on commit 1cba4bc

Please sign in to comment.