Skip to content
Snippets Groups Projects
Commit d4b76875 authored by Benjamin Cumming's avatar Benjamin Cumming
Browse files

work on spike source <remove>

parent 3553ac8b
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ namespace mc {
class spike_source {
public:
virtual std::vector<float> test(float t) = 0;
virtual util::optional<float> test(float t) = 0;
};
// spike detector for a lowered cell
......@@ -36,15 +36,15 @@ class spike_detector : public spike_source
is_spiking_ = previous_v_ >= thresh ? true : false;
}
std::vector<float> test(float t) override {
std::vector<float> spike_times;
util::optional<float> test(float t) override {
util::optional<float> result = util::nothing;
auto v = cell_->voltage(location_);
if (!is_spiking_) {
if (v>=threshold_) {
// the threshold has been passed, so estimate the time using
// linear interpolation
auto pos = (threshold_ - previous_v_)/(v - previous_v_);
spike_times.push_back(previous_t_ + pos*(t - previous_t_));
result = previous_t_ + pos*(t - previous_t_);
is_spiking_ = true;
}
......@@ -58,7 +58,7 @@ class spike_detector : public spike_source
previous_v_ = v;
previous_t_ = t;
return spike_times;
return result;
}
bool is_spiking() const {
......@@ -88,21 +88,25 @@ class poisson_generator : public spike_source
public:
poisson_generator(float r)
: firing_rate_(r)
: dist_(0.0f, 1.0f),
firing_rate_(r)
{}
util::optional<float> test(float t) {
// generate a uniformly distrubuted random number x \in [0,1]
// if (x > r*dt) we have a spike in the interval
std::vector<float> spike_times;
if(rand() > firing_rate_*(t-previous_t_)) {
if(dist_(generator_) > firing_rate_*(t-previous_t_)) {
return t;
}
return util::optional<float>::nothing;
return util::nothing;
}
private:
std::mt19937 generator_; // for now default initialized
std::uniform_real_distribution<float> dist_;
// firing rate in spikes/ms
float firing_rate_;
float previous_t_;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment