Spike
Loading...
Searching...
No Matches
IF.h
Go to the documentation of this file.
1
6#ifndef SPIKE_IF_H
7#define SPIKE_IF_H
8
9#include <cassert>
10#include <cmath>
11#include <ostream>
12#include <random>
13#include <vector>
14
15#include "Spike/Neuron/Neuron.h"
17#include "Spike/Signal/Signal.h"
18#include "Spike/SpikeTrain/SpikeTrain.h"
19#include "Spike/TimeFrame/TimeFrame.h"
20
21namespace Spike {
22
26class IF : public Neuron {
27protected:
28 double mu;
29 double D;
30 std::random_device rd;
31 std::mt19937 generator;
32 std::normal_distribution<double> dist;
33
34public:
39 explicit IF(const std::string &input_file);
40
46 IF(double mu, double D);
47
53 [[nodiscard]] virtual double drift(double v) const = 0;
54
59 [[nodiscard]] double diffusion() const;
60
66 void get_spikes(SpikeTrain &spike_train) override;
67
74 void get_spikes(Signal &signal, SpikeTrain &spike_train) override;
75
81 void get_voltage_curve(const TimeFrame &time, std::vector<double> &v);
82
87 void set_mu(double mu_new) { this->mu = mu_new; };
88
93 void set_D(double D_new) { this->D = D_new; };
94
99 [[nodiscard]] double get_D() const { return D; };
100
105 virtual void print(std::ostream &out) const = 0;
106
113 friend std::ostream &operator<<(std::ostream &out, const IF &neuron);
114};
115
120class PIF : public IF {
121public:
127 PIF(double mu, double D);
128
133 explicit PIF(const std::string &input_file);
134
140 [[nodiscard]] double drift(double v) const override;
141
146 void print(std::ostream &out) const override {
147 out << "PIF(mu: " << mu << ", D: " << D << ")";
148 }
149};
150
154class LIF : public IF {
155public:
161 LIF(double mu, double D);
162
167 explicit LIF(const std::string &input_file);
168
174 [[nodiscard]] double drift(double v) const override;
175
180 void print(std::ostream &out) const override {
181 out << "LIF(mu: " << mu << ", D: " << D << ")";
182 }
183};
184
185} // namespace Spike
186
187#endif // SPIKE_IF_H
Abstract base class for integrate-and-fire (IF) neurons.
Definition IF.h:26
void set_mu(double mu_new)
Set new mean input current.
Definition IF.h:87
double diffusion() const
Calculates the diffusion of the IF neurons, i.e. sqrt(2D).
Definition IF.cpp:30
IF(const std::string &input_file)
Constructs an IF neuron from a .ini file.
Definition IF.cpp:18
double D
diffusion coefficient
Definition IF.h:29
virtual void print(std::ostream &out) const =0
Prints the IF neuron to the outstream.
std::random_device rd
random device (seeding)
Definition IF.h:30
double mu
mean input current
Definition IF.h:28
void get_voltage_curve(const TimeFrame &time, std::vector< double > &v)
Calculates the trajectory, i.e. v(t) for a given time frame.
Definition IF.cpp:73
double get_D() const
Returns the diffusion coefficient.
Definition IF.h:99
virtual double drift(double v) const =0
Calculates the drift of the IF neuron.
std::mt19937 generator
random number generator
Definition IF.h:31
void set_D(double D_new)
Set new diffusion coefficient.
Definition IF.h:93
void get_spikes(SpikeTrain &spike_train) override
Obtains spikes by integrating the Langevin equation using an Euler-Maruyama scheme.
Definition IF.cpp:32
friend std::ostream & operator<<(std::ostream &out, const IF &neuron)
Overloads the << operator, so we can print the neuron.
Definition IF.cpp:92
std::normal_distribution< double > dist
normal distribution
Definition IF.h:32
A leaky integrate-and-fire (LIF) neuron.
Definition IF.h:154
double drift(double v) const override
Calculates drift of the LIF, i.e. mu - v.
Definition IF.cpp:123
LIF(double mu, double D)
Constructs an LIF from given parameters.
Definition IF.cpp:111
void print(std::ostream &out) const override
Prints the LIF neuron to out stream.
Definition IF.h:180
Abstract base class for Neurons.
Definition Neuron.h:18
Implements a perfect integrate-and-fire (PIF) neuron.
Definition IF.h:120
PIF(double mu, double D)
Construct PIF from parameters.
Definition IF.cpp:97
double drift(double v) const override
Returns drift of the PIF neuron, i.e. mu.
Definition IF.cpp:109
void print(std::ostream &out) const override
Prints the PIF neuron to out stream.
Definition IF.h:146
An abstract base class for signals.
Definition Signal.h:20
A spike train for discretized times. For a given time discretization with time step dt,...
Definition SpikeTrain.h:18
A time frame with discrete time steps.
Definition TimeFrame.h:13