diff --git a/Partie2/Src/constant.h b/Partie2/Src/constant.h index b8d491f..6f1903a 100644 --- a/Partie2/Src/constant.h +++ b/Partie2/Src/constant.h @@ -1,9 +1,12 @@ const double Spike_Treshold(0.020); //V const double Tau(0.02); //s const double TauR(0.002); //s (temps de repos après spike) -const double DeltaTime(0.001); //pas de temps +const double DeltaTime(0.0001); //pas de temps const double Resistance(0.020); //Ohm const double Standard_potential(0); //V const int mV(1000); const int ms(1000); -const int bufferSize(10); ///peut-être à adapter +const double toMs(0.001); +const int bufferSize(16); ///peut-être à adapter +const double synaptic_delay(0.0015); +const double J(0.001); //V diff --git a/Partie2/Src/main.cpp b/Partie2/Src/main.cpp index 5f6aa98..5cf5de7 100644 --- a/Partie2/Src/main.cpp +++ b/Partie2/Src/main.cpp @@ -1,143 +1,116 @@ #include #include #include "neurone.hpp" #include "network.hpp" #include "constant.h" #include using namespace std; double AskForTime(); bool SpecialValueForI(); void DemanderBornes(double& borne_inf,double& borne_sup, double temps_f ); double DemanderI(); -void print(ofstream& donnees, double potential, int time); -void printSpikeTimes (ofstream& donnees, std::vector spikeTimes); + int main () { double temps_f(0.0); + unsigned int t(0); + do { temps_f = AskForTime(); } while (temps_f <= 0 ); - - unsigned int NumberOfTimes (0); - NumberOfTimes=(temps_f*0.001)/DeltaTime; ofstream donnees ("donnees.txt", ios::out); donnees << setw(20) << "Membrane Potential : (mV)" ; donnees << setw(20) << "Time : (ms)" << std::endl; donnees << std::endl; bool isvalueForI = SpecialValueForI(); double valueForI(0.0); double borne_inf(0.0); double borne_sup(0.0); if (isvalueForI) { DemanderBornes(borne_inf,borne_sup, temps_f); valueForI = DemanderI(); } - Network network; network.addNeurone(new Neurone); network.addNeurone(new Neurone); - - network.print(donnees, -1); + network.print(donnees,-1); double I(0.0); - for (unsigned int i (0); i < NumberOfTimes ; ++i) { + while (t < (temps_f/DeltaTime)) { - if (i >= borne_inf and i < borne_sup) { + if (t >= (borne_inf/DeltaTime) and t < (borne_sup/DeltaTime)) { I=valueForI; } else { I=0.0; } - network.update(i*DeltaTime,I); - network.print(donnees,i); + network.update(t,I); + network.print(donnees,t); + ++t; } network.printSpikeTimes(donnees); donnees.close(); return 0; } double AskForTime() { double duree (0); std::cout << "Entrez la durée de la simulation (en ms) : " << std::endl; cin >> duree; - return duree; + return duree*toMs; }; bool SpecialValueForI() { - double yes_or_no(0.0); + int yes_or_no(0.0); do { std::cout << "Do you want to enter a value for I ? 1 -> yes , 0 -> no" << std::endl; cin >> yes_or_no; } while (yes_or_no!=0 and yes_or_no!=1); if (yes_or_no == 0) { return false; } return true; } void DemanderBornes(double& borne_inf,double& borne_sup, double temps_f) { do { std::cout << "Entrez les bornes inférieurs puis supérieures des temps pour lesquels cette valeur doit s'appliquer :" << std::endl; cin >> borne_inf >> borne_sup; - } while (borne_inf < 0 or borne_inf >= borne_sup or borne_sup > temps_f); + } while (borne_inf < 0 or borne_inf >= borne_sup or borne_sup > temps_f*ms); + borne_inf*=toMs; + borne_sup*=toMs; } double DemanderI () { double I; std::cout << "Entrez la valeur de I : " << std::endl; cin>> I; return I; } -void print(ofstream& donnees, double potential, int time) { - - donnees << setw(20) << potential*mV; - donnees << setw(20) << (time+1)*DeltaTime*ms << std::endl; - -} - -void printSpikeTimes (ofstream& donnees, std::vector spikeTimes) { - - donnees << std::endl; - - if(spikeTimes.empty()) { - - donnees << "Pas de spike" << std::endl; - - } else { - - for (unsigned int i(0);i #include #include #include "network.hpp" #include "constant.h" Network::Network() {} void Network::addNeurone(Neurone* neurone) { if (neurone != nullptr) { neurones_.push_back(neurone); } } -void Network::update(double time, double Input_current) { - /*if (not neurones_.empty()) { +void Network::update(unsigned int t, double Input_current) { + if (not neurones_.empty()) { for (auto& neu : neurones_) { bool spike(false); - spike=neu->update(Input_current,time); + spike=neu->update(Input_current,t); ///Verify for each neurone if it spikes if (spike) { for (auto& target : neurones_) { if (target!=neu) { - target->receive(time+DeltaTime,Spike_Treshold); //Modifier J ? + target->receive(t*DeltaTime+synaptic_delay); //Modifier J ? } } ///if it spikes, transmit to the neurone connected the information (and the potential) } } - }*/ - bool spike (false); - spike = neurones_[0]->update(Input_current,time); - if (spike) { - neurones_[1]->receive(time+3*DeltaTime,Spike_Treshold-0.001); } - neurones_[1]->update(0,time); } -void Network::print(std::ofstream& donnees, int time) { - for (auto neu : neurones_) { - donnees << std::setw(20) << neu->getMembranePotential()*mV; - donnees << std::setw(20) << (time+1)*DeltaTime*ms << std::endl; - } +void Network::print(std::ofstream& donnees, unsigned int t) { + for (auto neu : neurones_) { + donnees << std::setw(20) << neu->getMembranePotential()*mV; + donnees << std::setw(20) << (t+1)*DeltaTime*ms << std::endl; + } donnees<getSpikeTimes()).empty()) { - - donnees << "Pas de spike" << std::endl; - - } else { - - for (unsigned int j(0);j<(neurones_[i]->getSpikeTimes()).size();++j) { - - donnees << "Spike " << std::setw(5) << i+1; - donnees << std::setw(10) << (neurones_[i]->getSpikeTimes())[j] << std::endl; + donnees << std::endl; + if((neurones_[i]->getSpikeTimes()).empty()) { + donnees << "Pas de spike" << std::endl; + } else { + for (unsigned int j(0);j<(neurones_[i]->getSpikeTimes()).size();++j) { + donnees << "Spike " << std::setw(5) << i+1; + donnees << std::setw(10) << (neurones_[i]->getSpikeTimes())[j]*ms << std::endl; + } } - } - -} } diff --git a/Partie2/Src/network.hpp b/Partie2/Src/network.hpp index c8d53f0..77da40b 100644 --- a/Partie2/Src/network.hpp +++ b/Partie2/Src/network.hpp @@ -1,61 +1,61 @@ #include #include "neurone.hpp" #include #include #ifndef NETWORK_H #define NETWORK_H // Destructeur /*! * @class Network * * @brief represents a neurone network, allow to simulate their life and make them * interact */ class Network { private : /** * The neurones of the network */ std::vector neurones_; public : /** * @brief Network constructor */ Network(); /** * @brief Add a neurone to the network * * @param neurone neurone to add */ void addNeurone(Neurone* neurone); /** * @brief update the network (update each neurone) * * @param time simulation time * @param Input_current -> to be modified */ - void update(double time, double Input_current); + void update(unsigned int t, double Input_current); /** * @brief print the membrane potential values of each neurone * * @param donnes where to write * @param time simulation time */ - void print(std::ofstream& donnees, int time); + void print(std::ofstream& donnees, unsigned int t); void printSpikeTimes(std::ofstream& donnees); }; #endif diff --git a/Partie2/Src/neurone.cpp b/Partie2/Src/neurone.cpp index f13a17d..666ae38 100644 --- a/Partie2/Src/neurone.cpp +++ b/Partie2/Src/neurone.cpp @@ -1,102 +1,101 @@ #include "neurone.hpp" #include "constant.h" #include #include #include Neurone::Neurone() : membrane_potential_(Standard_potential),global_clock_(0.0),clock_rest_time_(0.0) {} //constructeur buffer ??? -bool Neurone::update(double const Input_current, double time_i) { +bool Neurone::update(double const Input_current, unsigned int t) { - bool spike(false); - spike=Spike(time_i); + spike=Spike(t); /// 1) make the neurone spike and set it refractory (if necessary) double new_potential(0.0); if(not isInRest()) { new_potential = exp(-DeltaTime/Tau)*(membrane_potential_); new_potential += Input_current*(Resistance)*(1-exp(-DeltaTime/Tau)); /// 2) calculate the new potential new_potential += outsideInput(); /// 3) add the potential created by other neurones membrane_potential_=new_potential; /// 4) update the membrane potential } else { membrane_potential_=0.0; } buffer_.update(); global_clock_+=DeltaTime; /// 5) increase the time return spike; } double Neurone::getMembranePotential () const { return membrane_potential_-0.070; /// -0.070 because we use a 0 origin for the membrane potential } bool Neurone::isInRest() { if (not (clock_rest_time_ <= 0.0)) { clock_rest_time_-=DeltaTime; /// retires an unit of time return true; } return false; } -bool Neurone::Spike(double time_i) { +bool Neurone::Spike(unsigned int t) { bool spike(false); if(membrane_potential_ >= Spike_Treshold) { - spikes_times_.push_back(time_i); + spikes_times_.push_back(t*DeltaTime); /// stores the spike time membrane_potential_=Standard_potential; /// reinitialize the membrane potential clock_rest_time_=TauR; /// set the rest time spike=true; }; return spike; } std::vector Neurone::getSpikeTimes() const { return spikes_times_; } -void Neurone::receive(double D,double J) { +void Neurone::receive(double D) { buffer_.addValue(D,J); } /*double Neurone::otherNeurone() { if (fabs(global_clock_-receive_clock_) <= std::numeric_limits::epsilon()) { ///To compare two double values receive_clock_=0.0; return J_; } return 0.0; }*/ double Neurone::outsideInput() const { double input(buffer_.valueFor()); return input; } diff --git a/Partie2/Src/neurone.hpp b/Partie2/Src/neurone.hpp index 7a17c91..bcb5b91 100644 --- a/Partie2/Src/neurone.hpp +++ b/Partie2/Src/neurone.hpp @@ -1,103 +1,103 @@ #include #include #include "ringbuffer.hpp" #ifndef NEURONE_H #define NEURONE_H /*! * @class Neurone * * @brief represents a neurone and allows to simulate its life */ class Neurone { private : /** * Represents the neurone's membrane potential */ double membrane_potential_; /** * Used to store the spike times */ std::vector spikes_times_; /** * Manage the global time */ double global_clock_; /** * Manage the rest time */ double clock_rest_time_; RingBuffer buffer_; /*/** * Provisoire double receive_clock_; double J_;*/ public : /** * @brief Neurone constructor (the initiation constants are in constant.h) */ Neurone(); /** * @brief update the neurone (change the membrane potential, make it * spike if the treshold is reached and manage rest time) * * @param Input_current the current coming inside the neurone * @param time_i time of the simulation */ - bool update (double const Input_current, double time_i); + bool update (double const Input_current, unsigned int t); /** * @brief return the membrane potential */ double getMembranePotential () const ; /** * @brief Test if the treshold is reached, if it is, make the neurone spike * and reinitialize the membrane potential. Store the spike's time * * @param time_i used to store the spike's time */ - bool Spike(double time_i); + bool Spike(unsigned int t); /** * @brief Test if the neuron is in rest. If it is, subtract an unit of time * to the rest time */ bool isInRest(); /** * @brief Return all the spike times */ std::vector getSpikeTimes() const; /** * provisoire */ - void receive(double D, double J); + void receive(double D); /** * @brief Return the outside input */ double outsideInput() const; /*/** * @brief Return the potential created by the other neurons double otherNeurone(); */ }; #endif