Skip to content

Commit

Permalink
+ spike-field coherence
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Kramer committed Nov 14, 2024
1 parent 732e154 commit bfcbefb
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 48 deletions.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions Coherence_Lab_Part_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@
"Yf = \"SOMETHING\" # Compute Fourier transform of y for each trial\n",
"\n",
"# Auto- and cross-spectra.\n",
"Sxx = \"SOMETHING\" # Spectrum of E1 trials\n",
"Syy = \"SOMETHING\" # ... and E2 trials\n",
"Sxx = \"SOMETHING\" # Spectrum of x trials\n",
"Syy = \"SOMETHING\" # ... and y trials\n",
"Sxy = \"SOMETHING\" # ... and the cross spectrum\n",
"\n",
"# Trial average.\n",
Expand Down Expand Up @@ -155,7 +155,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
26 changes: 8 additions & 18 deletions Coherence_Lab_Part_3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@
"metadata": {},
"outputs": [],
"source": [
"[cohr, f, SYY, SNN, SYN] = coherence(n,y,t) # Coherence for original spike train.\n",
"[cohr, f, SYY, SNN, SYN] = \"SOMETHING\" # Coherence for original spike train.\n",
"plt.clf()\n",
"plt.plot(f,cohr, 'b')\n",
"[cohr, f, SYY, SNN, SYN] = coherence(thinned_spike_train(n,0.5),y,t) # ... and for the thinned spike train.\n",
"[cohr, f, SYY, SNN, SYN] = \"SOMETHING\" # ... and for the thinned spike train.\n",
"plt.plot(f,cohr, 'r')\n",
"plt.xlim([40, 50])\n",
"plt.legend(['Original', 'Thinned'])\n",
Expand All @@ -188,15 +188,12 @@
"metadata": {},
"outputs": [],
"source": [
"plt.figure(1); plt.clf(); plt.figure(2); plt.clf()\n",
"counter=1\n",
"for thinner in np.arange(0,1,0.25):\n",
" thinned = thinned_spike_train(n,thinner)\n",
" [cohr, f, SYY, SNN, SYN] = coherence(thinned,y,t) # ... and for the thinned spike train.\n",
" plt.figure(1)\n",
" plt.plot(f,cohr,label=str(thinner))\n",
" \n",
"plt.figure(1)\n",
"plt.figure();\n",
"for thin_factor in \"SOMETHING\n",
" thinned = \"SOMETHING\" # Make the thinned spike train\n",
" [cohr, f, SYY, SNN, SYN] =\"SOMETHING\" # ... and compute the coherence\n",
" plt.plot(f,cohr,label=str(thin_factor)) # \n",
"\n",
"plt.xlim([40, 50])\n",
"plt.legend()\n",
"plt.xlabel('Frequency [Hz]')\n",
Expand Down Expand Up @@ -349,13 +346,6 @@
"plt.title('Neuron A Rate: Baseline=' + str(baseline_A) + ', Coupling=' + str(coupling_A) + '\\n'\n",
" 'Neuron B Rate: Baseline=' + str(baseline_B) + ', Coupling=' + str(coupling_B));"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
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 = [{"id":1,"options":{"autorun":"","read-only":"false","fig-width":7,"warning":"true","comment":"","context":"interactive","dpi":72,"label":"","out-width":"700px","message":"true","output":"true","fig-height":5,"classes":"","results":"markup","fig-cap":"","out-height":""},"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd"},{"id":2,"options":{"autorun":"","read-only":"false","fig-width":7,"warning":"true","comment":"","context":"interactive","dpi":72,"label":"","out-width":"700px","message":"true","output":"true","fig-height":5,"classes":"","results":"markup","fig-cap":"","out-height":""},"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"},{"id":3,"options":{"autorun":"","read-only":"false","fig-width":7,"warning":"true","comment":"","context":"interactive","dpi":72,"label":"","out-width":"700px","message":"true","output":"true","fig-height":5,"classes":"","results":"markup","fig-cap":"","out-height":""},"code":"print(np.transpose([in_true, out_true]))"},{"id":4,"options":{"autorun":"","read-only":"false","fig-width":7,"warning":"true","comment":"","context":"interactive","dpi":72,"label":"","out-width":"700px","message":"true","output":"true","fig-height":5,"classes":"","results":"markup","fig-cap":"","out-height":""},"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"},{"id":5,"options":{"autorun":"","read-only":"false","fig-width":7,"warning":"true","comment":"","context":"interactive","dpi":72,"label":"","out-width":"700px","message":"true","output":"true","fig-height":5,"classes":"","results":"markup","fig-cap":"","out-height":""},"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 = [{"id":1,"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd","options":{"fig-cap":"","context":"interactive","message":"true","warning":"true","autorun":"","dpi":72,"comment":"","read-only":"false","classes":"","fig-height":5,"out-height":"","label":"","results":"markup","fig-width":7,"output":"true","out-width":"700px"}},{"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":{"fig-cap":"","context":"interactive","message":"true","warning":"true","autorun":"","dpi":72,"comment":"","read-only":"false","classes":"","fig-height":5,"out-height":"","label":"","results":"markup","fig-width":7,"output":"true","out-width":"700px"}},{"id":3,"code":"print(np.transpose([in_true, out_true]))","options":{"fig-cap":"","context":"interactive","message":"true","warning":"true","autorun":"","dpi":72,"comment":"","read-only":"false","classes":"","fig-height":5,"out-height":"","label":"","results":"markup","fig-width":7,"output":"true","out-width":"700px"}},{"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":{"fig-cap":"","context":"interactive","message":"true","warning":"true","autorun":"","dpi":72,"comment":"","read-only":"false","classes":"","fig-height":5,"out-height":"","label":"","results":"markup","fig-width":7,"output":"true","out-width":"700px"}},{"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])","options":{"fig-cap":"","context":"interactive","message":"true","warning":"true","autorun":"","dpi":72,"comment":"","read-only":"false","classes":"","fig-height":5,"out-height":"","label":"","results":"markup","fig-width":7,"output":"true","out-width":"700px"}}];


</script>
Expand Down
4 changes: 2 additions & 2 deletions docs/Coherence_Lab_Part_2.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ <h2 class="anchored" data-anchor-id="compute-the-coherence">Compute the coherenc
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>Yf <span class="op">=</span> <span class="st">"SOMETHING"</span> <span class="co"># Compute Fourier transform of y for each trial</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Auto- and cross-spectra.</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>Sxx <span class="op">=</span> <span class="st">"SOMETHING"</span> <span class="co"># Spectrum of E1 trials</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>Syy <span class="op">=</span> <span class="st">"SOMETHING"</span> <span class="co"># ... and E2 trials</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>Sxx <span class="op">=</span> <span class="st">"SOMETHING"</span> <span class="co"># Spectrum of x trials</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>Syy <span class="op">=</span> <span class="st">"SOMETHING"</span> <span class="co"># ... and y trials</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a>Sxy <span class="op">=</span> <span class="st">"SOMETHING"</span> <span class="co"># ... and the cross spectrum</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a><span class="co"># Trial average.</span></span>
Expand Down
27 changes: 12 additions & 15 deletions docs/Coherence_Lab_Part_3.html
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ <h3 class="anchored" data-anchor-id="make-a-function-to-thin-a-spike-train.">Mak
<section id="compare-the-spike-field-coherence-for-original-and-thinned-data." class="level3">
<h3 class="anchored" data-anchor-id="compare-the-spike-field-coherence-for-original-and-thinned-data.">Compare the spike-field coherence for original and thinned data.</h3>
<div id="cell-13" class="cell">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>[cohr, f, SYY, SNN, SYN] <span class="op">=</span> coherence(n,y,t) <span class="co"># Coherence for original spike train.</span></span>
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>[cohr, f, SYY, SNN, SYN] <span class="op">=</span> <span class="st">"SOMETHING"</span> <span class="co"># Coherence for original spike train.</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>plt.clf()</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a>plt.plot(f,cohr, <span class="st">'b'</span>)</span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>[cohr, f, SYY, SNN, SYN] <span class="op">=</span> coherence(thinned_spike_train(n,<span class="fl">0.5</span>),y,t) <span class="co"># ... and for the thinned spike train.</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>[cohr, f, SYY, SNN, SYN] <span class="op">=</span> <span class="st">"SOMETHING"</span> <span class="co"># ... and for the thinned spike train.</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a>plt.plot(f,cohr, <span class="st">'r'</span>)</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a>plt.xlim([<span class="dv">40</span>, <span class="dv">50</span>])</span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a>plt.legend([<span class="st">'Original'</span>, <span class="st">'Thinned'</span>])</span>
Expand All @@ -300,19 +300,16 @@ <h3 class="anchored" data-anchor-id="compare-the-spike-field-coherence-for-origi
<section id="repeat-for-different-thinning-factors." class="level3">
<h3 class="anchored" data-anchor-id="repeat-for-different-thinning-factors.">Repeat for different thinning factors.</h3>
<div id="cell-15" class="cell">
<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>plt.figure(<span class="dv">1</span>)<span class="op">;</span> plt.clf()<span class="op">;</span> plt.figure(<span class="dv">2</span>)<span class="op">;</span> plt.clf()</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>counter<span class="op">=</span><span class="dv">1</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> thinner <span class="kw">in</span> np.arange(<span class="dv">0</span>,<span class="dv">1</span>,<span class="fl">0.25</span>):</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> thinned <span class="op">=</span> thinned_spike_train(n,thinner)</span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> [cohr, f, SYY, SNN, SYN] <span class="op">=</span> coherence(thinned,y,t) <span class="co"># ... and for the thinned spike train.</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a> plt.figure(<span class="dv">1</span>)</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a> plt.plot(f,cohr,label<span class="op">=</span><span class="bu">str</span>(thinner))</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a>plt.figure(<span class="dv">1</span>)</span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a>plt.xlim([<span class="dv">40</span>, <span class="dv">50</span>])</span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a>plt.legend()</span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a>plt.xlabel(<span class="st">'Frequency [Hz]'</span>)</span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a>plt.ylabel(<span class="st">'Coherence'</span>)<span class="op">;</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="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>plt.figure()<span class="op">;</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> thin_factor <span class="kw">in</span> <span class="st">"SOMETHING</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a><span class="er"> thinned = "SOMETHING" # Make the thinned spike train</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> [cohr, f, SYY, SNN, SYN] <span class="op">=</span><span class="st">"SOMETHING"</span> <span class="co"># ... and compute the coherence</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> plt.plot(f,cohr,label<span class="op">=</span><span class="bu">str</span>(thin_factor)) <span class="co"># </span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a>plt.xlim([<span class="dv">40</span>, <span class="dv">50</span>])</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a>plt.legend()</span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a>plt.xlabel(<span class="st">'Frequency [Hz]'</span>)</span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a>plt.ylabel(<span class="st">'Coherence'</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<hr>
</section>
Expand Down
Loading

0 comments on commit bfcbefb

Please sign in to comment.