Skip to content

Commit

Permalink
+ spike spectra
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Kramer committed Nov 7, 2024
1 parent 94a3196 commit bbbecb9
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 59 deletions.
6 changes: 3 additions & 3 deletions Analyzing_Rhythms_Lab_3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Repeat the entire simulation many times, and plot the average spectrum\n",
"# Repeat the entire simulation many times, and plot the average autocovariance and spectrum\n",
"\n",
"K = 1000 # Number of times to repeat the simulation.\n",
"lambda_est = np.zeros(K) # Vector to store estimate of lambda.\n",
Expand All @@ -126,7 +126,7 @@
" P[k,:] = Pj # ... and save the result.\n",
"\n",
"plt.figure() # Plot it.\n",
"plt.plot(lags, np.mean(AC,0))\n",
"plt.plot(lags*dt, np.mean(AC,0))\n",
"plt.xlabel('Lag [s]')\n",
"plt.ylabel('Autocovariance');\n",
"\n",
Expand Down Expand Up @@ -198,7 +198,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Repeat the entire simulation many times, and plot the average spectrum"
"# Repeat the entire simulation many times, and plot the average autocovariance and spectrum"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion Coherence_Lab_Part_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.8.18"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion Coherence_Lab_Part_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.8.18"
}
},
"nbformat": 4,
Expand Down
Binary file modified Slides/Analyzing_Rhythms_Lecture_3.pdf
Binary file not shown.
6 changes: 3 additions & 3 deletions docs/Analyzing_Rhythms_Lab_3.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ <h1>Example: a randomly spiking neuron</h1>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a>plt.xlabel(<span class="st">'Frequency [Hz]'</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div id="cell-7" class="cell">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Repeat the entire simulation many times, and plot the average spectrum</span></span>
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Repeat the entire simulation many times, and plot the average autocovariance and spectrum</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>K <span class="op">=</span> <span class="dv">1000</span> <span class="co"># Number of times to repeat the simulation.</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>lambda_est <span class="op">=</span> np.zeros(K) <span class="co"># Vector to store estimate of lambda.</span></span>
Expand All @@ -266,7 +266,7 @@ <h1>Example: a randomly spiking neuron</h1>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true" tabindex="-1"></a> P[k,:] <span class="op">=</span> Pj <span class="co"># ... and save the result.</span></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true" tabindex="-1"></a>plt.figure() <span class="co"># Plot it.</span></span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true" tabindex="-1"></a>plt.plot(lags, np.mean(AC,<span class="dv">0</span>))</span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true" tabindex="-1"></a>plt.plot(lags<span class="op">*</span>dt, np.mean(AC,<span class="dv">0</span>))</span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true" tabindex="-1"></a>plt.xlabel(<span class="st">'Lag [s]'</span>)</span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true" tabindex="-1"></a>plt.ylabel(<span class="st">'Autocovariance'</span>)<span class="op">;</span></span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true" tabindex="-1"></a></span>
Expand Down Expand Up @@ -304,7 +304,7 @@ <h1>Example: a randomly spiking neuron + refractory period</h1>
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Compute the spectrum.</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div id="cell-13" class="cell">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Repeat the entire simulation many times, and plot the average spectrum</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Repeat the entire simulation many times, and plot the average autocovariance and spectrum</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>


Expand Down
2 changes: 1 addition & 1 deletion docs/Backpropagation.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
}

// Store cell data
globalThis.qpyodideCellDetails = [{"options":{"warning":"true","label":"","out-width":"700px","context":"interactive","read-only":"false","classes":"","comment":"","message":"true","output":"true","autorun":"","dpi":72,"out-height":"","fig-width":7,"fig-cap":"","fig-height":5,"results":"markup"},"id":1,"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd"},{"options":{"warning":"true","label":"","out-width":"700px","context":"interactive","read-only":"false","classes":"","comment":"","message":"true","output":"true","autorun":"","dpi":72,"out-height":"","fig-width":7,"fig-cap":"","fig-height":5,"results":"markup"},"id":2,"code":"df = pd.read_csv(\"https://raw.githubusercontent.com/Mark-Kramer/BU-MA665-MA666/master/Data/backpropagation_example_data.csv\")\n\n# Extract the variables from the loaded data\nin_true = np.array(df.iloc[:,0]) #Get the values associated with the first column of the dataframe\nout_true = np.array(df.iloc[:,1]) #Get the values associated with the second column of the dataframe"},{"options":{"warning":"true","label":"","out-width":"700px","context":"interactive","read-only":"false","classes":"","comment":"","message":"true","output":"true","autorun":"","dpi":72,"out-height":"","fig-width":7,"fig-cap":"","fig-height":5,"results":"markup"},"id":3,"code":"print(np.transpose([in_true, out_true]))"},{"options":{"warning":"true","label":"","out-width":"700px","context":"interactive","read-only":"false","classes":"","comment":"","message":"true","output":"true","autorun":"","dpi":72,"out-height":"","fig-width":7,"fig-cap":"","fig-height":5,"results":"markup"},"id":4,"code":"def sigmoid(x):\n return 1/(1+np.exp(-x)) # Define the sigmoid anonymous function.\n\ndef feedforward(w, s0): # Define feedforward solution.\n # ... x1 = activity of first neuron,\n # ... s1 = output of first neuron,\n # ... x2 = activity of second neuron,\n # ... s2 = output of second neuron,\n # ... out = output of neural network.\n return out,s1,s2"},{"options":{"warning":"true","label":"","out-width":"700px","context":"interactive","read-only":"false","classes":"","comment":"","message":"true","output":"true","autorun":"","dpi":72,"out-height":"","fig-width":7,"fig-cap":"","fig-height":5,"results":"markup"},"id":5,"code":"w = [0.5,0.5] # Choose initial values for the weights.\nalpha = 0.01 # Set the learning constant.\n\nK = np.size(in_true);\nresults = np.zeros([K,3]) # Define a variable to hold the results of each iteration. \n\nfor k in np.arange(K):\n s0 = in_true[k] # Define the input,\n target = out_true[k] # ... and the target output.\n \n #Calculate feedforward solution to get output.\n \n #Update the weights.\n w0 = w[0]; w1 = w[1];\n w[1] = \"SOMETHING\"\n w[0] = \"SOMETHING\"\n \n # Save the results of this step. --------------------------------------\n # Here we save the 3 weights, and the neural network output.\n # results[k,:] = [w[0],w[1], out]\n\n# Plot the NN weights and error during training \n# plt.clf()\n# plt.plot(results[:,1], label='w1')\n# plt.plot(results[:,0], label='w0')\n# plt.plot(results[:,2]-target, label='error')\n# plt.legend() #Include a legend,\n# plt.xlabel('Iteration number'); #... and axis label.\n\n# Print the NN weights\n# print(results[-1,0:2])"}];
globalThis.qpyodideCellDetails = [{"options":{"message":"true","dpi":72,"warning":"true","out-width":"700px","fig-height":5,"classes":"","fig-cap":"","context":"interactive","output":"true","label":"","autorun":"","out-height":"","comment":"","results":"markup","fig-width":7,"read-only":"false"},"id":1,"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd"},{"options":{"message":"true","dpi":72,"warning":"true","out-width":"700px","fig-height":5,"classes":"","fig-cap":"","context":"interactive","output":"true","label":"","autorun":"","out-height":"","comment":"","results":"markup","fig-width":7,"read-only":"false"},"id":2,"code":"df = pd.read_csv(\"https://raw.githubusercontent.com/Mark-Kramer/BU-MA665-MA666/master/Data/backpropagation_example_data.csv\")\n\n# Extract the variables from the loaded data\nin_true = np.array(df.iloc[:,0]) #Get the values associated with the first column of the dataframe\nout_true = np.array(df.iloc[:,1]) #Get the values associated with the second column of the dataframe"},{"options":{"message":"true","dpi":72,"warning":"true","out-width":"700px","fig-height":5,"classes":"","fig-cap":"","context":"interactive","output":"true","label":"","autorun":"","out-height":"","comment":"","results":"markup","fig-width":7,"read-only":"false"},"id":3,"code":"print(np.transpose([in_true, out_true]))"},{"options":{"message":"true","dpi":72,"warning":"true","out-width":"700px","fig-height":5,"classes":"","fig-cap":"","context":"interactive","output":"true","label":"","autorun":"","out-height":"","comment":"","results":"markup","fig-width":7,"read-only":"false"},"id":4,"code":"def sigmoid(x):\n return 1/(1+np.exp(-x)) # Define the sigmoid anonymous function.\n\ndef feedforward(w, s0): # Define feedforward solution.\n # ... x1 = activity of first neuron,\n # ... s1 = output of first neuron,\n # ... x2 = activity of second neuron,\n # ... s2 = output of second neuron,\n # ... out = output of neural network.\n return out,s1,s2"},{"options":{"message":"true","dpi":72,"warning":"true","out-width":"700px","fig-height":5,"classes":"","fig-cap":"","context":"interactive","output":"true","label":"","autorun":"","out-height":"","comment":"","results":"markup","fig-width":7,"read-only":"false"},"id":5,"code":"w = [0.5,0.5] # Choose initial values for the weights.\nalpha = 0.01 # Set the learning constant.\n\nK = np.size(in_true);\nresults = np.zeros([K,3]) # Define a variable to hold the results of each iteration. \n\nfor k in np.arange(K):\n s0 = in_true[k] # Define the input,\n target = out_true[k] # ... and the target output.\n \n #Calculate feedforward solution to get output.\n \n #Update the weights.\n w0 = w[0]; w1 = w[1];\n w[1] = \"SOMETHING\"\n w[0] = \"SOMETHING\"\n \n # Save the results of this step. --------------------------------------\n # Here we save the 3 weights, and the neural network output.\n # results[k,:] = [w[0],w[1], out]\n\n# Plot the NN weights and error during training \n# plt.clf()\n# plt.plot(results[:,1], label='w1')\n# plt.plot(results[:,0], label='w0')\n# plt.plot(results[:,2]-target, label='error')\n# plt.legend() #Include a legend,\n# plt.xlabel('Iteration number'); #... and axis label.\n\n# Print the NN weights\n# print(results[-1,0:2])"}];


</script>
Expand Down
Loading

0 comments on commit bbbecb9

Please sign in to comment.