diff --git a/.DS_Store b/.DS_Store index 3c2568a..c757271 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/HH.ipynb b/HH.ipynb index 507fe54..ccfffdc 100644 --- a/HH.ipynb +++ b/HH.ipynb @@ -371,10 +371,11 @@ "metadata": {}, "source": [ "```{pyodide-python}\n", - "plt.show()\n", + "plt.figure()\n", "plt.plot(t,V,'k') #Plot the voltage,\n", "plt.xlim([42, 56]) #... focused on a single spike,\n", - "plt.ylabel('V [mV]'); #... with y-axis labeled.\n", + "plt.ylabel('V [mV]') #... with y-axis labeled.\n", + "plt.show()\n", "```" ] }, @@ -391,12 +392,11 @@ "source": [ "```{pyodide-python}\n", "gNa0 = 120\n", - "gNa = gNa0*m**3*h Sodium conductance\n", + "# gNa = ??? #Sodium conductance\n", "gK0 = 36\n", - "gK = gK0*n**4 Potassium conductance\n", + "# gK = ??? #Potassium conductance\n", "gL0 = 0.3\n", - "gL = gL0*np.ones(np.shape(gK)) Leak conductance\n", - "plt.show()\n", + "# gL = ??? #Leak conductance\n", "```" ] }, @@ -421,13 +421,14 @@ "metadata": {}, "source": [ "```{pyodide-python}\n", + "plt.figure()\n", "plt.plot(t,gNa,'m', label='gNa')#... and plot the sodium conductance,\n", "plt.plot(t,gK, 'g', label='gK') #... and plot the potassium conductance,\n", "plt.plot(t,gL, 'k', label='gL') #... and plot the leak conductance.\n", "plt.xlim([42, 56]) #... focused on a single spike,\n", "plt.xlabel('Time [ms]') #... label the x-axis.\n", "plt.ylabel('mS/cm^2') #... and label the y-axis.\n", - "plt.legend(); #... make a legend.\n", + "plt.legend() #... make a legend.\n", "plt.show()\n", "```" ] @@ -531,11 +532,10 @@ "source": [ "# Challenges\n", "\n", - "1. Explain each line of the Python code that simulates the HH model.\n", - "2. Describe the dynamics of the gates and ions during an action potential in the HH model.\n", + "1. Describe the dynamics during an action potential in the HH model. How does the voltage change? How do the gates open and close? How do the ions flow?\n", "5. Determine how the firing rate of the HH model varies with input current I. Plot the firing rate versus I (i.e., plot the “f-I curve”).\n", - "6. How do the dynamics change as you increases / decrease the potassium conductance?\n", - "7. How do the dynamics change as you increases / decrease the sodium conductance?" + "6. How does the firing rate of the HH model change as you increase the potassium conductance? Provide a \"simulation\" explanation and a \"physical\" explanation.\n", + "7. How does the firing rate of the HH model change as you increase sodium conductance? Provide a \"simulation\" explanation and a \"physical\" explanation." ] } ], diff --git a/Slides/HH_Lecture_1.pdf b/Slides/HH_Lecture_1.pdf new file mode 100644 index 0000000..e493f3c Binary files /dev/null and b/Slides/HH_Lecture_1.pdf differ diff --git a/docs/HH.html b/docs/HH.html index bb2eac7..f79252d 100644 --- a/docs/HH.html +++ b/docs/HH.html @@ -228,7 +228,7 @@ } // Store cell data -globalThis.qpyodideCellDetails = [{"id":1,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"import numpy as np\nimport matplotlib.pyplot as plt"},{"id":2,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"import requests\nurl = \"https://raw.githubusercontent.com/Mark-Kramer/BU-MA665-MA666/master/HH_functions.py\"\nresponse = requests.get(url)\nexec(response.text)"},{"id":3,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"I0 = 0"},{"id":4,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"T0 = 100"},{"id":5,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"[V,m,h,n,t]=HH(I0,T0)"},{"id":6,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"I0 = 10"},{"id":7,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"[V,m,h,n,t] = HH(I0,T0)"},{"id":8,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"plt.figure()\nplt.plot(t,V,'k')\nplt.xlim([42, 56])\nplt.ylabel('V [mV]')\nplt.show()"},{"id":9,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"plt.figure()\nplt.plot(t,m,'r', label='m')\nplt.xlim([42, 56]);\nplt.show()"},{"id":10,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"plt.figure()\nplt.plot(t,m,'r', label='m')\nplt.plot(t,h,'b', label='h')\nplt.plot(t,n,'g', label='n')\nplt.xlim([42, 56])\nplt.xlabel('Time [ms]');\nplt.legend();\nplt.show()"},{"id":11,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"plt.figure()\nax1 = plt.subplot(211); # Define axis for 1st subplot,\nax2 = plt.subplot(212, sharex=ax1); # ... and link axis of 2nd subplot to the 1st.\nax1.plot(t,V,'k') # Plot the voltage in the first subplot,\nplt.xlim([42, 56]);\nax2.plot(t,m,'r', label='m') # ... and the gating variables in the other subplot.\nax2.plot(t,h,'b', label='h')\nax2.plot(t,n,'g', label='n')\nplt.xlabel('Time [ms]')\nplt.legend()\nplt.show()"},{"id":12,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"plt.show()\nplt.plot(t,V,'k') #Plot the voltage,\nplt.xlim([42, 56]) #... focused on a single spike,\nplt.ylabel('V [mV]'); #... with y-axis labeled."},{"id":13,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"gNa0 = 120\ngNa = gNa0*m**3*h Sodium conductance\ngK0 = 36\ngK = gK0*n**4 Potassium conductance\ngL0 = 0.3\ngL = gL0*np.ones(np.shape(gK)) Leak conductance\nplt.show()"},{"id":14,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"plt.plot(t,gNa,'m', label='gNa')#... and plot the sodium conductance,\nplt.plot(t,gK, 'g', label='gK') #... and plot the potassium conductance,\nplt.plot(t,gL, 'k', label='gL') #... and plot the leak conductance.\nplt.xlim([42, 56]) #... focused on a single spike,\nplt.xlabel('Time [ms]') #... label the x-axis.\nplt.ylabel('mS/cm^2') #... and label the y-axis.\nplt.legend(); #... make a legend.\nplt.show()"},{"id":15,"options":{"fig-cap":"","read-only":"false","label":"","results":"markup","warning":"true","out-width":"700px","autorun":"","output":"true","context":"interactive","comment":"","out-height":"","dpi":72,"message":"true","fig-width":7,"classes":"","fig-height":5},"code":"gNa0 = 120\nENa = 115\n# INa = ??? Sodium current.\ngK0 = 36\nEK =-12\n# IK = ??? Potassium current.\ngL0 = 0.3\nEL = 10.6;\n# IL = ??? Leak current.\n\nplt.figure()\nplt.plot(t,INa,'m', label='INa') #... and plot the sodium current,\nplt.plot(t,IK, 'g', label='IK') #... and plot the potassium current,\nplt.plot(t,IL, 'k', label='IL') #... and plot the leak current.\nplt.xlim([42, 56]) #... focus on a single spike,\nplt.xlabel('Time [ms]') #... label the x-axis.\nplt.ylabel('mA/cm^2') #... and label the y-axis.\nplt.legend() #... make a legend.\nplt.show()"}]; +globalThis.qpyodideCellDetails = [{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"import numpy as np\nimport matplotlib.pyplot as plt","id":1},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"import requests\nurl = \"https://raw.githubusercontent.com/Mark-Kramer/BU-MA665-MA666/master/HH_functions.py\"\nresponse = requests.get(url)\nexec(response.text)","id":2},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"I0 = 0","id":3},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"T0 = 100","id":4},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"[V,m,h,n,t]=HH(I0,T0)","id":5},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"I0 = 10","id":6},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"[V,m,h,n,t] = HH(I0,T0)","id":7},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"plt.figure()\nplt.plot(t,V,'k')\nplt.xlim([42, 56])\nplt.ylabel('V [mV]')\nplt.show()","id":8},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"plt.figure()\nplt.plot(t,m,'r', label='m')\nplt.xlim([42, 56]);\nplt.show()","id":9},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"plt.figure()\nplt.plot(t,m,'r', label='m')\nplt.plot(t,h,'b', label='h')\nplt.plot(t,n,'g', label='n')\nplt.xlim([42, 56])\nplt.xlabel('Time [ms]');\nplt.legend();\nplt.show()","id":10},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"plt.figure()\nax1 = plt.subplot(211); # Define axis for 1st subplot,\nax2 = plt.subplot(212, sharex=ax1); # ... and link axis of 2nd subplot to the 1st.\nax1.plot(t,V,'k') # Plot the voltage in the first subplot,\nplt.xlim([42, 56]);\nax2.plot(t,m,'r', label='m') # ... and the gating variables in the other subplot.\nax2.plot(t,h,'b', label='h')\nax2.plot(t,n,'g', label='n')\nplt.xlabel('Time [ms]')\nplt.legend()\nplt.show()","id":11},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"plt.figure()\nplt.plot(t,V,'k') #Plot the voltage,\nplt.xlim([42, 56]) #... focused on a single spike,\nplt.ylabel('V [mV]') #... with y-axis labeled.\nplt.show()","id":12},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"gNa0 = 120\n# gNa = ??? #Sodium conductance\ngK0 = 36\n# gK = ??? #Potassium conductance\ngL0 = 0.3\n# gL = ??? #Leak conductance","id":13},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"plt.figure()\nplt.plot(t,gNa,'m', label='gNa')#... and plot the sodium conductance,\nplt.plot(t,gK, 'g', label='gK') #... and plot the potassium conductance,\nplt.plot(t,gL, 'k', label='gL') #... and plot the leak conductance.\nplt.xlim([42, 56]) #... focused on a single spike,\nplt.xlabel('Time [ms]') #... label the x-axis.\nplt.ylabel('mS/cm^2') #... and label the y-axis.\nplt.legend() #... make a legend.\nplt.show()","id":14},{"options":{"warning":"true","output":"true","fig-height":5,"context":"interactive","results":"markup","message":"true","fig-cap":"","out-height":"","label":"","out-width":"700px","autorun":"","classes":"","fig-width":7,"read-only":"false","dpi":72,"comment":""},"code":"gNa0 = 120\nENa = 115\n# INa = ??? Sodium current.\ngK0 = 36\nEK =-12\n# IK = ??? Potassium current.\ngL0 = 0.3\nEL = 10.6;\n# IL = ??? Leak current.\n\nplt.figure()\nplt.plot(t,INa,'m', label='INa') #... and plot the sodium current,\nplt.plot(t,IK, 'g', label='IK') #... and plot the potassium current,\nplt.plot(t,IL, 'k', label='IL') #... and plot the leak current.\nplt.xlim([42, 56]) #... focus on a single spike,\nplt.xlabel('Time [ms]') #... label the x-axis.\nplt.ylabel('mA/cm^2') #... and label the y-axis.\nplt.legend() #... make a legend.\nplt.show()","id":15}]; @@ -740,11 +740,10 @@

6 Discussion

7 Challenges

    -
  1. Explain each line of the Python code that simulates the HH model.
  2. -
  3. Describe the dynamics of the gates and ions during an action potential in the HH model.
  4. +
  5. Describe the dynamics during an action potential in the HH model. How does the voltage change? How do the gates open and close? How do the ions flow?
  6. Determine how the firing rate of the HH model varies with input current I. Plot the firing rate versus I (i.e., plot the “f-I curve”).
  7. -
  8. How do the dynamics change as you increases / decrease the potassium conductance?
  9. -
  10. How do the dynamics change as you increases / decrease the sodium conductance?
  11. +
  12. How does the firing rate of the HH model change as you increase the potassium conductance? Provide a “simulation” explanation and a “physical” explanation.
  13. +
  14. How does the firing rate of the HH model change as you increase sodium conductance? Provide a “simulation” explanation and a “physical” explanation.
diff --git a/docs/IF.html b/docs/IF.html index 55327d6..4a12228 100644 --- a/docs/IF.html +++ b/docs/IF.html @@ -228,7 +228,7 @@ } // Store cell data -globalThis.qpyodideCellDetails = [{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":1,"code":"import numpy as np\nimport matplotlib.pyplot as plt"},{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":2,"code":"C=1.0\nI=1.0"},{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":3,"code":"dt=0.01"},{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":4,"code":"V = np.zeros([1000,1])\nnp.shape(V)"},{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":5,"code":"V[0]=0.2"},{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":6,"code":"for k in range(1,999):\n V[k+1] = V[k] + dt*(I/C)"},{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":7,"code":"plt.figure()\nplt.plot(V)\nplt.show()"},{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":8,"code":"t = np.arange(0,len(V))*dt"},{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":9,"code":"plt.figure()\nplt.plot(t,V)\nplt.xlabel('Time [s]')\nplt.ylabel('V')\nplt.show()"},{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":10,"code":"import numpy as np\nimport matplotlib.pyplot as plt\n\nI = 1 #Set the parameter I.\nC = 1 #Set the parameter C.\ndt = 0.01 #Set the timestep.\nV = np.zeros([1000,1]) #Initialize V.\nV[0]= 0.2; #Set the initial value of V.\n\nfor k in range(1,999): #March forward in time,\n V[k+1] = V[k] + dt*(I/C) #... updating V along the way.\n\nt = np.arange(0,len(V))*dt #Define the time axis.\n\nplt.figure()\nplt.plot(t,V) #Plot the results.\nplt.xlabel('Time [s]')\nplt.ylabel('Voltage [mV]')\nplt.show()"},{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":11,"code":"Vth = 1; #Define the voltage threshold.\nVreset = 0; #Define the reset voltage.\n\nfor k in range(1,999): #March forward in time,\n V[k+1] = V[k] + dt*(I/C) #Update the voltage,\n ### ADD SOMETHING HERE??? --------------------------"},{"options":{"dpi":72,"label":"","fig-width":7,"out-height":"","context":"interactive","fig-height":5,"out-width":"700px","fig-cap":"","classes":"","results":"markup","message":"true","comment":"","autorun":"","read-only":"false","output":"true","warning":"true"},"id":12,"code":"### ADD YOUR CODE!"}]; +globalThis.qpyodideCellDetails = [{"code":"import numpy as np\nimport matplotlib.pyplot as plt","id":1,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}},{"code":"C=1.0\nI=1.0","id":2,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}},{"code":"dt=0.01","id":3,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}},{"code":"V = np.zeros([1000,1])\nnp.shape(V)","id":4,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}},{"code":"V[0]=0.2","id":5,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}},{"code":"for k in range(1,999):\n V[k+1] = V[k] + dt*(I/C)","id":6,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}},{"code":"plt.figure()\nplt.plot(V)\nplt.show()","id":7,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}},{"code":"t = np.arange(0,len(V))*dt","id":8,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}},{"code":"plt.figure()\nplt.plot(t,V)\nplt.xlabel('Time [s]')\nplt.ylabel('V')\nplt.show()","id":9,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}},{"code":"import numpy as np\nimport matplotlib.pyplot as plt\n\nI = 1 #Set the parameter I.\nC = 1 #Set the parameter C.\ndt = 0.01 #Set the timestep.\nV = np.zeros([1000,1]) #Initialize V.\nV[0]= 0.2; #Set the initial value of V.\n\nfor k in range(1,999): #March forward in time,\n V[k+1] = V[k] + dt*(I/C) #... updating V along the way.\n\nt = np.arange(0,len(V))*dt #Define the time axis.\n\nplt.figure()\nplt.plot(t,V) #Plot the results.\nplt.xlabel('Time [s]')\nplt.ylabel('Voltage [mV]')\nplt.show()","id":10,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}},{"code":"Vth = 1; #Define the voltage threshold.\nVreset = 0; #Define the reset voltage.\n\nfor k in range(1,999): #March forward in time,\n V[k+1] = V[k] + dt*(I/C) #Update the voltage,\n ### ADD SOMETHING HERE??? --------------------------","id":11,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}},{"code":"### ADD YOUR CODE!","id":12,"options":{"comment":"","context":"interactive","classes":"","results":"markup","fig-width":7,"message":"true","read-only":"false","label":"","warning":"true","fig-height":5,"dpi":72,"output":"true","out-height":"","autorun":"","fig-cap":"","out-width":"700px"}}]; diff --git a/docs/Introduction.html b/docs/Introduction.html index 9d81f51..6a50815 100644 --- a/docs/Introduction.html +++ b/docs/Introduction.html @@ -262,7 +262,7 @@ } // Store cell data -globalThis.qpyodideCellDetails = [{"id":1,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd\n\ndf = pd.read_csv(\"https://raw.githubusercontent.com/Mark-Kramer/BU-MA665-MA666/master/Data/Rhythms_1.csv\")\nd = np.array(df.iloc[:,0])\nt = np.array(df.iloc[:,1])\n\n# Print useful information about the data.\nprint(\"Sampling frequency is \" + str( 1/(t[2]-t[1])) + ' Hz.')\nprint(\"Total duration of recording is \" + str(t[-1]) + ' s.')\nprint(\"Dimensions of data are \" + str(np.shape(d)) + ' data points.')\n\n# Choose an initial interval of time, from onset to 5 s,\ninitial_time_interval = t < 5 \n\n# ... and plot it.\nplt.plot(t[initial_time_interval], d[initial_time_interval])\nplt.xlabel('Time [s]')\nplt.ylabel('Data')\nplt.title('Initial interval of data');\nplt.show()"},{"id":2,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"4+9"},{"id":3,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"4/3"},{"id":4,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"4/10**2"},{"id":5,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport math"},{"id":6,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"np.sin(2*np.pi)"},{"id":7,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"math.atan(2*np.pi)"},{"id":8,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\na = np.array([[1, 2, 3, 4]])\nprint(a)"},{"id":9,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"a = np.array( [[1, 2, 3, 4]] )\nprint( a * 3 )\nprint( 4 * a )\nprint( a + 1 )"},{"id":10,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\na = np.array([1,2,3,4])\na * a"},{"id":11,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\na = 2\nb = np.array( [[0, 4, 7, 6]] )\nc = np.array( [[1, 5, 6, 8]] )\n\nprint( b * c )\nprint( b / c + a)\nprint( np.multiply( b, c ))"},{"id":12,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"a = np.array([[1,2,3,4]])\nprint(a.shape)\nprint(np.shape(a))"},{"id":13,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\n\np = np.array( [[1,2,3],[4,5,6]] )"},{"id":14,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"print( p )"},{"id":15,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"print( p + 2 )\nprint( 2 * p )\nprint( p * p )"},{"id":16,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\na = np.array( [1, 2, 3, 4, 5] )\nb = np.array( [6, 7, 8, 9, 10] )"},{"id":17,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"print( \"a[1] = \" + str(a[1]) )\nprint( \"b[1] = \" + str(b[1]) )"},{"id":18,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"c = np.array([a,b])\nprint( \"c = \\n\" + str(c) ) # \\n is a newline, or carriage return, which makes the printed matrix lineup better "},{"id":19,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"print( \"shape of c = \" + str( np.shape(c) ) )"},{"id":20,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"print( \"c[0,3] = \" + str( c[0,3] ) )"},{"id":21,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"print( \"c[0,:] = \" + str( c[0,:] ) )\nprint( \"2nd through 4th columns of the first row are c[0,1:4] = \" + str(c[0,1:4]) )"},{"id":22,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"print(\"c[0, :4] = \" + str( c[0,:4]))\nprint(\"c[0, 1:] = \" + str( c[0,1:]))"},{"id":23,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"c[0,::2]"},{"id":24,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"a = np.arange(1,10) # this creates a vector of increasing values from 1 to 9\na = 2*a \n\nprint( \"a = \" + str(a) )"},{"id":25,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"a[a > 10]"},{"id":26,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"lgIdx = a > 10\nlgIdx"},{"id":27,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"a[lgIdx]"},{"id":28,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"lgIdx.nonzero()"},{"id":29,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"a[ (a > 10).nonzero() ]"},{"id":30,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"print(\"a = \" + str(a))\na[a > 10] = 100\nprint(\"a = \" + str(a))"},{"id":31,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"b = np.array([[1,2,3],[4,5,6],[7,8,9]])\nprint( \"b = \\n\" + str(b) )\nprint( \" b > 5 is \\n\" + str(b > 5) )\nprint(\" b[b>5] is an array: \" + str(b[b>5]) )"},{"id":32,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\n\nx = np.linspace(0,10,11) \nprint( \"x = \" + str(x) )\n\n# The above line constructs a vector that starts at 0, ends at 10, and\n# has 11 entries (takes steps of size 1 from 0 to 10). Let\n\ny = np.sin(x)\nprint( \"y = \" + str(y) )"},{"id":33,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import matplotlib.pyplot as plt\nx = ([1, 2, 3, 4])\ny = x\nplt.figure()\nplt.plot(x,y) \nplt.show() # this is the plotting equivalent of print()"},{"id":34,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"x = np.linspace(0,10,11) \ny = np.sin(x)\n\nplt.figure()\nplt.plot(x, y)\nplt.show()"},{"id":35,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\nx = np.linspace(0,10, 101)\nprint(x)"},{"id":36,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"y = np.sin(x)\nplt.figure()\nplt.plot(x,y,'k') # the 'k' we've added makes the curve black instead of blue\nplt.show()"},{"id":37,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\nx = np.linspace(0,10, 101)\nz = np.cos(x)"},{"id":38,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import matplotlib.pyplot as plt\nplt.figure()\nplt.plot(x,z)\nplt.show()"},{"id":39,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"y = np.sin(x)\nplt.figure()\nplt.plot(x,z) # plot z vs x.\nplt.plot(x,y,'r') # plot y vs x in red\nplt.show()"},{"id":40,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"plt.figure()\nplt.plot(x,z) # plot z vs x\nplt.plot(x,y,'r') # plot y vs x in red\nplt.xlabel('x') # x-axis label\nplt.ylabel('y or z') # y-axis label\nplt.title('y vs x and z vs x') # title\nplt.legend(('y','z')) # make a legend labeling each line\nplt.show()"},{"id":41,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"plt.figure()\nplt.plot(x,y, label='y') # sometimes it is easier to name a trace within the plot() call\nplt.plot(x,z, label='z') # notice without a color matplotlib will assign one\nplt.xlabel('x', fontsize=14)\nplt.ylabel('y', fontsize=14)\nplt.title('y vs x', fontsize=18)\nplt.legend(fontsize=12)\nplt.show()"},{"id":42,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\n\nprint(\"a Gaussian random number (mean=0, variance=1): \" + str( np.random.randn() ))\n\n# a uniform random number on [0,1)\nprint(\"a uniform random number from [0,1): \" + str(np.random.rand()))"},{"id":43,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"r = np.random.randn(1000)"},{"id":44,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import matplotlib.pyplot as plt\nplt.figure()\nplt.hist(r)\nplt.show()"},{"id":45,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\nimport matplotlib.pyplot as plt\n\nx = np.arange(0,10,0.1) # Define a vector x that ranges from 0 to 9.9 with step 0.1.\nk = 1 # Fix k=1,\ny = np.sin(x + k*np.pi/4) # ... and define y at this k.\n\nplt.figure() # Make a new figure,\nplt.plot(x,y) # ... and plot y versus x.\n\nk = 2 # Let's repeat this, for k=2,\ny = np.sin(x + k*np.pi/4) # ... and redefine y at this k,\nplt.plot(x,y) # ... and plot it.\n\nk = 3 # Let's repeat this, for k=3,\ny = np.sin(x + k*np.pi/4) # ... and redefine y at this k,\nplt.plot(x,y) # ... and plot it.\n\nk = 4 # Let's repeat this, for k=4,\ny = np.sin(x + k*np.pi/4) # ... and redefine y at this k,\nplt.plot(x,y) # ... and plot it.\n\nk = 5 # Let's repeat this, for k=5,\ny = np.sin(x + k*np.pi/4) # ... and redefine y at this k,\nplt.plot(x,y) # ... and plot it.\n\nplt.show()"},{"id":46,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"x = np.arange(0,10,0.1) #First, define the vector x."},{"id":47,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"plt.figure()\nfor k in range(1,6): \n y = np.sin(x + k*np.pi/4) #Define y (note the variable 'k' in sin), also note we have indented here!\n plt.plot(x,y) #Plot y versus x\n \n# no indentation now, so this code follows the loop\nplt.show()"},{"id":48,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"def my_square_function(x, c):\n \"\"\"Square a vector and add a constant.\n\n Arguments:\n x -- vector to square\n c -- constant to add to the square of x\n \n Returns:\n x*x + c\n \"\"\"\n \n return x * x + c"},{"id":49,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\nv = np.linspace(0.,10.,11)\nb = 2.5\n\n# Now let's run the code,\nv2 = my_square_function(v, b)\nprint(\"v = \" + str(v))\nprint(\"v*v+2.5 = \" + str(v2))"},{"id":50,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import pandas as pd"},{"id":51,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"df = pd.read_csv(\"https://raw.githubusercontent.com/Mark-Kramer/BU-MA665-MA666/master/Data/Rhythms_1.csv\")\ndf.info()"},{"id":52,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"print(df)"},{"id":53,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\nd = np.array(df.iloc[:,0]) #Get the values associated with the first column of the dataframe\nt = np.array(df.iloc[:,1]) #Get the values associated with the first column of the dataframe"},{"id":54,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import matplotlib.pyplot as plt\n\n# Choose a subset to plot\nt = t[0:500]\nd = d[0:500]\n\nplt.figure()\nplt.plot(t, d)\nplt.title('My plot')\nplt.xlabel('Time [s]')\nplt.ylabel('Voltage [mV]')\nplt.show()"},{"id":55,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt"},{"id":56,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"mu = np.mean(d)\nsd = np.std(d)"},{"id":57,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"samps = np.random.normal(mu, sd, 500)"},{"id":58,"options":{"fig-cap":"","dpi":72,"classes":"","label":"","context":"interactive","warning":"true","message":"true","comment":"","out-height":"","out-width":"700px","results":"markup","output":"true","read-only":"false","fig-width":7,"autorun":"","fig-height":5},"code":"plt.figure()\nplt.hist(samps)\nplt.hist(d)\nplt.show()"}]; +globalThis.qpyodideCellDetails = [{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":1,"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd\n\ndf = pd.read_csv(\"https://raw.githubusercontent.com/Mark-Kramer/BU-MA665-MA666/master/Data/Rhythms_1.csv\")\nd = np.array(df.iloc[:,0])\nt = np.array(df.iloc[:,1])\n\n# Print useful information about the data.\nprint(\"Sampling frequency is \" + str( 1/(t[2]-t[1])) + ' Hz.')\nprint(\"Total duration of recording is \" + str(t[-1]) + ' s.')\nprint(\"Dimensions of data are \" + str(np.shape(d)) + ' data points.')\n\n# Choose an initial interval of time, from onset to 5 s,\ninitial_time_interval = t < 5 \n\n# ... and plot it.\nplt.plot(t[initial_time_interval], d[initial_time_interval])\nplt.xlabel('Time [s]')\nplt.ylabel('Data')\nplt.title('Initial interval of data');\nplt.show()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":2,"code":"4+9"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":3,"code":"4/3"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":4,"code":"4/10**2"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":5,"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport math"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":6,"code":"np.sin(2*np.pi)"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":7,"code":"math.atan(2*np.pi)"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":8,"code":"import numpy as np\na = np.array([[1, 2, 3, 4]])\nprint(a)"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":9,"code":"a = np.array( [[1, 2, 3, 4]] )\nprint( a * 3 )\nprint( 4 * a )\nprint( a + 1 )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":10,"code":"import numpy as np\na = np.array([1,2,3,4])\na * a"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":11,"code":"import numpy as np\na = 2\nb = np.array( [[0, 4, 7, 6]] )\nc = np.array( [[1, 5, 6, 8]] )\n\nprint( b * c )\nprint( b / c + a)\nprint( np.multiply( b, c ))"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":12,"code":"a = np.array([[1,2,3,4]])\nprint(a.shape)\nprint(np.shape(a))"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":13,"code":"import numpy as np\n\np = np.array( [[1,2,3],[4,5,6]] )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":14,"code":"print( p )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":15,"code":"print( p + 2 )\nprint( 2 * p )\nprint( p * p )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":16,"code":"import numpy as np\na = np.array( [1, 2, 3, 4, 5] )\nb = np.array( [6, 7, 8, 9, 10] )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":17,"code":"print( \"a[1] = \" + str(a[1]) )\nprint( \"b[1] = \" + str(b[1]) )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":18,"code":"c = np.array([a,b])\nprint( \"c = \\n\" + str(c) ) # \\n is a newline, or carriage return, which makes the printed matrix lineup better "},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":19,"code":"print( \"shape of c = \" + str( np.shape(c) ) )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":20,"code":"print( \"c[0,3] = \" + str( c[0,3] ) )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":21,"code":"print( \"c[0,:] = \" + str( c[0,:] ) )\nprint( \"2nd through 4th columns of the first row are c[0,1:4] = \" + str(c[0,1:4]) )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":22,"code":"print(\"c[0, :4] = \" + str( c[0,:4]))\nprint(\"c[0, 1:] = \" + str( c[0,1:]))"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":23,"code":"c[0,::2]"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":24,"code":"a = np.arange(1,10) # this creates a vector of increasing values from 1 to 9\na = 2*a \n\nprint( \"a = \" + str(a) )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":25,"code":"a[a > 10]"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":26,"code":"lgIdx = a > 10\nlgIdx"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":27,"code":"a[lgIdx]"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":28,"code":"lgIdx.nonzero()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":29,"code":"a[ (a > 10).nonzero() ]"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":30,"code":"print(\"a = \" + str(a))\na[a > 10] = 100\nprint(\"a = \" + str(a))"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":31,"code":"b = np.array([[1,2,3],[4,5,6],[7,8,9]])\nprint( \"b = \\n\" + str(b) )\nprint( \" b > 5 is \\n\" + str(b > 5) )\nprint(\" b[b>5] is an array: \" + str(b[b>5]) )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":32,"code":"import numpy as np\n\nx = np.linspace(0,10,11) \nprint( \"x = \" + str(x) )\n\n# The above line constructs a vector that starts at 0, ends at 10, and\n# has 11 entries (takes steps of size 1 from 0 to 10). Let\n\ny = np.sin(x)\nprint( \"y = \" + str(y) )"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":33,"code":"import matplotlib.pyplot as plt\nx = ([1, 2, 3, 4])\ny = x\nplt.figure()\nplt.plot(x,y) \nplt.show() # this is the plotting equivalent of print()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":34,"code":"x = np.linspace(0,10,11) \ny = np.sin(x)\n\nplt.figure()\nplt.plot(x, y)\nplt.show()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":35,"code":"import numpy as np\nx = np.linspace(0,10, 101)\nprint(x)"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":36,"code":"y = np.sin(x)\nplt.figure()\nplt.plot(x,y,'k') # the 'k' we've added makes the curve black instead of blue\nplt.show()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":37,"code":"import numpy as np\nx = np.linspace(0,10, 101)\nz = np.cos(x)"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":38,"code":"import matplotlib.pyplot as plt\nplt.figure()\nplt.plot(x,z)\nplt.show()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":39,"code":"y = np.sin(x)\nplt.figure()\nplt.plot(x,z) # plot z vs x.\nplt.plot(x,y,'r') # plot y vs x in red\nplt.show()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":40,"code":"plt.figure()\nplt.plot(x,z) # plot z vs x\nplt.plot(x,y,'r') # plot y vs x in red\nplt.xlabel('x') # x-axis label\nplt.ylabel('y or z') # y-axis label\nplt.title('y vs x and z vs x') # title\nplt.legend(('y','z')) # make a legend labeling each line\nplt.show()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":41,"code":"plt.figure()\nplt.plot(x,y, label='y') # sometimes it is easier to name a trace within the plot() call\nplt.plot(x,z, label='z') # notice without a color matplotlib will assign one\nplt.xlabel('x', fontsize=14)\nplt.ylabel('y', fontsize=14)\nplt.title('y vs x', fontsize=18)\nplt.legend(fontsize=12)\nplt.show()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":42,"code":"import numpy as np\n\nprint(\"a Gaussian random number (mean=0, variance=1): \" + str( np.random.randn() ))\n\n# a uniform random number on [0,1)\nprint(\"a uniform random number from [0,1): \" + str(np.random.rand()))"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":43,"code":"r = np.random.randn(1000)"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":44,"code":"import matplotlib.pyplot as plt\nplt.figure()\nplt.hist(r)\nplt.show()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":45,"code":"import numpy as np\nimport matplotlib.pyplot as plt\n\nx = np.arange(0,10,0.1) # Define a vector x that ranges from 0 to 9.9 with step 0.1.\nk = 1 # Fix k=1,\ny = np.sin(x + k*np.pi/4) # ... and define y at this k.\n\nplt.figure() # Make a new figure,\nplt.plot(x,y) # ... and plot y versus x.\n\nk = 2 # Let's repeat this, for k=2,\ny = np.sin(x + k*np.pi/4) # ... and redefine y at this k,\nplt.plot(x,y) # ... and plot it.\n\nk = 3 # Let's repeat this, for k=3,\ny = np.sin(x + k*np.pi/4) # ... and redefine y at this k,\nplt.plot(x,y) # ... and plot it.\n\nk = 4 # Let's repeat this, for k=4,\ny = np.sin(x + k*np.pi/4) # ... and redefine y at this k,\nplt.plot(x,y) # ... and plot it.\n\nk = 5 # Let's repeat this, for k=5,\ny = np.sin(x + k*np.pi/4) # ... and redefine y at this k,\nplt.plot(x,y) # ... and plot it.\n\nplt.show()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":46,"code":"x = np.arange(0,10,0.1) #First, define the vector x."},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":47,"code":"plt.figure()\nfor k in range(1,6): \n y = np.sin(x + k*np.pi/4) #Define y (note the variable 'k' in sin), also note we have indented here!\n plt.plot(x,y) #Plot y versus x\n \n# no indentation now, so this code follows the loop\nplt.show()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":48,"code":"def my_square_function(x, c):\n \"\"\"Square a vector and add a constant.\n\n Arguments:\n x -- vector to square\n c -- constant to add to the square of x\n \n Returns:\n x*x + c\n \"\"\"\n \n return x * x + c"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":49,"code":"import numpy as np\nv = np.linspace(0.,10.,11)\nb = 2.5\n\n# Now let's run the code,\nv2 = my_square_function(v, b)\nprint(\"v = \" + str(v))\nprint(\"v*v+2.5 = \" + str(v2))"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":50,"code":"import pandas as pd"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":51,"code":"df = pd.read_csv(\"https://raw.githubusercontent.com/Mark-Kramer/BU-MA665-MA666/master/Data/Rhythms_1.csv\")\ndf.info()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":52,"code":"print(df)"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":53,"code":"import numpy as np\nd = np.array(df.iloc[:,0]) #Get the values associated with the first column of the dataframe\nt = np.array(df.iloc[:,1]) #Get the values associated with the first column of the dataframe"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":54,"code":"import matplotlib.pyplot as plt\n\n# Choose a subset to plot\nt = t[0:500]\nd = d[0:500]\n\nplt.figure()\nplt.plot(t, d)\nplt.title('My plot')\nplt.xlabel('Time [s]')\nplt.ylabel('Voltage [mV]')\nplt.show()"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":55,"code":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":56,"code":"mu = np.mean(d)\nsd = np.std(d)"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":57,"code":"samps = np.random.normal(mu, sd, 500)"},{"options":{"output":"true","classes":"","warning":"true","out-height":"","comment":"","results":"markup","context":"interactive","read-only":"false","fig-cap":"","fig-height":5,"label":"","dpi":72,"fig-width":7,"autorun":"","message":"true","out-width":"700px"},"id":58,"code":"plt.figure()\nplt.hist(samps)\nplt.hist(d)\nplt.show()"}]; diff --git a/docs/Perceptron.html b/docs/Perceptron.html index a48a91c..9ef69ed 100644 --- a/docs/Perceptron.html +++ b/docs/Perceptron.html @@ -228,7 +228,7 @@ } // Store cell data -globalThis.qpyodideCellDetails = [{"id":1,"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport time","options":{"message":"true","context":"interactive","label":"","output":"true","warning":"true","comment":"","fig-height":5,"dpi":72,"read-only":"false","results":"markup","autorun":"","out-width":"700px","out-height":"","fig-cap":"","fig-width":7,"classes":""}},{"id":2,"code":"def my_perceptron(input1, input2, w1, w2, theta):\n print(\"Do something!\")\n # Define the activity of the perceptron, x. \n # Apply a binary threshold.","options":{"message":"true","context":"interactive","label":"","output":"true","warning":"true","comment":"","fig-height":5,"dpi":72,"read-only":"false","results":"markup","autorun":"","out-width":"700px","out-height":"","fig-cap":"","fig-width":7,"classes":""}},{"id":3,"code":"my_perceptron(1,0,0.5,-0.5,0)","options":{"message":"true","context":"interactive","label":"","output":"true","warning":"true","comment":"","fig-height":5,"dpi":72,"read-only":"false","results":"markup","autorun":"","out-width":"700px","out-height":"","fig-cap":"","fig-width":7,"classes":""}},{"id":4,"code":"def known_answer(slope, intercept, x, y):\n print(\"Do something!\")\n #Determine yline\n #Determine if y is above yline","options":{"message":"true","context":"interactive","label":"","output":"true","warning":"true","comment":"","fig-height":5,"dpi":72,"read-only":"false","results":"markup","autorun":"","out-width":"700px","out-height":"","fig-cap":"","fig-width":7,"classes":""}},{"id":5,"code":"x,y = 0.7,3\nslope = 2\nintercept = 1\ncorrect_answer = known_answer(slope, intercept, x, y)\nprint(correct_answer)","options":{"message":"true","context":"interactive","label":"","output":"true","warning":"true","comment":"","fig-height":5,"dpi":72,"read-only":"false","results":"markup","autorun":"","out-width":"700px","out-height":"","fig-cap":"","fig-width":7,"classes":""}},{"id":6,"code":"def feedforward(x, y, wx, wy, wb):\n print(\"Do something!\")\n # Fix the bias.\n # Define the activity of the neuron, activity.\n # Apply the binary threshold.","options":{"message":"true","context":"interactive","label":"","output":"true","warning":"true","comment":"","fig-height":5,"dpi":72,"read-only":"false","results":"markup","autorun":"","out-width":"700px","out-height":"","fig-cap":"","fig-width":7,"classes":""}},{"id":7,"code":"x,y = 0.7,3\nwx,wy,wb = 3*[0.5]\nperceptron_guess = feedforward(x, y, wx, wy, wb)\nprint(perceptron_guess)","options":{"message":"true","context":"interactive","label":"","output":"true","warning":"true","comment":"","fig-height":5,"dpi":72,"read-only":"false","results":"markup","autorun":"","out-width":"700px","out-height":"","fig-cap":"","fig-width":7,"classes":""}},{"id":8,"code":"error = 'SOMETHING?'\nprint(error)","options":{"message":"true","context":"interactive","label":"","output":"true","warning":"true","comment":"","fig-height":5,"dpi":72,"read-only":"false","results":"markup","autorun":"","out-width":"700px","out-height":"","fig-cap":"","fig-width":7,"classes":""}},{"id":9,"code":"learning_constant = 0.01","options":{"message":"true","context":"interactive","label":"","output":"true","warning":"true","comment":"","fig-height":5,"dpi":72,"read-only":"false","results":"markup","autorun":"","out-width":"700px","out-height":"","fig-cap":"","fig-width":7,"classes":""}},{"id":10,"code":"wx = \"SOMETHING\"\nwy = \"SOMETHING\"\nwb = \"SOMETHING\"\nprint(wx)","options":{"message":"true","context":"interactive","label":"","output":"true","warning":"true","comment":"","fig-height":5,"dpi":72,"read-only":"false","results":"markup","autorun":"","out-width":"700px","out-height":"","fig-cap":"","fig-width":7,"classes":""}},{"id":11,"code":"slope = 2; # Define the line with slope, \nintercept = 1; # ... and intercept.\n\nwx,wy,wb = 3*[0.5]; # Choose initial values for the perceptron's weights\n\nlearning_constant = 0.01; # And, set the learning constant.\n\nestimated_slope = np.zeros(2000) # Variables to hold the perceptron estimates.\nestimated_intercept = np.zeros(2000)\n\nfor k in np.arange(2000): # For 2000 iteractions,\n x = np.random.randn(1); # Choose a random (x,y) point in the plane\n y = np.random.randn(1);\n # Step 1: Calculate known answer.\n \n # Step 2. Ask perceptron to guess an answer.\n \n # Step 3. Compute the error.\n \n # Step 4. Adjust weights according to error.\n \n estimated_slope[k] = -wx/wy; # Compute estimated slope from perceptron.\n estimated_intercept[k] = -wb/wy;# Compute estimated intercept from perceptron.\n\n# Display the results! ------------------------------------------------------------------------\nx_range = np.linspace(-2,2,100); # For a range of x-values,\nfig, ax = plt.subplots()\nax.plot(x_range, slope*x_range+intercept, 'k') # ... plot the true line,\n\nfor k in range(1,2000,100): # ... and plot some intermediate perceptron guess\n ax.plot(x_range, estimated_slope[k]*x_range+estimated_intercept[k], 'r', alpha=0.25)\n # ... and plot the last perceptron guess\nplt.xlabel('x')\nplt.title('Known answer (black), Perceptron final guess (blue)')\nplt.show()","options":{"message":"true","context":"interactive","label":"","output":"true","warning":"true","comment":"","fig-height":5,"dpi":72,"read-only":"false","results":"markup","autorun":"","out-width":"700px","out-height":"","fig-cap":"","fig-width":7,"classes":""}}]; +globalThis.qpyodideCellDetails = [{"id":1,"options":{"results":"markup","read-only":"false","warning":"true","context":"interactive","fig-width":7,"fig-cap":"","autorun":"","comment":"","classes":"","out-height":"","dpi":72,"out-width":"700px","output":"true","message":"true","fig-height":5,"label":""},"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport time"},{"id":2,"options":{"results":"markup","read-only":"false","warning":"true","context":"interactive","fig-width":7,"fig-cap":"","autorun":"","comment":"","classes":"","out-height":"","dpi":72,"out-width":"700px","output":"true","message":"true","fig-height":5,"label":""},"code":"def my_perceptron(input1, input2, w1, w2, theta):\n print(\"Do something!\")\n # Define the activity of the perceptron, x. \n # Apply a binary threshold."},{"id":3,"options":{"results":"markup","read-only":"false","warning":"true","context":"interactive","fig-width":7,"fig-cap":"","autorun":"","comment":"","classes":"","out-height":"","dpi":72,"out-width":"700px","output":"true","message":"true","fig-height":5,"label":""},"code":"my_perceptron(1,0,0.5,-0.5,0)"},{"id":4,"options":{"results":"markup","read-only":"false","warning":"true","context":"interactive","fig-width":7,"fig-cap":"","autorun":"","comment":"","classes":"","out-height":"","dpi":72,"out-width":"700px","output":"true","message":"true","fig-height":5,"label":""},"code":"def known_answer(slope, intercept, x, y):\n print(\"Do something!\")\n #Determine yline\n #Determine if y is above yline"},{"id":5,"options":{"results":"markup","read-only":"false","warning":"true","context":"interactive","fig-width":7,"fig-cap":"","autorun":"","comment":"","classes":"","out-height":"","dpi":72,"out-width":"700px","output":"true","message":"true","fig-height":5,"label":""},"code":"x,y = 0.7,3\nslope = 2\nintercept = 1\ncorrect_answer = known_answer(slope, intercept, x, y)\nprint(correct_answer)"},{"id":6,"options":{"results":"markup","read-only":"false","warning":"true","context":"interactive","fig-width":7,"fig-cap":"","autorun":"","comment":"","classes":"","out-height":"","dpi":72,"out-width":"700px","output":"true","message":"true","fig-height":5,"label":""},"code":"def feedforward(x, y, wx, wy, wb):\n print(\"Do something!\")\n # Fix the bias.\n # Define the activity of the neuron, activity.\n # Apply the binary threshold."},{"id":7,"options":{"results":"markup","read-only":"false","warning":"true","context":"interactive","fig-width":7,"fig-cap":"","autorun":"","comment":"","classes":"","out-height":"","dpi":72,"out-width":"700px","output":"true","message":"true","fig-height":5,"label":""},"code":"x,y = 0.7,3\nwx,wy,wb = 3*[0.5]\nperceptron_guess = feedforward(x, y, wx, wy, wb)\nprint(perceptron_guess)"},{"id":8,"options":{"results":"markup","read-only":"false","warning":"true","context":"interactive","fig-width":7,"fig-cap":"","autorun":"","comment":"","classes":"","out-height":"","dpi":72,"out-width":"700px","output":"true","message":"true","fig-height":5,"label":""},"code":"error = 'SOMETHING?'\nprint(error)"},{"id":9,"options":{"results":"markup","read-only":"false","warning":"true","context":"interactive","fig-width":7,"fig-cap":"","autorun":"","comment":"","classes":"","out-height":"","dpi":72,"out-width":"700px","output":"true","message":"true","fig-height":5,"label":""},"code":"learning_constant = 0.01"},{"id":10,"options":{"results":"markup","read-only":"false","warning":"true","context":"interactive","fig-width":7,"fig-cap":"","autorun":"","comment":"","classes":"","out-height":"","dpi":72,"out-width":"700px","output":"true","message":"true","fig-height":5,"label":""},"code":"wx = \"SOMETHING\"\nwy = \"SOMETHING\"\nwb = \"SOMETHING\"\nprint(wx)"},{"id":11,"options":{"results":"markup","read-only":"false","warning":"true","context":"interactive","fig-width":7,"fig-cap":"","autorun":"","comment":"","classes":"","out-height":"","dpi":72,"out-width":"700px","output":"true","message":"true","fig-height":5,"label":""},"code":"slope = 2; # Define the line with slope, \nintercept = 1; # ... and intercept.\n\nwx,wy,wb = 3*[0.5]; # Choose initial values for the perceptron's weights\n\nlearning_constant = 0.01; # And, set the learning constant.\n\nestimated_slope = np.zeros(2000) # Variables to hold the perceptron estimates.\nestimated_intercept = np.zeros(2000)\n\nfor k in np.arange(2000): # For 2000 iteractions,\n x = np.random.randn(1); # Choose a random (x,y) point in the plane\n y = np.random.randn(1);\n # Step 1: Calculate known answer.\n \n # Step 2. Ask perceptron to guess an answer.\n \n # Step 3. Compute the error.\n \n # Step 4. Adjust weights according to error.\n \n estimated_slope[k] = -wx/wy; # Compute estimated slope from perceptron.\n estimated_intercept[k] = -wb/wy;# Compute estimated intercept from perceptron.\n\n# Display the results! ------------------------------------------------------------------------\nx_range = np.linspace(-2,2,100); # For a range of x-values,\nfig, ax = plt.subplots()\nax.plot(x_range, slope*x_range+intercept, 'k') # ... plot the true line,\n\nfor k in range(1,2000,100): # ... and plot some intermediate perceptron guess\n ax.plot(x_range, estimated_slope[k]*x_range+estimated_intercept[k], 'r', alpha=0.25)\n # ... and plot the last perceptron guess\nplt.xlabel('x')\nplt.title('Known answer (black), Perceptron final guess (blue)')\nplt.show()"}]; diff --git a/docs/Readings/MA665_MA666_Syllabus.pdf b/docs/Readings/MA665_MA666_Syllabus.pdf index e59baeb..78b7607 100644 Binary files a/docs/Readings/MA665_MA666_Syllabus.pdf and b/docs/Readings/MA665_MA666_Syllabus.pdf differ diff --git a/docs/Slides/IF_Lecture_1.pdf b/docs/Slides/IF_Lecture_1.pdf index 1f0c967..16a69c9 100644 Binary files a/docs/Slides/IF_Lecture_1.pdf and b/docs/Slides/IF_Lecture_1.pdf differ diff --git a/docs/search.json b/docs/search.json index 226556d..0fb6288 100644 --- a/docs/search.json +++ b/docs/search.json @@ -109,6 +109,6 @@ "href": "HH.html", "title": "Hodgkin-Huxley Neuron", "section": "", - "text": "In this notebook we will use Python to simulate the Hodgkin-Huxley (HH) neuron model. This model is arguably the most important computational model in neuroscience. We’ll focus here on simulating this model and understanding its pieces.\n\n1 Preliminaries\nBefore beginning, let’s load in the Python packages we’ll need:\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nIn addition, let’s import the functions we’ll need to simulate the HH model, which are available on this repository:\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n2 The Hodgkin-Huxley (HH) equation code.\nTo start, let’s examine the code for the HH model. To do so, visit the raw code avaiable here.\n\n\n\n\n\n\nQ: Examine this code. Can you make sense of it? Can you identify the gating variables? The rate functions? The equations that define the dynamics? We’ll answer these questions in this in notebook, but try so on your own first.\n\n\n\nWhenever examining code, it’s useful to consider the inputs to the code, and the outputs produced by the code. There are two inputs to HH0:\n\nI0 = the current we inject to the neuron.\nT0 = the total time of the simulation in [ms].\n\nAnd there are five outputs:\n\nV = the voltage of neuron.\nm = activation variable for Na-current.\nh = inactivation variable for Na-current.\nn = activation variable for K-current.\nt = the time axis of the simulation (useful for plotting).\n\n\n\n3 At low input current (I0), examine the HH dynamics.\nTo understand how the HH model works, we’ll start by focusing on the case when I0 is small. Let’s fix the input current to zero,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nand let’s simulate the model for 100 ms,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nWe’ve now defined both inputs to the HH function, and can execute it, as follows,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nNotice that the function returns five outputs, which we assign to the variables V, m, h, n, and t.\n\n\n\n\n\n\nQ: What are the dynamics of the voltage (variable V) resulting from this simulation? HINT: Plot V vs t.\n\n\n\n\n\n\n\n\n\nQ: What are the dynamics of the gating variables (m, h, n) resulting from this simulation? HINT: Plot them!\n\n\n\n\n\n\n\n\n\nQ: What are the final values (after the 100 ms of simulation) of V, m, h, and n?\n\n\n\n\n\n4 At high input current (I0), examine the HH dynamics of a spike.\nLet’s now increase the input current to the HH model and get this model to generate repeated spiking activity. To do so, let’s set,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nWe can now simulate this model,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n\n\n\n\nQ: What happens to the dynamics? HINT: Plot V vs t.\n\n\n\nObservations: You should have found that, at this value of input current, the model generates repeated spikes.\n\nLet’s now explore how the combined gates and dynamics evolve. To do so, let’s start by focusing our plot on a single spike. As a first step, let’s plot the voltage, and choose the time axis to focus on a single spike,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nWe’ve now plotted the voltage dynamics for a single spike (and colored the curve black).\nLet’s now plot the three gating variables. To do so, we’ll make another plot.\nLet’s start by displaying the gating variable m over the same x-limits,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nNotice that, in the call to plot we included the input label. This will be useful when we create a legend. Within this subplot, we can also simultaneously show the gating variables h and n, with the x-axis labeled.\nLet’s also add a legend to help us keep track of the different curves:\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n\n\n\n\nQ: Using the figure you created above, describe how the gates swing open and closed during a spike.\n\n\n\nASIDE: Here’s a nice plotting trick, to link the x-axes of our two subfigures. Linking the axes is useful so that, when we zoom or move one subfigure, the other subfigure will match the x-axis.\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nNow, in the figure, you may use the pan/zoom tool to adjust the linked subplots.\n\n\n5 At high input current (I0), describe the dynamics of the conductances.\nWe have so far explored how the three gates m, h, and n evolve during a spike. By combining these terms, we can visualize how the conductances evolve during a spike. To do so, let’s stick with the simulation results we generated in the previous section, and focus our plot on a single spike,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nNow, to plot the conductances, let’s define three new variables,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n\n\n\n\nQ: Where do these terms come from?\n\n\n\nThen, let’s plot these conductances,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n\n\n\n\nQ: How do the conductances evolve during a spike?\n\n\n\nAt high input current (I0), describe the dynamics of the currents. In the previous section, we explored how the three conductances (gNa, gK, gL) evolve during a spike.\nLet’s now visualize how the ionic currents evolve during a spike.\nTo do so, let’s stick with the same settings used in the previous section and examine the same simulation result. Again, we’ll focus our plot on a single spike.\nNow, to plot the current, let’s define the new variables,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n\n\n\n\nQ: How do the conductances evolve during a spike?\n\n\n\n\n\n\n\n\n\nQ: You may notice a small, transient decrease in the sodium current INa near 47 ms. What causes this?\n\n\n\n\n\n6 Discussion\n\nHow is the HH model different from / similar to the IF and LIF models?\nWhat are the ion species simulated in the HH model?\nWhich ion species is fastest / slowest?\nHow many variables are in the HH model? Define each.\nSketch the model equations, in schematic form, to capture the “essence” of the behavior (don’t worry about the detailed values for parameters).\nWhich gating variables are depolarization activated / depolarization inactivated?\nSketch the steady-state curves for the gating variables.\nConsider the current: I_K=g_K n^4 (E_K-V)\n\nDefine each term.\nHow does this current behave for different values of V?\n\nConsider the current: I_Na=g_Na m^3 h (E_Na-V)\n\nDefine each term.\nHow does this current behave for different values of V?\n\n\n\n\n7 Challenges\n\nExplain each line of the Python code that simulates the HH model.\nDescribe the dynamics of the gates and ions during an action potential in the HH model.\nDetermine how the firing rate of the HH model varies with input current I. Plot the firing rate versus I (i.e., plot the “f-I curve”).\nHow do the dynamics change as you increases / decrease the potassium conductance?\nHow do the dynamics change as you increases / decrease the sodium conductance?" + "text": "In this notebook we will use Python to simulate the Hodgkin-Huxley (HH) neuron model. This model is arguably the most important computational model in neuroscience. We’ll focus here on simulating this model and understanding its pieces.\n\n1 Preliminaries\nBefore beginning, let’s load in the Python packages we’ll need:\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nIn addition, let’s import the functions we’ll need to simulate the HH model, which are available on this repository:\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n2 The Hodgkin-Huxley (HH) equation code.\nTo start, let’s examine the code for the HH model. To do so, visit the raw code avaiable here.\n\n\n\n\n\n\nQ: Examine this code. Can you make sense of it? Can you identify the gating variables? The rate functions? The equations that define the dynamics? We’ll answer these questions in this in notebook, but try so on your own first.\n\n\n\nWhenever examining code, it’s useful to consider the inputs to the code, and the outputs produced by the code. There are two inputs to HH0:\n\nI0 = the current we inject to the neuron.\nT0 = the total time of the simulation in [ms].\n\nAnd there are five outputs:\n\nV = the voltage of neuron.\nm = activation variable for Na-current.\nh = inactivation variable for Na-current.\nn = activation variable for K-current.\nt = the time axis of the simulation (useful for plotting).\n\n\n\n3 At low input current (I0), examine the HH dynamics.\nTo understand how the HH model works, we’ll start by focusing on the case when I0 is small. Let’s fix the input current to zero,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nand let’s simulate the model for 100 ms,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nWe’ve now defined both inputs to the HH function, and can execute it, as follows,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nNotice that the function returns five outputs, which we assign to the variables V, m, h, n, and t.\n\n\n\n\n\n\nQ: What are the dynamics of the voltage (variable V) resulting from this simulation? HINT: Plot V vs t.\n\n\n\n\n\n\n\n\n\nQ: What are the dynamics of the gating variables (m, h, n) resulting from this simulation? HINT: Plot them!\n\n\n\n\n\n\n\n\n\nQ: What are the final values (after the 100 ms of simulation) of V, m, h, and n?\n\n\n\n\n\n4 At high input current (I0), examine the HH dynamics of a spike.\nLet’s now increase the input current to the HH model and get this model to generate repeated spiking activity. To do so, let’s set,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nWe can now simulate this model,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n\n\n\n\nQ: What happens to the dynamics? HINT: Plot V vs t.\n\n\n\nObservations: You should have found that, at this value of input current, the model generates repeated spikes.\n\nLet’s now explore how the combined gates and dynamics evolve. To do so, let’s start by focusing our plot on a single spike. As a first step, let’s plot the voltage, and choose the time axis to focus on a single spike,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nWe’ve now plotted the voltage dynamics for a single spike (and colored the curve black).\nLet’s now plot the three gating variables. To do so, we’ll make another plot.\nLet’s start by displaying the gating variable m over the same x-limits,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nNotice that, in the call to plot we included the input label. This will be useful when we create a legend. Within this subplot, we can also simultaneously show the gating variables h and n, with the x-axis labeled.\nLet’s also add a legend to help us keep track of the different curves:\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n\n\n\n\nQ: Using the figure you created above, describe how the gates swing open and closed during a spike.\n\n\n\nASIDE: Here’s a nice plotting trick, to link the x-axes of our two subfigures. Linking the axes is useful so that, when we zoom or move one subfigure, the other subfigure will match the x-axis.\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nNow, in the figure, you may use the pan/zoom tool to adjust the linked subplots.\n\n\n5 At high input current (I0), describe the dynamics of the conductances.\nWe have so far explored how the three gates m, h, and n evolve during a spike. By combining these terms, we can visualize how the conductances evolve during a spike. To do so, let’s stick with the simulation results we generated in the previous section, and focus our plot on a single spike,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\nNow, to plot the conductances, let’s define three new variables,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n\n\n\n\nQ: Where do these terms come from?\n\n\n\nThen, let’s plot these conductances,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n\n\n\n\nQ: How do the conductances evolve during a spike?\n\n\n\nAt high input current (I0), describe the dynamics of the currents. In the previous section, we explored how the three conductances (gNa, gK, gL) evolve during a spike.\nLet’s now visualize how the ionic currents evolve during a spike.\nTo do so, let’s stick with the same settings used in the previous section and examine the same simulation result. Again, we’ll focus our plot on a single spike.\nNow, to plot the current, let’s define the new variables,\n\nPlease enable JavaScript to experience the dynamic code cell content on this page.\n\n\n\n\n\n\nQ: How do the conductances evolve during a spike?\n\n\n\n\n\n\n\n\n\nQ: You may notice a small, transient decrease in the sodium current INa near 47 ms. What causes this?\n\n\n\n\n\n6 Discussion\n\nHow is the HH model different from / similar to the IF and LIF models?\nWhat are the ion species simulated in the HH model?\nWhich ion species is fastest / slowest?\nHow many variables are in the HH model? Define each.\nSketch the model equations, in schematic form, to capture the “essence” of the behavior (don’t worry about the detailed values for parameters).\nWhich gating variables are depolarization activated / depolarization inactivated?\nSketch the steady-state curves for the gating variables.\nConsider the current: I_K=g_K n^4 (E_K-V)\n\nDefine each term.\nHow does this current behave for different values of V?\n\nConsider the current: I_Na=g_Na m^3 h (E_Na-V)\n\nDefine each term.\nHow does this current behave for different values of V?\n\n\n\n\n7 Challenges\n\nDescribe the dynamics during an action potential in the HH model. How does the voltage change? How do the gates open and close? How do the ions flow?\nDetermine how the firing rate of the HH model varies with input current I. Plot the firing rate versus I (i.e., plot the “f-I curve”).\nHow does the firing rate of the HH model change as you increase the potassium conductance? Provide a “simulation” explanation and a “physical” explanation.\nHow does the firing rate of the HH model change as you increase sodium conductance? Provide a “simulation” explanation and a “physical” explanation." } ] \ No newline at end of file