Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jizhang02 committed Aug 26, 2024
1 parent 4fc7ea1 commit 51697e1
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion deep_learning_from_scratch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,63 @@
"## Perceptron"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### What is a perceptron\n",
"\n",
"![A perceptron](./figures/dlscratch_perceptron.png) \n",
"$\n",
"y = \n",
"\\begin{cases} \n",
"0 & \\text{if } w_1 x_1 + w_2 x_2 \\leq \\theta, \\\\\n",
"1 & \\text{if } w_1 x_1 + w_2 x_2 > \\theta.\n",
"\\end{cases}\n",
"$\n",
"$x$ is input signal, $y$ is output signal, $w$ is weight, $\\theta$ is threshold.\n",
"\n",
"### Simple logic circuit\n",
"\n",
"![AND gate](./figures/dlscratch_andgate.png) ![NOTAND gate](./figures/dlscratch_notandgate.png) ![OR gate](./figures/dlscratch_orgate.png)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0, 0) -> 0\n",
"(1, 0) -> 0\n",
"(0, 1) -> 0\n",
"(1, 1) -> 1\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"\n",
"def AND(x1, x2):\n",
" x = np.array([x1, x2])\n",
" w = np.array([0.5, 0.5])\n",
" b = -0.7\n",
" tmp = np.sum(w*x) + b\n",
" if tmp <= 0:\n",
" return 0\n",
" else:\n",
" return 1\n",
"\n",
"if __name__ == '__main__':\n",
" for xs in [(0, 0), (1, 0), (0, 1), (1, 1)]:\n",
" y = AND(xs[0], xs[1])\n",
" print(str(xs) + \" -> \" + str(y))"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -69,8 +126,27 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.11.6 ('base')",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
},
"vscode": {
"interpreter": {
"hash": "d0af3871f74fa798a0a222812f3db7ca3ddb43c51379edde28baf2323a73ac20"
}
}
},
"nbformat": 4,
Expand Down
Binary file added figures/dlscratch_andgate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figures/dlscratch_notandgate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figures/dlscratch_orgate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figures/dlscratch_perceptron.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 51697e1

Please sign in to comment.