<jupyter_start><jupyter_text>Simulating an EPSP EPSP (Excitatory Post Synaptic Potential) is the variation in membrane potential in a receiving neuron initiated by a spike from the sending neuron. Read more about [EPSP](https://en.wikipedia.org/wiki/Excitatory_postsynaptic_potential)**This notebook:**1. Will simulate an EPSP process( not entirely, but as a crude approximation)  Import librariesRun the following cell to import the required libraries for this project. In case you receive a  **ModuleNotFoundError** , you will first have to install them to your system.<jupyter_code>#numpy -  mainly for math operations.
#matploltib  - for plotting
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Initialize data and constantsThe data and constants here are just arbitrary and in no way represent real world values<jupyter_code>#specify constants
'''
c_m = membrane capacitance
g_L = conducatance of leak channels
tau_syn = the time constant which sets the time scale of the opening/closing of the synaptic ion channels 
E_syn = reversal potential of synaptic ion channels
delta_t = infinitesimal change in time.
'''
c_m=1
g_L=1
tau_syn=1
E_syn=10
delta_t = 0.01

# initializing our data arrays.
'''
t = time 
g_syn = conductance of synaptic ion channels 
I_syn = current from synaptic ion channels
v_m = membrane voltage.
'''
t = np.arange(0, 10, delta_t, dtype= "float16")
g_syn=np.zeros((t.shape), dtype = "float16")
I_syn=np.zeros((t.shape), dtype = "float16")
v_m=np.zeros((t.shape), dtype = "float16")<jupyter_output><empty_output><jupyter_text>Calculate variables for each instant of timedependent variables : `g_syn` , `I_syn`, `v_m`**Equations:** (All equations are in numerical method form)1. `g_syn`$$ g_{syn(i)} = g_{syn(i-1)} - (\frac{\nabla t * g_{syn(i-1)}}{\tau _{syn}}) $$2. `I_syn` $$I_{syn(i)} = g_{syn(i)}\times (v_{m(i-1)} - E_{syn})$$3. `v_m` $$ v_{m(i)} = v_{m(i-1)} - \frac{\nabla t \times (g_{L} \times v_{m(i - 1)})}{c_{m}} - \frac{\nabla t \times I_{syn(i)}}{c_{m}} $$<jupyter_code>#run through time to get values for each parameter.
for i, val in enumerate(t):
    #before the spike
    if(val < 2.0):
        g_syn[i] = 0
        I_syn[i] = 0
        v_m[i] = 0
    #hardcoding the  spike
    elif(val == 2.0):
        g_syn[i] = 1
    # the exponential decay post spike
    else:
        g_syn[i] = g_syn[i-1] - (delta_t * g_syn[i-1])/tau_syn
        I_syn[i] = g_syn[i] * (v_m[i-1] - E_syn)
        v_m[i] = v_m[i-1] - (delta_t * g_L * v_m[i-1])/c_m - (delta_t * I_syn[i])/c_m<jupyter_output><empty_output><jupyter_text>Plot the graph<jupyter_code># plotting the graph
%matplotlib inline

plt.plot(t, g_syn*5, "--r", label="g_sync")
plt.plot(t, I_syn/5, ":k", label= "I_sync")
plt.plot(t, v_m, "b", label= "v_m")

plt.legend()

plt.title("Time course of variables")
plt.xlabel("time(s)")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14191988950276244, 'fraction_numerical': 0.014848066298342542, 'mean_word_length': 4.497153700189753, 'pattern_counts': {'":': 1, '<': 18, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '539351', 'license': 'MIT', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1053, 'n_words': 309, 'path': 'Chapter02/EPSP.ipynb', 'repo_name': 'jayanthvarma134/Computational-neuroscience', 'size': '2896'}