Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
Alluxia-F committed Jul 12, 2017
1 parent 249d4b2 commit da8e6ee
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 115 deletions.
29 changes: 19 additions & 10 deletions Chapter 5/5. Gradient Descent With Multiple Outputs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"cells": [
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"execution_count": 27,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Create an empty network with multiple outputs\n",
Expand All @@ -22,14 +24,14 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Prediction: [ 0.195 0.13 0.585]\n",
"Prediction:[ 0.195 0.13 0.585]\n",
"Error: [ 0.009025 0.7569 0.235225]\n",
"Delta: [ 0.095 -0.87 0.485]\n",
"weights_delta:[ 0.06175 -0.5655 0.31525]\n"
Expand All @@ -47,7 +49,7 @@
"true=[hurt[0],win[0],sad[0]]\n",
"\n",
"pred=nerual_network(inputs,weights)\n",
"print 'Prediction: '+str(pred)\n",
"print 'Prediction:'+str(pred)\n",
"error=(pred-true)**2\n",
"print 'Error: '+str(error)\n",
"delta=pred-true\n",
Expand All @@ -71,11 +73,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"execution_count": 29,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-29-a434de873d6d>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-29-a434de873d6d>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m Note: There are so many mistakes on the diagram\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"Note: There are so many mistakes on the diagram"
]
Expand Down
136 changes: 136 additions & 0 deletions Chapter 5/6. Gradient Descent with Multiple Inputs & Outputs.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 215,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Create an empty network with multiple inputs & outputs\n",
"def nerual_network(inputs,weights):\n",
" pred=mat_mul(inputs,weights) # Matrix multiplication\n",
" return pred\n",
"\n",
"def mat_mul(inputs,weights):\n",
" assert len(inputs)==len(weights)\n",
" output=[]\n",
" for index,weight in enumerate(weights):\n",
" output.append(w_sum(inputs,weight))\n",
" return output\n",
"\n",
"def w_sum(inputs,weights):\n",
" sums=0\n",
" for i,v in enumerate(inputs):\n",
" sums+=inputs[i]*weights[i]\n",
" return sums\n"
]
},
{
"cell_type": "code",
"execution_count": 216,
"metadata": {},
"outputs": [],
"source": [
"# Data information\n",
"\n",
"toes=[8.5,9.5,9.9,9.0]\n",
"wlrec=[0.65,0.8,0.8,0.9]\n",
"nfans=[1.2,1.3,0.5,1.0]\n",
"\n",
"hurt=[0.1,0.0,0.0,0.1]\n",
"win=[1,1,0,1]\n",
"sad=[0.1,0.0,0.1,0.2]\n",
"\n",
"inputs=[toes[0],wlrec[0],nfans[0]]\n",
"true=[hurt[0],win[0],sad[0]]\n",
"\n",
"weights=[[0.1,0.1,-0.3],[0.1,0.2,0.0],[0.0,1.3,0.1]]\n",
"alpha=0.01"
]
},
{
"cell_type": "code",
"execution_count": 217,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Prediction:[ 0.555 0.98 0.965]\n",
"Error:[ 2.07025000e-01 4.00000000e-04 7.48225000e-01]\n",
"Delta:[ 0.455 -0.02 0.865]\n",
"Weights_Delta: [[ 3.8675 -0.17 7.3525 ]\n",
" [ 0.29575 -0.013 0.56225]\n",
" [ 0.546 -0.024 1.038 ]]\n"
]
}
],
"source": [
"# Run the model and make the prediciton\n",
"import numpy as np\n",
"pred=nerual_network(inputs,weights)\n",
"pred=np.array(pred)\n",
"weights=np.array(weights)\n",
"inputs=np.array(inputs)\n",
"print 'Prediction:'+str(pred)\n",
"true=np.array(true)\n",
"error=(pred-true)**2\n",
"print 'Error:'+str((error))\n",
"delta=pred-true\n",
"print 'Delta:'+str(delta)\n",
"\n",
"weights_delta=np.zeros(weights.shape)\n",
"for i,x in np.ndenumerate(inputs):\n",
" for j,v in np.ndenumerate(delta):\n",
" weights_delta[i][j]=inputs[i]*delta[j]\n",
"print 'Weights_Delta: '+str(weights_delta)\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": 218,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0.061325 0.1017 -0.373525 ]\n",
" [ 0.0970425 0.20013 -0.0056225]\n",
" [-0.00546 1.30024 0.08962 ]]\n"
]
}
],
"source": [
"# Update the weights\n",
"weights-=alpha*weights_delta\n",
"print weights"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
105 changes: 0 additions & 105 deletions Chapter 5/Gradient Descent With Multiple Outputs.ipynb

This file was deleted.

0 comments on commit da8e6ee

Please sign in to comment.