Skip to content

Commit

Permalink
+ backpropagation edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Kramer committed Oct 3, 2024
1 parent 5c1afef commit b8eb222
Show file tree
Hide file tree
Showing 17 changed files with 18 additions and 16 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion Backpropagation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion Perceptron.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
Binary file removed Slides/.DS_Store
Binary file not shown.
Binary file added Slides/Backpropagation_1.pdf
Binary file not shown.
Binary file renamed Data/.DS_Store → _extensions/.DS_Store
Binary file not shown.
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 = [{"options":{"results":"markup","fig-height":5,"classes":"","output":"true","warning":"true","message":"true","autorun":"","read-only":"false","comment":"","fig-cap":"","dpi":72,"context":"interactive","label":"","out-width":"700px","out-height":"","fig-width":7},"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd","id":1},{"options":{"results":"markup","fig-height":5,"classes":"","output":"true","warning":"true","message":"true","autorun":"","read-only":"false","comment":"","fig-cap":"","dpi":72,"context":"interactive","label":"","out-width":"700px","out-height":"","fig-width":7},"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":{"results":"markup","fig-height":5,"classes":"","output":"true","warning":"true","message":"true","autorun":"","read-only":"false","comment":"","fig-cap":"","dpi":72,"context":"interactive","label":"","out-width":"700px","out-height":"","fig-width":7},"code":"print(np.transpose([in_true, out_true]))","id":3},{"options":{"results":"markup","fig-height":5,"classes":"","output":"true","warning":"true","message":"true","autorun":"","read-only":"false","comment":"","fig-cap":"","dpi":72,"context":"interactive","label":"","out-width":"700px","out-height":"","fig-width":7},"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 = w[0]*s0 # ... activity of first neuron,\n s1 = sigmoid(x1) # ... output of first neuron,\n x2 = w[1]*s1 # ... activity of second neuron,\n s2 = sigmoid(x2) # ... output of second neuron,\n out= w[2] # Output of neural network.\n return out,s1,s2","id":4},{"options":{"results":"markup","fig-height":5,"classes":"","output":"true","warning":"true","message":"true","autorun":"","read-only":"false","comment":"","fig-cap":"","dpi":72,"context":"interactive","label":"","out-width":"700px","out-height":"","fig-width":7},"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 #Step 2. Calculate feedforward solution to get output.\n \n #Step 3. 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}];
globalThis.qpyodideCellDetails = [{"code":"import numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd","options":{"classes":"","out-width":"700px","warning":"true","fig-width":7,"context":"interactive","label":"","results":"markup","autorun":"","output":"true","fig-height":5,"out-height":"","dpi":72,"comment":"","message":"true","fig-cap":"","read-only":"false"},"id":1},{"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":{"classes":"","out-width":"700px","warning":"true","fig-width":7,"context":"interactive","label":"","results":"markup","autorun":"","output":"true","fig-height":5,"out-height":"","dpi":72,"comment":"","message":"true","fig-cap":"","read-only":"false"},"id":2},{"code":"print(np.transpose([in_true, out_true]))","options":{"classes":"","out-width":"700px","warning":"true","fig-width":7,"context":"interactive","label":"","results":"markup","autorun":"","output":"true","fig-height":5,"out-height":"","dpi":72,"comment":"","message":"true","fig-cap":"","read-only":"false"},"id":3},{"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 = w[0]*s0 # ... activity of first neuron,\n s1 = sigmoid(x1) # ... output of first neuron,\n x2 = w[1]*s1 # ... activity of second neuron,\n s2 = sigmoid(x2) # ... output of second neuron,\n out= w[2] # Output of neural network.\n return out,s1,s2","options":{"classes":"","out-width":"700px","warning":"true","fig-width":7,"context":"interactive","label":"","results":"markup","autorun":"","output":"true","fig-height":5,"out-height":"","dpi":72,"comment":"","message":"true","fig-cap":"","read-only":"false"},"id":4},{"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 #Step 2. Calculate feedforward solution to get output.\n \n #Step 3. 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":{"classes":"","out-width":"700px","warning":"true","fig-width":7,"context":"interactive","label":"","results":"markup","autorun":"","output":"true","fig-height":5,"out-height":"","dpi":72,"comment":"","message":"true","fig-cap":"","read-only":"false"},"id":5}];


</script>
Expand Down
Loading

0 comments on commit b8eb222

Please sign in to comment.