Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions ANDNOT logic functions using numpy neuron..ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Y is initiallised [[0]\n",
" [0]\n",
" [0]\n",
" [0]]\n",
"Calculated y [[0.]\n",
" [0.]\n",
" [0.]\n",
" [0.]]\n",
"Expected Target t [[0]\n",
" [1]\n",
" [0]\n",
" [0]]\n",
"MODEL IS NOT TRAINED\n",
"Enter New Theta : 1\n",
"Enter Weight : 1\n",
"Enter Weight : -1\n",
"Y is initiallised [ 0. 1. -1. 0.]\n",
"Calculated y [[0.]\n",
" [1.]\n",
" [0.]\n",
" [0.]]\n",
"Expected Target t [[0]\n",
" [1]\n",
" [0]\n",
" [0]]\n",
"MODEL IS TRAINED \n",
"\n",
"Output : \n",
" [[0.]\n",
" [1.]\n",
" [0.]\n",
" [0.]]\n",
"\n",
"weights : [ 1. -1.] \n",
"\n",
"theta : 1\n"
]
}
],
"source": [
"import numpy as np\n",
"x=np.array([[1,1],[1,0],[0,1],[0,0]])\n",
"t=np.array([[0],[1],[0],[0]])\n",
"w=np.array([[0],[0]])\n",
"theta=1\n",
"yin=np.zeros(shape=(4,1))\n",
"y=np.zeros(shape=(4,1))\n",
"yin=np.dot(x,w)\n",
"i=0\n",
"found=0\n",
"while(found==0):\n",
" i=0\n",
" yin=np.dot(x,w)\n",
" print(\"Y is initiallised\",yin)\n",
" while(i<4):\n",
" if yin[i]>=theta:\n",
" y[i]=1 \n",
" i=i+1\n",
" else:\n",
" y[i]=0\n",
" i=i+1\n",
" print(\"Calculated y\",y)\n",
" print(\"Expected Target t\",t)\n",
" if (y==t).all():\n",
" print(\"MODEL IS TRAINED \")\n",
" print(\"\\nOutput : \\n\",y)\n",
" print(\"\\nweights : \",w,\"\\n\")\n",
" print(\"theta : \",theta)\n",
" found=1\n",
" else:\n",
" print(\"MODEL IS NOT TRAINED\")\n",
" w=np.zeros(shape=(0,0))\n",
" theta=int(input(\"Enter New Theta : \"))\n",
" for k in range(int(2)):\n",
" w1=int(input(\"Enter Weight : \"))\n",
" w=np.append(w,w1)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"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.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
159 changes: 159 additions & 0 deletions ANDlogic functions using numpy neuron..ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Y is initiallised [[0]\n",
" [0]\n",
" [0]\n",
" [0]]\n",
"Calculated y [[0.]\n",
" [0.]\n",
" [0.]\n",
" [0.]]\n",
"Expected Target t [[1]\n",
" [0]\n",
" [0]\n",
" [0]]\n",
"Calculated y [[0.]\n",
" [0.]\n",
" [0.]\n",
" [0.]]\n",
"Expected Target t [[1]\n",
" [0]\n",
" [0]\n",
" [0]]\n",
"Calculated y [[0.]\n",
" [0.]\n",
" [0.]\n",
" [0.]]\n",
"Expected Target t [[1]\n",
" [0]\n",
" [0]\n",
" [0]]\n",
"Calculated y [[0.]\n",
" [0.]\n",
" [0.]\n",
" [0.]]\n",
"Expected Target t [[1]\n",
" [0]\n",
" [0]\n",
" [0]]\n",
"MODEL IS NOT TRAINED\n",
"Enter New Theta : 2\n",
"Enter Weight : 1\n",
"Enter Weight : 1\n",
"Y is initiallised [2. 1. 1. 0.]\n",
"Calculated y [[1.]\n",
" [0.]\n",
" [0.]\n",
" [0.]]\n",
"Expected Target t [[1]\n",
" [0]\n",
" [0]\n",
" [0]]\n",
"Calculated y [[1.]\n",
" [0.]\n",
" [0.]\n",
" [0.]]\n",
"Expected Target t [[1]\n",
" [0]\n",
" [0]\n",
" [0]]\n",
"Calculated y [[1.]\n",
" [0.]\n",
" [0.]\n",
" [0.]]\n",
"Expected Target t [[1]\n",
" [0]\n",
" [0]\n",
" [0]]\n",
"MODEL IS TRAINED \n",
"\n",
"Output : \n",
" [[1.]\n",
" [0.]\n",
" [0.]\n",
" [0.]]\n",
"\n",
"weights : [1. 1.] \n",
"\n",
"theta : 2\n"
]
}
],
"source": [
"import numpy as np\n",
"x=np.array([[1,1],[1,0],[0,1],[0,0]])\n",
"t=np.array([[1],[0],[0],[0]])\n",
"w=np.array([[0],[0]])\n",
"theta=1\n",
"yin=np.zeros(shape=(4,1))\n",
"y=np.zeros(shape=(4,1))\n",
"yin=np.dot(x,w)\n",
"i=0\n",
"found=0\n",
"while(found==0):\n",
" i=0\n",
" yin=np.dot(x,w)\n",
" print(\"Y is initiallised\",yin)\n",
" while(i<4):\n",
" if yin[i]>=theta:\n",
" y[i]=1 \n",
" i=i+1\n",
" else:\n",
" y[i]=0\n",
" i=i+1\n",
" print(\"Calculated y\",y)\n",
" print(\"Expected Target t\",t)\n",
" if (y==t).all():\n",
" print(\"MODEL IS TRAINED \")\n",
" print(\"\\nOutput : \\n\",y)\n",
" print(\"\\nweights : \",w,\"\\n\")\n",
" print(\"theta : \",theta)\n",
" found=1\n",
" else:\n",
" print(\"MODEL IS NOT TRAINED\")\n",
" w=np.zeros(shape=(0,0))\n",
" theta=int(input(\"Enter New Theta : \"))\n",
" for k in range(int(2)):\n",
" w1=int(input(\"Enter Weight : \"))\n",
" w=np.append(w,w1)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"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.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
74 changes: 74 additions & 0 deletions BFS .ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"enter the number you want to search-5\n",
"[1, 2, 3, 5]\n"
]
}
],
"source": [
"def bfs(graph,start,search):\n",
" explored = []\n",
" queue = [start]\n",
" found = 1\n",
" while found:\n",
" node = queue.pop(0)\n",
" if(node == search):\n",
" found = 0\n",
" if node not in explored:\n",
" explored.append(node)\n",
" neighbours = graph[node]\n",
" for neighbour in neighbours:\n",
" queue.append(neighbour)\n",
" print(explored)\n",
"\n",
"search = int(input(\"enter the number you want to search-\"))\n",
"graph = {1: [2, 3, 5],\n",
" 2: [1,4, 5],\n",
" 3: [1, 6, 7],\n",
" 4: [2],\n",
" 5: [1, 2,4],\n",
" 6: [3],\n",
" 7: [3]}\n",
"bfs(graph,1,search)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"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.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading