jupyter files
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Output after training: [[ 6.55109972e-03 9.93684857e-01 9.93925710e-01 6.62304973e-03]\n",
|
||||
" [ 1.71082162e-03 9.97516440e-01 9.97766376e-01 1.82685927e-03]\n",
|
||||
" [ 2.05800960e-03 9.98268211e-01 9.97548919e-01 1.77362990e-03]\n",
|
||||
" [ 5.35659849e-04 9.99320839e-01 9.99100767e-01 4.87503198e-04]]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"#sigmoid\n",
|
||||
"def nonlin(x, deriv=False):\n",
|
||||
" if (deriv==True):\n",
|
||||
" return x*(1-x)\n",
|
||||
" return 1/(1+np.exp(-x))\n",
|
||||
"\n",
|
||||
"#input data\n",
|
||||
"x=np.array([[0,0,1],[0,1,1],[1,0,1],[1,1,1]])\n",
|
||||
"\n",
|
||||
"#output data\n",
|
||||
"y=np.array([0,1,1,0]).T\n",
|
||||
"\n",
|
||||
"#seed random numbers to make calculation\n",
|
||||
"np.random.seed(1)\n",
|
||||
"\n",
|
||||
"#initialize weights with mean=0\n",
|
||||
"syn0=2*np.random.random((3,4))-1\n",
|
||||
"\n",
|
||||
"for iter in range(10000):\n",
|
||||
" #forward propogation\n",
|
||||
" l0=x\n",
|
||||
" l1=nonlin(np.dot(l0,syn0))\n",
|
||||
" l1_error=y-l1\n",
|
||||
" #multiply error by slope of sigmoid at values of l1\n",
|
||||
" l1_delta=l1_error*nonlin(l1,True)\n",
|
||||
" #update weights\n",
|
||||
" syn0+=np.dot(l0.T, l1_delta)\n",
|
||||
" \n",
|
||||
"print(\"Output after training: \",l1 )"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user