Skip to content

Commit

Permalink
small edits to Analyze Rhythms Lab 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Kramer committed Oct 29, 2024
1 parent 531acd3 commit b37a33d
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 33 deletions.
Binary file modified .DS_Store
Binary file not shown.
14 changes: 7 additions & 7 deletions Analyzing_Rhythms_Lab_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@
"metadata": {},
"outputs": [],
"source": [
"x = EEG\n",
"xf = np.fft.fft(x) # Compute Fourier transform of x\n",
"Sxx = 2 * dt ** 2 / T * (xf * xf.conj()) # Compute spectrum\n",
"Sxx = Sxx[0:int(N / 2)].real # Ignore negative frequencies"
"x = EEG\n",
"X = np.fft.fft(x) # Compute Fourier transform of x\n",
"Sxx = \"SOMETHING\" # Compute spectrum\n",
"Sxx = Sxx[0:int(N / 2)].real # Ignore negative frequencies"
]
},
{
Expand Down Expand Up @@ -338,8 +338,8 @@
"metadata": {},
"outputs": [],
"source": [
"xf_tapered = [???] # Compute Fourier transform of x.\n",
"Sxx_tapered = [???] # Compute the spectrum,\n",
"xf_tapered = \"SOMETHING\" # Compute Fourier transform of x.\n",
"Sxx_tapered = \"SOMETHING\" # Compute the spectrum,\n",
"Sxx_tapered = np.real(Sxx_tapered[:int(N / 2)]) # ... and ignore negative frequencies.\n",
"\n",
"plt.figure()\n",
Expand Down Expand Up @@ -408,7 +408,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions docs/Analyzing_Rhythms_Lab_1.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>

<meta charset="utf-8">
<meta name="generator" content="quarto-1.5.56">
<meta name="generator" content="quarto-1.5.57">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

Expand Down Expand Up @@ -279,10 +279,10 @@ <h2 class="anchored" data-anchor-id="compute-the-spectrum-by-hand">Compute the s
<section id="compute-the-power-spectrum-using-the-fft-function." class="level2">
<h2 class="anchored" data-anchor-id="compute-the-power-spectrum-using-the-fft-function.">Compute the power spectrum using the FFT function.</h2>
<div id="cell-20" 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>x <span class="op">=</span> EEG</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>xf <span class="op">=</span> np.fft.fft(x) <span class="co"># Compute Fourier transform of x</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>Sxx <span class="op">=</span> <span class="dv">2</span> <span class="op">*</span> dt <span class="op">**</span> <span class="dv">2</span> <span class="op">/</span> T <span class="op">*</span> (xf <span class="op">*</span> xf.conj()) <span class="co"># Compute spectrum</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a>Sxx <span class="op">=</span> Sxx[<span class="dv">0</span>:<span class="bu">int</span>(N <span class="op">/</span> <span class="dv">2</span>)].real <span class="co"># Ignore negative frequencies</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>x <span class="op">=</span> EEG</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>X <span class="op">=</span> np.fft.fft(x) <span class="co"># Compute Fourier transform of x</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>Sxx <span class="op">=</span> <span class="st">"SOMETHING"</span> <span class="co"># Compute spectrum</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a>Sxx <span class="op">=</span> Sxx[<span class="dv">0</span>:<span class="bu">int</span>(N <span class="op">/</span> <span class="dv">2</span>)].real <span class="co"># Ignore negative frequencies</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Define the frequency axis</p>
<div id="cell-22" class="cell">
Expand Down Expand Up @@ -330,8 +330,8 @@ <h2 class="anchored" data-anchor-id="apply-hanning-taper">Apply Hanning taper</h
</div>
<p>Apply the Hanning taper and look at the spectrum.</p>
<div id="cell-33" class="cell">
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>xf_tapered <span class="op">=</span> [???] <span class="co"># Compute Fourier transform of x.</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>Sxx_tapered <span class="op">=</span> [???] <span class="co"># Compute the spectrum,</span></span>
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>xf_tapered <span class="op">=</span> <span class="st">"SOMETHING"</span> <span class="co"># Compute Fourier transform of x.</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>Sxx_tapered <span class="op">=</span> <span class="st">"SOMETHING"</span> <span class="co"># Compute the spectrum,</span></span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a>Sxx_tapered <span class="op">=</span> np.real(Sxx_tapered[:<span class="bu">int</span>(N <span class="op">/</span> <span class="dv">2</span>)]) <span class="co"># ... and ignore negative frequencies.</span></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a>plt.figure()</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/Analyzing_Rhythms_Lab_2a.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>

<meta charset="utf-8">
<meta name="generator" content="quarto-1.5.56">
<meta name="generator" content="quarto-1.5.57">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

Expand Down
2 changes: 1 addition & 1 deletion docs/Analyzing_Rhythms_Lab_2b.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>

<meta charset="utf-8">
<meta name="generator" content="quarto-1.5.56">
<meta name="generator" content="quarto-1.5.57">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

Expand Down
4 changes: 2 additions & 2 deletions docs/Backpropagation.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>

<meta charset="utf-8">
<meta name="generator" content="quarto-1.5.56">
<meta name="generator" content="quarto-1.5.57">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

Expand Down Expand Up @@ -228,7 +228,7 @@
}

// Store cell data
globalThis.qpyodideCellDetails = [{"id":1,"options":{"warning":"true","message":"true","fig-cap":"","dpi":72,"autorun":"","fig-height":5,"output":"true","fig-width":7,"results":"markup","read-only":"false","comment":"","out-height":"","label":"","out-width":"700px","context":"interactive","classes":""},"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd"},{"id":2,"options":{"warning":"true","message":"true","fig-cap":"","dpi":72,"autorun":"","fig-height":5,"output":"true","fig-width":7,"results":"markup","read-only":"false","comment":"","out-height":"","label":"","out-width":"700px","context":"interactive","classes":""},"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":{"warning":"true","message":"true","fig-cap":"","dpi":72,"autorun":"","fig-height":5,"output":"true","fig-width":7,"results":"markup","read-only":"false","comment":"","out-height":"","label":"","out-width":"700px","context":"interactive","classes":""},"code":"print(np.transpose([in_true, out_true]))"},{"id":4,"options":{"warning":"true","message":"true","fig-cap":"","dpi":72,"autorun":"","fig-height":5,"output":"true","fig-width":7,"results":"markup","read-only":"false","comment":"","out-height":"","label":"","out-width":"700px","context":"interactive","classes":""},"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":{"warning":"true","message":"true","fig-cap":"","dpi":72,"autorun":"","fig-height":5,"output":"true","fig-width":7,"results":"markup","read-only":"false","comment":"","out-height":"","label":"","out-width":"700px","context":"interactive","classes":""},"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":{"context":"interactive","comment":"","message":"true","read-only":"false","dpi":72,"label":"","fig-height":5,"output":"true","fig-width":7,"fig-cap":"","autorun":"","warning":"true","results":"markup","out-height":"","classes":"","out-width":"700px"},"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd","id":1},{"options":{"context":"interactive","comment":"","message":"true","read-only":"false","dpi":72,"label":"","fig-height":5,"output":"true","fig-width":7,"fig-cap":"","autorun":"","warning":"true","results":"markup","out-height":"","classes":"","out-width":"700px"},"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":2},{"options":{"context":"interactive","comment":"","message":"true","read-only":"false","dpi":72,"label":"","fig-height":5,"output":"true","fig-width":7,"fig-cap":"","autorun":"","warning":"true","results":"markup","out-height":"","classes":"","out-width":"700px"},"code":"print(np.transpose([in_true, out_true]))","id":3},{"options":{"context":"interactive","comment":"","message":"true","read-only":"false","dpi":72,"label":"","fig-height":5,"output":"true","fig-width":7,"fig-cap":"","autorun":"","warning":"true","results":"markup","out-height":"","classes":"","out-width":"700px"},"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":4},{"options":{"context":"interactive","comment":"","message":"true","read-only":"false","dpi":72,"label":"","fig-height":5,"output":"true","fig-width":7,"fig-cap":"","autorun":"","warning":"true","results":"markup","out-height":"","classes":"","out-width":"700px"},"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])","id":5}];


</script>
Expand Down
Loading

0 comments on commit b37a33d

Please sign in to comment.