From b01051843b1af8b29886ac162b90dbcf148c2601 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Fri, 24 Jul 2020 21:51:58 +0900 Subject: [PATCH 01/60] Initial commit --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d80698 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Python_Toolbox +My personal toolbox that contains my daily python tools for datascience and machinelearning From 8f7f0872910922e8c0388bdcb18af59a60ff4973 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:07:26 +0900 Subject: [PATCH 02/60] Update README.md --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 0d80698..e3f4fd4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,23 @@ # Python_Toolbox My personal toolbox that contains my daily python tools for datascience and machinelearning + +## 1. Basic Structure +1. Print +2. Variable (Integer, string) +3. Function +4. Method +5. Formatting +6. List and Tuple +7. Dictionary +8. Set +9. Collection +10. Lambda Function +11. Copy + +## 2. Standard Modules +1. math +2. statistics +3. time +4. calendar +5. random +6. sys From 6b3a1d36a03ca41760d2c3f9cd1ccde5d0f1ecb3 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:09:58 +0900 Subject: [PATCH 03/60] Update README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e3f4fd4..03cb5fc 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ My personal toolbox that contains my daily python tools for datascience and mach ## 1. Basic Structure 1. Print -2. Variable (Integer, string) +2. Variable (Integer, String) 3. Function 4. Method 5. Formatting @@ -11,13 +11,13 @@ My personal toolbox that contains my daily python tools for datascience and mach 7. Dictionary 8. Set 9. Collection -10. Lambda Function -11. Copy + 10. Lambda Function + 11. Copy ## 2. Standard Modules -1. math -2. statistics -3. time -4. calendar -5. random -6. sys +1. Random +2. Time +3. Calendar +4. Math +5. Statistics +6. Sys From aeeb8023dfb573b4adc8728f97c9b2c5f0f74d88 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:10:35 +0900 Subject: [PATCH 04/60] Update README.md --- README.md | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 03cb5fc..a6baa47 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,10 @@ My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure -1. Print -2. Variable (Integer, String) -3. Function -4. Method -5. Formatting -6. List and Tuple -7. Dictionary -8. Set -9. Collection - 10. Lambda Function - 11. Copy +1. Print 2. Variable (Integer, String) 3. Function +4. Method 5. Formatting 6. List and Tuple +7. Dictionary 8. Set 9. Collection +10. Lambda Function 11. Copy ## 2. Standard Modules 1. Random From 8d0f1ab9bbea6fc53200b39b6e4e6b414961b2c9 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:11:54 +0900 Subject: [PATCH 05/60] Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index a6baa47..b71adc9 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,15 @@ My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure +|제목|내용|설명|설명| +|------|---|---|---| +|테스트1|테스트2|테스트3|테스트3| +|테스트1|테스트2|테스트3|테스트3| +|테스트1|테스트2|테스트3|테스트3| +|테스트1|테스트2|테스트3|테스트3| +|테스트1|테스트2|테스트3|테스트3| +|테스트1|테스트2|테스트3|테스트3| + 1. Print 2. Variable (Integer, String) 3. Function 4. Method 5. Formatting 6. List and Tuple 7. Dictionary 8. Set 9. Collection From 98de2a96cb35fc66a131555ba34e92c31ceec939 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:13:12 +0900 Subject: [PATCH 06/60] Update README.md --- README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b71adc9..edc4e62 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,12 @@ My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure -|제목|내용|설명|설명| -|------|---|---|---| -|테스트1|테스트2|테스트3|테스트3| -|테스트1|테스트2|테스트3|테스트3| -|테스트1|테스트2|테스트3|테스트3| -|테스트1|테스트2|테스트3|테스트3| -|테스트1|테스트2|테스트3|테스트3| -|테스트1|테스트2|테스트3|테스트3| +|1|테스트2|7|테스트3| +|2|테스트2|8|테스트3| +|3|테스트2|9|테스트3| +|4|테스트2|10|테스트3| +|5|테스트2|11|테스트3| +|6|테스트2| |테스트3| 1. Print 2. Variable (Integer, String) 3. Function 4. Method 5. Formatting 6. List and Tuple From 3bb349ca88131813afcbcede211e447e259ef7ec Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:13:29 +0900 Subject: [PATCH 07/60] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index edc4e62..18d0429 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure +|------|---|---|---| |1|테스트2|7|테스트3| |2|테스트2|8|테스트3| |3|테스트2|9|테스트3| From 90578b4fd01c66a5483ac509f0141d2eef34007a Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:13:46 +0900 Subject: [PATCH 08/60] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 18d0429..a9add6a 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure +|제목|내용|설명|설명| |------|---|---|---| |1|테스트2|7|테스트3| |2|테스트2|8|테스트3| From 89581aac3ac8254284165d53ce6bf00bb94563c7 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:15:10 +0900 Subject: [PATCH 09/60] Update README.md --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a9add6a..541bddd 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,13 @@ My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure -|제목|내용|설명|설명| +|1|Print|7|Dictionary| |------|---|---|---| -|1|테스트2|7|테스트3| -|2|테스트2|8|테스트3| -|3|테스트2|9|테스트3| -|4|테스트2|10|테스트3| -|5|테스트2|11|테스트3| -|6|테스트2| |테스트3| +|2|Variable|8|Set| +|3|Function|9|Collection| +|4|Method|10|Lambda Function| +|5|Formatting|11|Copy| +|6|List and Tuple|12|| 1. Print 2. Variable (Integer, String) 3. Function 4. Method 5. Formatting 6. List and Tuple From 67b008f0666d8a38fdd4392e8fb5207165ba3aa1 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:16:51 +0900 Subject: [PATCH 10/60] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 541bddd..b55d2eb 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,9 @@ My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure -|1|Print|7|Dictionary| +|no.|Print|no.|Dictionary| |------|---|---|---| +|1|Print|7|Dictionary| |2|Variable|8|Set| |3|Function|9|Collection| |4|Method|10|Lambda Function| From 8ef74a9f10a44457841a1f9eb088cad897829696 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:18:43 +0900 Subject: [PATCH 11/60] Update README.md --- README.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b55d2eb..a570b4a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure -|no.|Print|no.|Dictionary| +|No.|Contents|no.|Contents| |------|---|---|---| |1|Print|7|Dictionary| |2|Variable|8|Set| @@ -11,15 +11,12 @@ My personal toolbox that contains my daily python tools for datascience and mach |5|Formatting|11|Copy| |6|List and Tuple|12|| -1. Print 2. Variable (Integer, String) 3. Function -4. Method 5. Formatting 6. List and Tuple -7. Dictionary 8. Set 9. Collection -10. Lambda Function 11. Copy - ## 2. Standard Modules -1. Random -2. Time -3. Calendar -4. Math -5. Statistics -6. Sys +|No.|Contents|no.|Contents| +|------|---|---|---| +|1|Random|7|| +|2|Time|8|| +|3|Calendar|9|| +|4|Math|10|| +|5|Statistics|11|| +|6|Sys|12|| From 8032a25c3c303c66b4c6dc99952290698c0abe65 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:19:14 +0900 Subject: [PATCH 12/60] Update README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a570b4a..c9bcd22 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure -|No.|Contents|no.|Contents| +|No.|Contents|No.|Contents| |------|---|---|---| |1|Print|7|Dictionary| |2|Variable|8|Set| @@ -12,11 +12,11 @@ My personal toolbox that contains my daily python tools for datascience and mach |6|List and Tuple|12|| ## 2. Standard Modules -|No.|Contents|no.|Contents| -|------|---|---|---| -|1|Random|7|| -|2|Time|8|| -|3|Calendar|9|| -|4|Math|10|| -|5|Statistics|11|| -|6|Sys|12|| +|No.|Contents| +|------|---| +|1|Random| +|2|Time| +|3|Calendar| +|4|Math| +|5|Statistics| +|6|Sys| From 458d418c84e0b1d0ff9962efbad913ece864cf07 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung Date: Tue, 28 Jul 2020 23:20:57 +0900 Subject: [PATCH 13/60] 20200728 --- 1_Basic_Structure.ipynb | 899 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 899 insertions(+) create mode 100644 1_Basic_Structure.ipynb diff --git a/1_Basic_Structure.ipynb b/1_Basic_Structure.ipynb new file mode 100644 index 0000000..44ff880 --- /dev/null +++ b/1_Basic_Structure.ipynb @@ -0,0 +1,899 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 1. Basic Structure\n", + "1. Print\n", + "2. Variable (Integer, string)\n", + "3. Function\n", + "4. Method\n", + "5. Formatting\n", + "6. List and Tuple\n", + "7. Dictionary\n", + "8. Set\n", + "9. Collection\n", + "10. Lambda Function\n", + "11. Copy" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1. Print" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12\n", + "1->2\n" + ] + } + ], + "source": [ + "a, b = 1, 2\n", + "print(a, b, sep = \"\") # Separator\n", + "print(a, b, sep = \"->\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12\n" + ] + } + ], + "source": [ + "print(a, end = '') # add after printing\n", + "print(b) ## default : newline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2. Variable\n", + "- Keyword can not be identifier \n", + "if, else, elif, for, while, break, continue \n", + "True, False, None \n", + "and, or, not, in \n", + "def, return, lambda, nonlocal, global \n", + "try, except, finally, raise \n", + "import, from, class \n", + "is, del, with, as, yield, assert, pass" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2-1) Integer\n", + "- 16 (hexadecimal) : 0x (0~9, a~f)\n", + "- 8 (octal) : 0o (0~7)\n", + "- 2 (binary) : 0b (0,1) " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0x14\n", + "0o24\n", + "0b10100\n" + ] + } + ], + "source": [ + "print(hex(20))\n", + "print(oct(20))\n", + "print(bin(20))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2-2) String" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello \"my\" world\n" + ] + } + ], + "source": [ + "# print(\"Hello \"my\" world\") # error\n", + "print('Hello \"my\" world')" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello\n", + "World\n", + "c:\\Desktop\\a.txt\n" + ] + } + ], + "source": [ + "# Escape Sequence\n", + "print(\"Hello\\nWorld\") ## \\n : newline\n", + "print(r\"c:\\Desktop\\a.txt\") ## raw" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5040\n" + ] + } + ], + "source": [ + "answer = 1 * 2 * 3 * 4 * \\ \n", + " 5 * 6 * 7\n", + "print(answer)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "97\n", + "d\n" + ] + } + ], + "source": [ + "# code\n", + "print(ord('a'))\n", + "print(chr(100))" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2.5\n", + "2\n" + ] + } + ], + "source": [ + "print(5/2)\n", + "print(5//2) # remove decimal part" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello2002\n" + ] + } + ], + "source": [ + "# print(\"Hello\" + 2020) # error\n", + "print(\"Hello\" + str(2002))" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n", + "6\n", + "5.7\n", + "123000\n" + ] + } + ], + "source": [ + "# round\n", + "print(int(5.67))\n", + "print(round(5.67))\n", + "print(round(5.67, 1))\n", + "print(round(123456, -3))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3. Function" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def calc():\n", + " pass\n", + "'''\n", + "# in C, Java\n", + "void calc()\n", + "{\n", + "}\n", + "'''" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 4. Method\n", + "- return BOOLEAN \n", + "isalpha, islower, isupper, isspace, isalnum, isdecimal, isdigit, isnumeric, isidentifier, isprintable" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "18\n", + "4\n", + "9\n", + "8\n", + "2\n" + ] + } + ], + "source": [ + "s = \"python programming\"\n", + "print(len(s))\n", + "print(s.find('o'))\n", + "print(s.rfind('o')) # rearfind\n", + "print(s.index('r'))\n", + "print(s.count('m'))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 5. Formatting\n", + "%d : integer \n", + "%f : float \n", + "%s : string \n", + "%c : char \n", + "%h : hexadecimal \n", + "%o : octal \n", + "%% : %" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "###100###\n", + "### 100###\n", + "### 100###\n", + "###100 ###\n", + "###100###\n" + ] + } + ], + "source": [ + "# formatting and sort\n", + "a = 100\n", + "print(\"###%d###\" % a)\n", + "print(\"###%5d###\" % a)\n", + "print(\"###%10d###\" % a)\n", + "print(\"###%-10d###\" % a)\n", + "print(\"###%1d###\" % a)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 3.141593\n", + "3.14159265\n", + " 3.14159\n", + " 3.14\n" + ] + } + ], + "source": [ + "pi = 3.14159265\n", + "print(\"%10f\" % pi)\n", + "print(\"%10.8f\" % pi)\n", + "print(\"%10.5f\" % pi)\n", + "print(\"%10.2f\" % pi)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a : 10, b : 20, c : 30\n", + "a : 10 , b : 20, c : 30.66 \n" + ] + } + ], + "source": [ + "print(\"a : {0}, b : {1}, c : {2}\".format(10,20,30))\n", + "print(\"a : {0:^10d}, b : {1:>5d}, c : {2:<8.2f}\".format(10,20,30.66))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 6. List and Tuple" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 4, 5, 6, 7]\n" + ] + } + ], + "source": [ + "# range remove\n", + "num = [0,1,2,3,4,5,6,7]\n", + "num[1:4] = [] # remove\n", + "print(num)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n" + ] + } + ], + "source": [ + "# list comprehension\n", + "nums = [2*n for n in range(1,11)]\n", + "print(nums)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 4, 100, 6, 8, 10, 12, 14, 16, 18, 20, 22]\n" + ] + } + ], + "source": [ + "# insert\n", + "nums.append(22)\n", + "nums.insert(2, 100) # (location, element) \n", + "print(nums)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "apple banana cat\n" + ] + } + ], + "source": [ + "# unpacking\n", + "tu = \"apple\", \"banana\", \"cat\"\n", + "a, b, c = tu\n", + "print(a, b, c)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 7. Dictionary" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "10\n", + "dict_keys(['a', 'b', 'c'])\n", + "dict_values([10, 20, 30])\n", + "dict_items([('a', 10), ('b', 20), ('c', 30)])\n" + ] + } + ], + "source": [ + "dic = {'a' : 10, 'b' : 20, 'c' : 30}\n", + "new_dic = {'d' : 40, 'e' : 50}\n", + "\n", + "print(dic['a']) # print value\n", + "print(dic.get('a'))\n", + "\n", + "print(dic.keys())\n", + "print(dic.values())\n", + "print(dic.items())" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'a': 10, 'b': 20, 'c': 30, 'd': 40, 'e': 50}\n" + ] + } + ], + "source": [ + "dic.update(new_dic)\n", + "print(dic) # merge" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 8. Set" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{12, 6}\n", + "{2, 3, 4, 6, 8, 9, 10, 12, 15}\n", + "{8, 2, 10, 4}\n", + "{2, 3, 4, 8, 9, 10, 15}\n" + ] + } + ], + "source": [ + "a_set = {2, 4, 6, 8, 10, 12}\n", + "b_set = {3, 6, 9, 12, 15}\n", + "\n", + "print(a_set & b_set) # intersection\n", + "print(a_set | b_set) # union\n", + "print(a_set - b_set) # difference\n", + "print(a_set ^ b_set) # symmetric difference" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "False\n" + ] + } + ], + "source": [ + "print(a_set <= b_set) # issubset\n", + "print(a_set >= b_set) # issuperset\n", + "# ( <, > : proper subset)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 9. Collection" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[(0, 11), (1, 25), (2, 4), (3, 67), (4, 83)]\n", + "2 11\n", + "3 25\n", + "4 4\n", + "5 67\n", + "6 83\n" + ] + } + ], + "source": [ + "# enumerate\n", + "age = [11, 25, 4, 67, 83]\n", + "print(list(enumerate(age)))\n", + "for no, s in enumerate(age, 2): # 2 : start setting\n", + " print(str(no), s)" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a 1\n", + "b 2\n", + "c 3\n", + "d 4\n", + "e 5\n", + "\n", + "{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}\n" + ] + } + ], + "source": [ + "# zip\n", + "alpha = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "num = [1, 2, 3, 4, 5]\n", + "list = zip(alpha, num)\n", + "\n", + "for p, q in list:\n", + " print(p,q)\n", + "print() \n", + "print(dict(zip(alpha, num))) " + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], + "source": [ + "# any, all\n", + "boo = [True, False, True, False]\n", + "print(any(boo)) # exist\n", + "print(all(boo)) # all" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 10. Lambda Function" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "40\n", + "50\n" + ] + } + ], + "source": [ + "# filter : subject to conditions\n", + "def flunk(s):\n", + " return s < 60\n", + "\n", + "score = [40, 50, 60, 70, 80]\n", + "\n", + "for s in filter(flunk, score): # filter(flunk, score) = [40, 50] -> return list\n", + " print(s)" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "20.025.030.035.040.0" + ] + } + ], + "source": [ + "# map : for all element\n", + "def half(s):\n", + " return s / 2\n", + "\n", + "for s in map(half, score):\n", + " print(s, end = '')" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(x)>" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# lambda function : only input & output\n", + "lambda x:x+1 # input : x, output : x+1" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "41\n", + "51\n", + "61\n", + "71\n", + "81\n" + ] + } + ], + "source": [ + "for s in map(lambda x:x+1, score):\n", + " print(s)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 11. Copy" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 200]\n", + "[1, 100, 3]\n" + ] + } + ], + "source": [ + "# separate storage\n", + "list1 = [1,2,3]\n", + "list2 = list1.copy()\n", + "\n", + "list2[1] = 100\n", + "list1[2] = 200\n", + "\n", + "print(list1)\n", + "print(list2)" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['a', 'c'], 1, 2]\n", + "[['a', 'c'], 1, 2]\n" + ] + } + ], + "source": [ + "# sharing 'list0'\n", + "list0 = ['a', 'b']\n", + "list1 = [list0, 1, 2]\n", + "list2 = list1.copy()\n", + "\n", + "list2[0][1] = 'c'\n", + "print(list1)\n", + "print(list2)" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['a', 'b'], 1, 2]\n", + "[['a', 'c'], 1, 2]\n" + ] + } + ], + "source": [ + "# complete copy\n", + "import copy\n", + "list0 = ['a', 'b']\n", + "list1 = [list0, 1, 2]\n", + "list2 = copy.deepcopy(list1)\n", + "\n", + "list2[0][1] = 'c'\n", + "print(list1)\n", + "print(list2)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], + "source": [ + "# is\n", + "print(list0 is list1)" + ] + } + ], + "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.7" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From c99c31905d89cce38b53a6062a1d4f541c359ed6 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung Date: Wed, 29 Jul 2020 01:25:17 +0900 Subject: [PATCH 14/60] 20200729 --- 2_Standard_Modules.ipynb | 572 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 572 insertions(+) create mode 100644 2_Standard_Modules.ipynb diff --git a/2_Standard_Modules.ipynb b/2_Standard_Modules.ipynb new file mode 100644 index 0000000..ee41ffe --- /dev/null +++ b/2_Standard_Modules.ipynb @@ -0,0 +1,572 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 2. Standard Modules\n", + "1. Random\n", + "2. Time\n", + "3. Calendar\n", + "4. Math\n", + "5. Statistics\n", + "6. Sys" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1. Random" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import random" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.4305544219309847\n", + "2\n", + "11.191936923643922\n" + ] + } + ], + "source": [ + "print(random.random())\n", + "print(random.randint(1,10)) # random number in 1~10 (including end)\n", + "print(random.uniform(1,100)) # random number in real number" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "d\n", + "['d', 'b', 'a']\n" + ] + } + ], + "source": [ + "alpha = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "\n", + "print(random.choice(alpha))\n", + "print(random.sample(alpha,3))" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['e', 'a', 'b', 'd', 'c']\n" + ] + } + ], + "source": [ + "random.shuffle(alpha)\n", + "print(alpha)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2. Time" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "import time" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1595951639.9061663\n" + ] + } + ], + "source": [ + "print(time.time()) # 1970 ~ 2020" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Wed Jul 29 00:57:03 2020\n", + "time.struct_time(tm_year=2020, tm_mon=7, tm_mday=29, tm_hour=0, tm_min=57, tm_sec=3, tm_wday=2, tm_yday=211, tm_isdst=0)\n", + "2020\n", + "0\n", + "211\n" + ] + } + ], + "source": [ + "t = time.time()\n", + "print(time.ctime(t))\n", + "print(time.localtime(t))\n", + "\n", + "print(time.localtime(t).tm_year)\n", + "print(time.localtime(t).tm_hour)\n", + "print(time.localtime(t).tm_yday)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "import datetime" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2020년 7월 29일 0:58:24\n" + ] + } + ], + "source": [ + "now = datetime.datetime.now()\n", + "print(\"%d년 %d월 %d일 %d:%d:%d\" % (now.year, now.month, now.day, now.hour, now.minute, now.second))" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Runtime : 0.0009970664978027344\n" + ] + } + ], + "source": [ + "# Run time\n", + "start = time.time()\n", + "\n", + "list = []\n", + "for a in range(10000):\n", + " list.append(a)\n", + "end = time.time()\n", + "\n", + "print(\"Runtime :\", end - start)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "time.sleep(5) # wait!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3. Calendar" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "import calendar" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 2020\n", + "\n", + " January February March\n", + "Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa\n", + " 1 2 3 4 1 1 2 3 4 5 6 7\n", + " 5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14\n", + "12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21\n", + "19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28\n", + "26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31\n", + "\n", + " April May June\n", + "Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa\n", + " 1 2 3 4 1 2 1 2 3 4 5 6\n", + " 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13\n", + "12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20\n", + "19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27\n", + "26 27 28 29 30 24 25 26 27 28 29 30 28 29 30\n", + " 31\n", + "\n", + " July August September\n", + "Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa\n", + " 1 2 3 4 1 1 2 3 4 5\n", + " 5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12\n", + "12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19\n", + "19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26\n", + "26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30\n", + " 30 31\n", + "\n", + " October November December\n", + "Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa\n", + " 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5\n", + " 4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12\n", + "11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19\n", + "18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26\n", + "25 26 27 28 29 30 31 29 30 27 28 29 30 31\n", + "\n" + ] + } + ], + "source": [ + "print(calendar.calendar(2020))" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Today is Wednesday\n" + ] + } + ], + "source": [ + "ans = [\"Monday\", \"Tuesday\",\"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n", + "day = calendar.weekday(2020,7,29)\n", + "print(\"Today is\", ans[day])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 4. Math" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [], + "source": [ + "import math" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3.141592653589793\n", + "6.283185307179586\n", + "2.718281828459045\n", + "inf\n", + "nan\n" + ] + } + ], + "source": [ + "# Math module constants\n", + "print(math.pi)\n", + "print(math.tau) # 2*pi\n", + "print(math.e) # Euler's number\n", + "print(math.inf)\n", + "print(math.nan)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4.0 16.0\n", + "5.0\n", + "24\n" + ] + } + ], + "source": [ + "print(math.sqrt(16), math.pow(4,2))\n", + "print(math.hypot(3,4)) # Pythagorean theorem\n", + "print(math.factorial(4))" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.479425538604203 0.8775825618903728 0.5463024898437905\n", + "1.5707963267948966 0.0 0.7853981633974483\n", + "1.1752011936438014 1.5430806348152437 0.7615941559557649\n", + "180.0\n", + "3.141592653589793\n" + ] + } + ], + "source": [ + "print(math.sin(0.5), math.cos(0.5), math.tan(0.5))\n", + "print(math.asin(1), math.acos(1), math.atan(1))\n", + "print(math.sinh(1), math.cosh(1), math.tanh(1))\n", + "print(math.degrees(math.pi)) # radian -> degree\n", + "print(math.radians(180)) # degree -> radian" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4 3 3\n", + "1.5\n", + "4.0 0.6989700043360189\n", + "1\n" + ] + } + ], + "source": [ + "print(math.ceil(3.6), math.floor(3.6), math.trunc(3.6))\n", + "print(math.fabs(-1.5)) # absolute value\n", + "print(math.log(16, 2), math.log10(5))\n", + "print(math.gcd(3,5))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 5. Statistics" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [], + "source": [ + "import statistics" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "53.75\n", + "43.41085271317829\n" + ] + } + ], + "source": [ + "data = [20, 30, 40, 50, 60, 70, 80, 80]\n", + "\n", + "print(statistics.mean(data))\n", + "print(statistics.harmonic_mean(data))" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "55.0\n", + "50\n", + "60\n" + ] + } + ], + "source": [ + "print(statistics.median(data))\n", + "print(statistics.median_low(data))\n", + "print(statistics.median_high(data))" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n", + "22.638462845343543\n", + "512.5\n" + ] + } + ], + "source": [ + "print(statistics.mode(data))\n", + "print(statistics.stdev(data)) # Standard Deviation\n", + "print(statistics.variance(data))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 6. Sys" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [], + "source": [ + "import sys" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1. Version : 3.7.7 (default, May 6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]\n", + "2. Platform : win32\n", + "3. Window Version : sys.getwindowsversion(major=10, minor=0, build=18362, platform=2, service_pack='')\n", + "4. Byte order : little\n", + "5. Path : ['C:\\\\Users\\\\eilee\\\\Desktop\\\\Python', 'C:\\\\ProgramData\\\\Anaconda3\\\\python37.zip', 'C:\\\\ProgramData\\\\Anaconda3\\\\DLLs', 'C:\\\\ProgramData\\\\Anaconda3\\\\lib', 'C:\\\\ProgramData\\\\Anaconda3', '', 'C:\\\\Users\\\\eilee\\\\AppData\\\\Roaming\\\\Python\\\\Python37\\\\site-packages', 'C:\\\\ProgramData\\\\Anaconda3\\\\lib\\\\site-packages', 'C:\\\\ProgramData\\\\Anaconda3\\\\lib\\\\site-packages\\\\win32', 'C:\\\\ProgramData\\\\Anaconda3\\\\lib\\\\site-packages\\\\win32\\\\lib', 'C:\\\\ProgramData\\\\Anaconda3\\\\lib\\\\site-packages\\\\Pythonwin', 'C:\\\\ProgramData\\\\Anaconda3\\\\lib\\\\site-packages\\\\IPython\\\\extensions', 'C:\\\\Users\\\\eilee\\\\.ipython']\n" + ] + } + ], + "source": [ + "# system information\n", + "\n", + "print(\"1. Version :\", sys.version)\n", + "print(\"2. Platform :\", sys.platform)\n", + "print(\"3. Window Version :\", sys.getwindowsversion())\n", + "print(\"4. Byte order :\", sys.byteorder)\n", + "print(\"5. Path :\", sys.path)" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['C:\\\\ProgramData\\\\Anaconda3\\\\lib\\\\site-packages\\\\ipykernel_launcher.py', '-f', 'C:\\\\Users\\\\eilee\\\\AppData\\\\Roaming\\\\jupyter\\\\runtime\\\\kernel-54222200-078a-4522-b5d9-ea5064a2a6d1.json']\n" + ] + } + ], + "source": [ + "print(sys.argv)" + ] + } + ], + "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.7" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 5652614373f656b2fa37786d5bb86cd6ee06309f Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Wed, 29 Jul 2020 01:58:38 +0900 Subject: [PATCH 15/60] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index c9bcd22..4c888be 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,6 @@ My personal toolbox that contains my daily python tools for datascience and mach |4|Math| |5|Statistics| |6|Sys| + +## Reference +[1] 김상형,『파이썬 정복』, 한빛미디어(2018) From a9ba5658902529395a6b4eb1deea5d0fcc0ef013 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Wed, 29 Jul 2020 01:58:56 +0900 Subject: [PATCH 16/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c888be..4d051c5 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,4 @@ My personal toolbox that contains my daily python tools for datascience and mach |6|Sys| ## Reference -[1] 김상형,『파이썬 정복』, 한빛미디어(2018) +[1] 김상형,『파이썬 정복』, 한빛미디어(2018) From a97698d51bc567eb3abb2e5dad6fd61ecc104260 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Wed, 29 Jul 2020 10:08:55 +0900 Subject: [PATCH 17/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d051c5..aaa0f17 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Python_Toolbox +# Python_Toolbox (20200728 ~) My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure From 93b7b02ca3a4d7066907ec5fb06efcb102cb27ea Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Wed, 29 Jul 2020 21:22:04 +0900 Subject: [PATCH 18/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aaa0f17..5ade80e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Python_Toolbox (20200728 ~) +# Python Toolbox (20200728 ~) My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure From 18290e9eaab5b47647580ec991c6a729431041ba Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Sun, 27 Sep 2020 00:23:03 +0900 Subject: [PATCH 19/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ade80e..f808ea1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Python Toolbox (20200728 ~) -My personal toolbox that contains my daily python tools for datascience and machinelearning +- My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure |No.|Contents|No.|Contents| From 06845f777b0766ff0e10552b7962d74eff2935e5 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 13 Oct 2020 21:07:17 +0900 Subject: [PATCH 20/60] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6347be7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 OH-Seoyoung + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From b861f5c65843ca098501222efdbca58b3057b780 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Tue, 13 Oct 2020 22:32:27 +0900 Subject: [PATCH 21/60] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f808ea1..4c2e625 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,6 @@ |6|Sys| ## Reference +``` [1] 김상형,『파이썬 정복』, 한빛미디어(2018) +``` From d91ac5837e6b4bacf4b5521d4f97ea65a0c90160 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung <57218700+OH-Seoyoung@users.noreply.github.com> Date: Thu, 15 Oct 2020 15:08:53 +0900 Subject: [PATCH 22/60] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4c2e625..48ef57b 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,14 @@ |6|List and Tuple|12|| ## 2. Standard Modules -|No.|Contents| -|------|---| -|1|Random| -|2|Time| -|3|Calendar| -|4|Math| -|5|Statistics| -|6|Sys| +|No.|Contents|No.|Contents| +|------|---|------|---| +|1|Random|4|Math| +|2|Time|5|Statistics| +|3|Calendar|6|Sys| + + + ## Reference ``` From 1aa964c5de3c74c32dba751f542db00ef600ddd2 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Tue, 1 Dec 2020 19:55:11 +0900 Subject: [PATCH 23/60] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 48ef57b..398eeb5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Python Toolbox (20200728 ~) - My personal toolbox that contains my daily python tools for datascience and machinelearning -## 1. Basic Structure +## 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/1_Basic_Structure.ipynb) |No.|Contents|No.|Contents| |------|---|---|---| |1|Print|7|Dictionary| @@ -11,7 +11,7 @@ |5|Formatting|11|Copy| |6|List and Tuple|12|| -## 2. Standard Modules +## 2. Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/2_Standard_Modules.ipynb) |No.|Contents|No.|Contents| |------|---|------|---| |1|Random|4|Math| From cfa7b4a770165119f4b73eb2e6476ca9a6a0d4c7 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Tue, 1 Dec 2020 19:55:49 +0900 Subject: [PATCH 24/60] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 398eeb5..f03a969 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Python Toolbox (20200728 ~) - My personal toolbox that contains my daily python tools for datascience and machinelearning -## 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/1_Basic_Structure.ipynb) +### 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/1_Basic_Structure.ipynb) |No.|Contents|No.|Contents| |------|---|---|---| |1|Print|7|Dictionary| @@ -11,7 +11,7 @@ |5|Formatting|11|Copy| |6|List and Tuple|12|| -## 2. Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/2_Standard_Modules.ipynb) +### 2. Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/2_Standard_Modules.ipynb) |No.|Contents|No.|Contents| |------|---|------|---| |1|Random|4|Math| From d3ea11024ff4ee7a6f19bc92b65a30797f5f7e2a Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Tue, 1 Dec 2020 19:56:05 +0900 Subject: [PATCH 25/60] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f03a969..398eeb5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Python Toolbox (20200728 ~) - My personal toolbox that contains my daily python tools for datascience and machinelearning -### 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/1_Basic_Structure.ipynb) +## 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/1_Basic_Structure.ipynb) |No.|Contents|No.|Contents| |------|---|---|---| |1|Print|7|Dictionary| @@ -11,7 +11,7 @@ |5|Formatting|11|Copy| |6|List and Tuple|12|| -### 2. Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/2_Standard_Modules.ipynb) +## 2. Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/2_Standard_Modules.ipynb) |No.|Contents|No.|Contents| |------|---|------|---| |1|Random|4|Math| From 9063c08cc610fcb1e846c9cc87c83880f0c6b58a Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 2 Dec 2020 10:37:44 +0900 Subject: [PATCH 26/60] Update README.md --- README.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 398eeb5..4662dc4 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,11 @@ - My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/1_Basic_Structure.ipynb) -|No.|Contents|No.|Contents| -|------|---|---|---| -|1|Print|7|Dictionary| -|2|Variable|8|Set| -|3|Function|9|Collection| -|4|Method|10|Lambda Function| -|5|Formatting|11|Copy| -|6|List and Tuple|12|| +|No.|Contents|No.|Contents|No.|Contents| +|------|---|---|---|---|---| +|1|Print|4|Method|7|Dictionary|10|Lambda Function| +|2|Variable|5|Formatting|8|Set|11|Copy| +|3|Function|6|List and Tuple|9|Collection|12|| ## 2. Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/2_Standard_Modules.ipynb) |No.|Contents|No.|Contents| From 97f635d6ced33a1ec8d4db1d1589550220ccedc2 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 2 Dec 2020 10:38:03 +0900 Subject: [PATCH 27/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4662dc4..d35dcff 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/1_Basic_Structure.ipynb) |No.|Contents|No.|Contents|No.|Contents| -|------|---|---|---|---|---| +|------|---|---|---|---|---|---|---| |1|Print|4|Method|7|Dictionary|10|Lambda Function| |2|Variable|5|Formatting|8|Set|11|Copy| |3|Function|6|List and Tuple|9|Collection|12|| From 9553665bc22491cfc30d54ff134433e0dfb24e44 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 2 Dec 2020 10:38:17 +0900 Subject: [PATCH 28/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d35dcff..1b3dc7c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ - My personal toolbox that contains my daily python tools for datascience and machinelearning ## 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/1_Basic_Structure.ipynb) -|No.|Contents|No.|Contents|No.|Contents| +|No.|Contents|No.|Contents|No.|Contents|No.|Contents| |------|---|---|---|---|---|---|---| |1|Print|4|Method|7|Dictionary|10|Lambda Function| |2|Variable|5|Formatting|8|Set|11|Copy| From 107f680f58c779eb24e39da12e92d3e508f9e2ef Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 2 Dec 2020 10:39:03 +0900 Subject: [PATCH 29/60] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 1b3dc7c..278405c 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,11 @@ |2|Variable|5|Formatting|8|Set|11|Copy| |3|Function|6|List and Tuple|9|Collection|12|| +|No.|Contents|No.|Contents|No.|Contents|No.|Contents| +|------|---|---|---|---|---|---|---| +|1|Print|2|Method|3|Dictionary|4|Lambda Function| +|5|Variable|6|Formatting|7|Set|8|Copy| +|9|Function|10|List and Tuple|11|Collection|12|| ## 2. Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/2_Standard_Modules.ipynb) |No.|Contents|No.|Contents| |------|---|------|---| From bb1b7e4c75e26afe8e4a2ef19ca993a94cdcc4d5 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 2 Dec 2020 10:41:11 +0900 Subject: [PATCH 30/60] Update README.md --- README.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 278405c..bfe4126 100644 --- a/README.md +++ b/README.md @@ -4,24 +4,16 @@ ## 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/1_Basic_Structure.ipynb) |No.|Contents|No.|Contents|No.|Contents|No.|Contents| |------|---|---|---|---|---|---|---| -|1|Print|4|Method|7|Dictionary|10|Lambda Function| -|2|Variable|5|Formatting|8|Set|11|Copy| -|3|Function|6|List and Tuple|9|Collection|12|| +|1|Print|2|Variable|3|Function|4|Method| +|5|Formatting|6|List and Tuple|7|Dictionary|8|Set| +|9|Collection|10|Lambda Function|11|Copy|12|| -|No.|Contents|No.|Contents|No.|Contents|No.|Contents| -|------|---|---|---|---|---|---|---| -|1|Print|2|Method|3|Dictionary|4|Lambda Function| -|5|Variable|6|Formatting|7|Set|8|Copy| -|9|Function|10|List and Tuple|11|Collection|12|| ## 2. Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/2_Standard_Modules.ipynb) |No.|Contents|No.|Contents| |------|---|------|---| -|1|Random|4|Math| -|2|Time|5|Statistics| -|3|Calendar|6|Sys| - - - +|1|Random|2|Time| +|3|Calendar|4|Math| +|5|Statistics|6|Sys| ## Reference ``` From 9ceb15db56048e366c3a3b72a9814d695a7af478 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung Date: Wed, 5 May 2021 01:47:51 +0900 Subject: [PATCH 31/60] 20210505 --- .../Automatic Differentiation.ipynb | 268 ++ .../Linear Regression.ipynb | 3068 +++++++++++++++++ Deeplearning_with_Pytorch/Probability.ipynb | 177 + .../1_Basic_Structure.ipynb | 0 .../2_Standard_Modules.ipynb | 0 5 files changed, 3513 insertions(+) create mode 100644 Deeplearning_with_Pytorch/Automatic Differentiation.ipynb create mode 100644 Deeplearning_with_Pytorch/Linear Regression.ipynb create mode 100644 Deeplearning_with_Pytorch/Probability.ipynb rename 1_Basic_Structure.ipynb => Python_Basic/1_Basic_Structure.ipynb (100%) rename 2_Standard_Modules.ipynb => Python_Basic/2_Standard_Modules.ipynb (100%) diff --git a/Deeplearning_with_Pytorch/Automatic Differentiation.ipynb b/Deeplearning_with_Pytorch/Automatic Differentiation.ipynb new file mode 100644 index 0000000..7e7f4cc --- /dev/null +++ b/Deeplearning_with_Pytorch/Automatic Differentiation.ipynb @@ -0,0 +1,268 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Automatic Differentiation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1. Scalar Variables" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- differentiating the function y = 2x.Tx with respect to the column vector x" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0., 1., 2., 3.])" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "\n", + "x = torch.arange(4.0)\n", + "x" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- calculating the gradient of y with respect to x \n", + "\n", + "-> we do not allocate new memory every time we take a derivative with respect to a parameter" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Since x is a vector of length 4, an inner product of x and x is performed -> scalar output -> assign y" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "x.requires_grad_(True) # Same as `x = torch.arange(4.0, requires_grad=True)`\n", + "x.grad # The default value is None" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor(28., grad_fn=)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y = 2 * torch.dot(x, x)\n", + "y" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- automatically calculating the gradient of y with respect to each component of x \n", + "\n", + "-> calling the function for backpropagation and printing the gradient." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([ 0., 4., 8., 12.])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y.backward()\n", + "x.grad" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- The gradient of the function y = 2x.Tx with respect toxshould be 4x -> check!" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([True, True, True, True])" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x.grad == 4 * x" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2. Non-Scalar Variable" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- For higher-dimensional y and x, the differentiation result could be a high-order tensor\n", + "- calculate the differentiation matrix but rather the sum of the partial derivatives computed individually for each example in the batch." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0., 2., 4., 6.])" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x.grad.zero_()\n", + "y = x * x\n", + "\n", + "y.sum().backward()\n", + "x.grad" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "def f(a):\n", + " b = a * 2\n", + " while b.norm() < 1000:\n", + " b = b * 2\n", + " if b.sum() > 0:\n", + " c = b\n", + " else:\n", + " c = 100 * b\n", + " return c" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "a = torch.randn(size=(), requires_grad=True)\n", + "d = f(a)\n", + "d.backward()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- it is piecewise linear in its input a. In other words, for any a there exists some constant scalar k such that f(a) = k * a, \n", + "where the value of k depends on the input a. Consequently d / a allows us to verify that the gradient is correct." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor(True)" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a.grad == d / a" + ] + } + ], + "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.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Deeplearning_with_Pytorch/Linear Regression.ipynb b/Deeplearning_with_Pytorch/Linear Regression.ipynb new file mode 100644 index 0000000..bc4e85c --- /dev/null +++ b/Deeplearning_with_Pytorch/Linear Regression.ipynb @@ -0,0 +1,3068 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Linear Regression" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Vectorization for Speed" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "import math\n", + "import time\n", + "import numpy as np\n", + "import torch\n", + "from d2l import torch as d2l" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "n = 10000\n", + "a = torch.ones(n)\n", + "b = torch.ones(n)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- define a timer" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "class Timer: #@save\n", + " \"\"\"Record multiple running times.\"\"\"\n", + " def __init__(self):\n", + " self.times = []\n", + " self.start()\n", + "\n", + " def start(self):\n", + " \"\"\"Start the timer.\"\"\"\n", + " self.tik = time.time()\n", + "\n", + " def stop(self):\n", + " \"\"\"Stop the timer and record the time in a list.\"\"\"\n", + " self.times.append(time.time() - self.tik)\n", + " return self.times[-1]\n", + "\n", + " def avg(self):\n", + " \"\"\"Return the average time.\"\"\"\n", + " return sum(self.times) / len(self.times)\n", + "\n", + " def sum(self):\n", + " \"\"\"Return the sum of time.\"\"\"\n", + " return sum(self.times)\n", + "\n", + " def cumsum(self):\n", + " \"\"\"Return the accumulated time.\"\"\"\n", + " return np.array(self.times).cumsum().tolist()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- 1. add them, one coordinate at a time, using a for-loop" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'0.20502 sec'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c = torch.zeros(n)\n", + "timer = Timer()\n", + "for i in range(n):\n", + " c[i] = a[i] + b[i]\n", + "f'{timer.stop():.5f} sec'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- 2. the reloaded + operator to compute the elementwise sum -> fast!" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'0.00000 sec'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "timer.start()\n", + "d = a + b\n", + "f'{timer.stop():.5f} sec'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### The Normal Distribution and Squared Loss" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "def normal(x, mu, sigma):\n", + " p = 1 / math.sqrt(2 * math.pi * sigma**2)\n", + " return p * np.exp(-0.5 / sigma**2 * (x - mu)**2)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\r\n", + "\r\n", + "\r\n", + "\r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " 2021-05-04T15:41:27.635839\r\n", + " image/svg+xml\r\n", + " \r\n", + " \r\n", + " Matplotlib v3.3.4, https://matplotlib.org/\r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + "\r\n" + ], + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "# Use numpy again for visualization\n", + "x = np.arange(-7, 7, 0.01)\n", + "\n", + "# Mean and standard deviation pairs\n", + "params = [(0, 1), (0, 2), (3, 1)]\n", + "d2l.plot(x, [normal(x, mu, sigma) for mu, sigma in params], xlabel='x',\n", + " ylabel='p(x)', figsize=(4.5, 2.5),\n", + " legend=[f'mean {mu}, std {sigma}' for mu, sigma in params])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Linear Regression Implementation from Scratch" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "import random\n", + "import torch\n", + "from d2l import torch as d2l" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- construct an artificial dataset according to a linear model with additive noise \n", + "\n", + "-> we generate a dataset containing 1000 examples, each consisting of 2 features sampled from a standard normal distribution" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "def synthetic_data(w, b, num_examples): #@save\n", + " \"\"\"Generate y = Xw + b + noise.\"\"\"\n", + " X = torch.normal(0, 1, (num_examples, len(w)))\n", + " y = torch.matmul(X, w) + b\n", + " y += torch.normal(0, 0.01, y.shape)\n", + " return X, y.reshape((-1, 1))\n", + "\n", + "true_w = torch.tensor([2, -3.4])\n", + "true_b = 4.2\n", + "features, labels = synthetic_data(true_w, true_b, 1000)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- each row in features consists of a 2-dimensional data example\n", + "- each row in labels consists of a 1-dimensional label value (a scalar)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "features: tensor([ 0.7840, -1.3051]) \n", + "label: tensor([10.2083])\n" + ] + } + ], + "source": [ + "print('features:', features[0], '\\nlabel:', labels[0])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- scatter plot using the second feature features[:, 1] and labels \n", + "\n", + "-> linear correlation between the two." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\r\n", + "\r\n", + "\r\n", + "\r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " 2021-05-04T15:44:50.638306\r\n", + " image/svg+xml\r\n", + " \r\n", + " \r\n", + " Matplotlib v3.3.4, https://matplotlib.org/\r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + " \r\n", + "\r\n" + ], + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "d2l.set_figsize()\n", + "# The semicolon is for displaying the plot only\n", + "d2l.plt.scatter(features[:, (1)].detach().numpy(),\n", + " labels.detach().numpy(), 1);" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- read the data" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "def data_iter(batch_size, features, labels):\n", + " num_examples = len(features)\n", + " indices = list(range(num_examples))\n", + " # The examples are read at random, in no particular order\n", + " random.shuffle(indices)\n", + " for i in range(0, num_examples, batch_size):\n", + " batch_indices = torch.tensor(indices[i:min(i +\n", + " batch_size, num_examples)])\n", + " yield features[batch_indices], labels[batch_indices]" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "tensor([[-1.5424, -0.2822],\n", + " [-1.2570, 0.1944],\n", + " [-0.0559, 1.2745],\n", + " [-1.5009, 0.4849],\n", + " [ 0.3836, 1.1902],\n", + " [-0.7026, 0.1668],\n", + " [-1.8561, -0.3443],\n", + " [ 0.9422, -2.7780],\n", + " [-0.4836, 0.8759],\n", + " [ 0.1438, -1.4416]]) \n", + " tensor([[ 2.0830],\n", + " [ 1.0128],\n", + " [-0.2520],\n", + " [-0.4559],\n", + " [ 0.9218],\n", + " [ 2.2245],\n", + " [ 1.6560],\n", + " [15.5200],\n", + " [ 0.2531],\n", + " [ 9.3897]])\n" + ] + } + ], + "source": [ + "batch_size = 10\n", + "\n", + "for X, y in data_iter(batch_size, features, labels):\n", + " print(X, '\\n', y)\n", + " break" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Initializing Model Parameters" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "w = torch.normal(0, 0.01, size=(2, 1), requires_grad=True)\n", + "b = torch.zeros(1, requires_grad=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Defining the Model" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "def linreg(X, w, b):\n", + " \"\"\"The linear regression model.\"\"\"\n", + " return torch.matmul(X, w) + b" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Defining the Loss Function : squared loss" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "def squared_loss(y_hat, y):\n", + " return (y_hat - y.reshape(y_hat.shape))**2 / 2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Defining the Optimization Algorithm : Minibatch stochastic gradient descent" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "def sgd(params, lr, batch_size): #@save\n", + " with torch.no_grad():\n", + " for param in params:\n", + " param -= lr * param.grad / batch_size\n", + " param.grad.zero_()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Training" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "epoch 1, loss 0.031178\n", + "epoch 2, loss 0.000102\n", + "epoch 3, loss 0.000047\n" + ] + } + ], + "source": [ + "lr = 0.03\n", + "num_epochs = 3\n", + "net = linreg\n", + "loss = squared_loss\n", + "\n", + "for epoch in range(num_epochs):\n", + " for X, y in data_iter(batch_size, features, labels):\n", + " l = loss(net(X, w, b), y) # Minibatch loss in `X` and `y`\n", + " # Compute gradient on `l` with respect to [`w`, `b`]\n", + " l.sum().backward()\n", + " sgd([w, b], lr, batch_size) # Update parameters using their gradient\n", + " with torch.no_grad():\n", + " train_l = loss(net(features, w, b), labels)\n", + " print(f'epoch {epoch + 1}, loss {float(train_l.mean()):f}')" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "error in estimating w: tensor([ 0.0004, -0.0003], grad_fn=)\n", + "error in estimating b: tensor([-0.0003], grad_fn=)\n" + ] + } + ], + "source": [ + "print(f'error in estimating w: {true_w - w.reshape(true_w.shape)}')\n", + "print(f'error in estimating b: {true_b - b}')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Concise Implementation of Linear Regression" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Generating the Dataset" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import torch\n", + "from torch.utils import data\n", + "from d2l import torch as d2l\n", + "\n", + "true_w = torch.tensor([2, -3.4])\n", + "true_b = 4.2\n", + "features, labels = d2l.synthetic_data(true_w, true_b, 1000)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Reading the Dataset" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "def load_array(data_arrays, batch_size, is_train=True):\n", + " dataset = data.TensorDataset(*data_arrays)\n", + " return data.DataLoader(dataset, batch_size, shuffle=is_train)\n", + "\n", + "batch_size = 10\n", + "data_iter = load_array((features, labels), batch_size)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[tensor([[ 3.0125, -0.5107],\n", + " [ 1.1328, 1.0593],\n", + " [-0.5198, -0.0207],\n", + " [ 0.2320, 1.3729],\n", + " [-0.7809, -1.5310],\n", + " [-0.6105, -0.4081],\n", + " [ 0.1310, 0.7226],\n", + " [ 0.6404, 0.4701],\n", + " [-1.5183, -0.8518],\n", + " [-0.5191, 0.1617]]),\n", + " tensor([[ 1.1968e+01],\n", + " [ 2.8768e+00],\n", + " [ 3.2143e+00],\n", + " [-5.2824e-03],\n", + " [ 7.8520e+00],\n", + " [ 4.3685e+00],\n", + " [ 2.0130e+00],\n", + " [ 3.8815e+00],\n", + " [ 4.0513e+00],\n", + " [ 2.6072e+00]])]" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "next(iter(data_iter))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Defining the Model\n", + "- The **Sequential class** defines a container for several layers that will be chained together \n", + "\n", + "-> Given input data, a Sequential instance passes it through the first layer, in turn passing the output as the second layer’s input and so forth\n", + "- the fully-connected layer is defined in the **Linear class**" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "from torch import nn\n", + "\n", + "net = nn.Sequential(nn.Linear(2, 1))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Initializing Model Parameters" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0.])" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net[0].weight.data.normal_(0, 0.01) # mean, deviation\n", + "net[0].bias.data.fill_(0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Defining the Loss Function" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "loss = nn.MSELoss()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Defining the Optimization Algorithm" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "trainer = torch.optim.SGD(net.parameters(), lr=0.03)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- Training \n", + "Generate predictions by calling net(X) and calculate the loss l (the forward propagation). \n", + "Calculate gradients by running the backpropagation. \n", + "Update the model parameters by invoking our optimizer. " + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "epoch 1, loss 0.000207\n", + "epoch 2, loss 0.000100\n", + "epoch 3, loss 0.000100\n" + ] + } + ], + "source": [ + "num_epochs = 3\n", + "for epoch in range(num_epochs):\n", + " for X, y in data_iter:\n", + " l = loss(net(X), y)\n", + " trainer.zero_grad()\n", + " l.backward()\n", + " trainer.step()\n", + " l = loss(net(features), labels)\n", + " print(f'epoch {epoch + 1}, loss {l:f}')" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "error in estimating w: tensor([-0.0003, 0.0002])\n", + "error in estimating b: tensor([-0.0006])\n" + ] + } + ], + "source": [ + "w = net[0].weight.data\n", + "print('error in estimating w:', true_w - w.reshape(true_w.shape))\n", + "b = net[0].bias.data\n", + "print('error in estimating b:', true_b - b)" + ] + } + ], + "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.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Deeplearning_with_Pytorch/Probability.ipynb b/Deeplearning_with_Pytorch/Probability.ipynb new file mode 100644 index 0000000..47727f7 --- /dev/null +++ b/Deeplearning_with_Pytorch/Probability.ipynb @@ -0,0 +1,177 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Probability" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1. Basic Probability Theory" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# pip install torch torchvision\n", + "# pip install -U d2l" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "import torch\n", + "from torch.distributions import multinomial\n", + "from d2l import torch as d2l" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- dice! : {1,…,6} are equally likely to occur -> probability 1/6\n", + "- estimate of the probability of a given event \n", + "\n", + "-> The law of large numbers tell us that as the number of tosses grows this estimate will draw closer and closer to the true underlying probability.\n", + "\n", + "-> loop? (x) multiple samples at once (o)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0., 1., 0., 0., 0., 0.])" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fair_probs = torch.ones([6]) / 6\n", + "multinomial.Multinomial(1, fair_probs).sample()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([4., 1., 0., 2., 2., 1.])" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "multinomial.Multinomial(10, fair_probs).sample()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- after each of the 1000 rolls, how many times each number was rolled. \n", + "\n", + "-> we calculate the relative frequency as the estimate of the true probability." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0.1510, 0.1710, 0.1490, 0.1800, 0.1800, 0.1690])" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "counts = multinomial.Multinomial(1000, fair_probs).sample()\n", + "counts / 1000 # Relative frequency as the estimate" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- we know that each outcome has true probability 1/6 , roughly 0.167 -> good results!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- visualize how these probabilities converge over time towards the true probability" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "counts = multinomial.Multinomial(10, fair_probs).sample((500,))\n", + "cum_counts = counts.cumsum(dim=0)\n", + "estimates = cum_counts / cum_counts.sum(dim=1, keepdims=True)\n", + "\n", + "d2l.set_figsize((6, 4.5))\n", + "for i in range(6):\n", + " d2l.plt.plot(estimates[:, i].numpy(), label=(\"P(die=\" + str(i + 1) + \")\"))\n", + "d2l.plt.axhline(y=0.167, color='black', linestyle='dashed')\n", + "d2l.plt.gca().set_xlabel('Groups of experiments')\n", + "d2l.plt.gca().set_ylabel('Estimated probability')\n", + "d2l.plt.legend();" + ] + } + ], + "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.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/1_Basic_Structure.ipynb b/Python_Basic/1_Basic_Structure.ipynb similarity index 100% rename from 1_Basic_Structure.ipynb rename to Python_Basic/1_Basic_Structure.ipynb diff --git a/2_Standard_Modules.ipynb b/Python_Basic/2_Standard_Modules.ipynb similarity index 100% rename from 2_Standard_Modules.ipynb rename to Python_Basic/2_Standard_Modules.ipynb From e06ce9eaaa31eeee584ce8085ed3012466bef66b Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 5 May 2021 01:49:19 +0900 Subject: [PATCH 32/60] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bfe4126..39457ad 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # Python Toolbox (20200728 ~) - My personal toolbox that contains my daily python tools for datascience and machinelearning -## 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/1_Basic_Structure.ipynb) +## 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/1_Basic_Structure.ipynb) |No.|Contents|No.|Contents|No.|Contents|No.|Contents| |------|---|---|---|---|---|---|---| |1|Print|2|Variable|3|Function|4|Method| |5|Formatting|6|List and Tuple|7|Dictionary|8|Set| |9|Collection|10|Lambda Function|11|Copy|12|| -## 2. Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/2_Standard_Modules.ipynb) +## 2. Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/2_Standard_Modules.ipynb) |No.|Contents|No.|Contents| |------|---|------|---| |1|Random|2|Time| From 3bf851179ed13deb7567682587326e2bfe55a9cb Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 5 May 2021 01:52:39 +0900 Subject: [PATCH 33/60] Update README.md --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 39457ad..15311df 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,27 @@ # Python Toolbox (20200728 ~) - My personal toolbox that contains my daily python tools for datascience and machinelearning -## 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/1_Basic_Structure.ipynb) +## Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/1_Basic_Structure.ipynb) |No.|Contents|No.|Contents|No.|Contents|No.|Contents| |------|---|---|---|---|---|---|---| |1|Print|2|Variable|3|Function|4|Method| |5|Formatting|6|List and Tuple|7|Dictionary|8|Set| |9|Collection|10|Lambda Function|11|Copy|12|| -## 2. Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/2_Standard_Modules.ipynb) +## Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/2_Standard_Modules.ipynb) |No.|Contents|No.|Contents| |------|---|------|---| |1|Random|2|Time| |3|Calendar|4|Math| |5|Statistics|6|Sys| + +## Pytorch Deeplearning +- Differentiation, Probability, Neural Networks + + ## Reference ``` [1] 김상형,『파이썬 정복』, 한빛미디어(2018) +[2] Dive into Deep Learning, http://d2l.ai/ ``` From a09c4479fe8dd98c3efd56d805244a7c5ef8a8ed Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 5 May 2021 01:53:21 +0900 Subject: [PATCH 34/60] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 15311df..f775766 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@ # Python Toolbox (20200728 ~) - My personal toolbox that contains my daily python tools for datascience and machinelearning -## Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/1_Basic_Structure.ipynb) +## Python Basic +### 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/1_Basic_Structure.ipynb) |No.|Contents|No.|Contents|No.|Contents|No.|Contents| |------|---|---|---|---|---|---|---| |1|Print|2|Variable|3|Function|4|Method| |5|Formatting|6|List and Tuple|7|Dictionary|8|Set| |9|Collection|10|Lambda Function|11|Copy|12|| -## Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/2_Standard_Modules.ipynb) +### 2.Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/2_Standard_Modules.ipynb) |No.|Contents|No.|Contents| |------|---|------|---| |1|Random|2|Time| From 9dc7a10614c9cc6909a78821c3021efed336590a Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 11:27:51 +0900 Subject: [PATCH 35/60] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f775766..c5a45ce 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ |3|Calendar|4|Math| |5|Statistics|6|Sys| +## 3. Module and Packages | [[Study]]() | [[Code]]() ## Pytorch Deeplearning - Differentiation, Probability, Neural Networks From a71b63b6e438df03f025768b8d66dd925b5c73bb Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 11:30:33 +0900 Subject: [PATCH 36/60] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c5a45ce..99eb0cc 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,11 @@ |3|Calendar|4|Math| |5|Statistics|6|Sys| -## 3. Module and Packages | [[Study]]() | [[Code]]() +## Module and Packages | [[Study]]() | [[Code]]() -## Pytorch Deeplearning + + +## Pytorch Deeplearning | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Deeplearning_with_Pytorch) - Differentiation, Probability, Neural Networks From f84fed1c8bae2d020512b7078c24e180fbc9d04b Mon Sep 17 00:00:00 2001 From: OH-Seoyoung Date: Wed, 12 May 2021 11:32:51 +0900 Subject: [PATCH 37/60] 20210512 --- .../Untitled-checkpoint.ipynb | 6 ++++ Module_and_Package/Untitled.ipynb | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Module_and_Package/.ipynb_checkpoints/Untitled-checkpoint.ipynb create mode 100644 Module_and_Package/Untitled.ipynb diff --git a/Module_and_Package/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/Module_and_Package/.ipynb_checkpoints/Untitled-checkpoint.ipynb new file mode 100644 index 0000000..7fec515 --- /dev/null +++ b/Module_and_Package/.ipynb_checkpoints/Untitled-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Module_and_Package/Untitled.ipynb b/Module_and_Package/Untitled.ipynb new file mode 100644 index 0000000..35eac67 --- /dev/null +++ b/Module_and_Package/Untitled.ipynb @@ -0,0 +1,32 @@ +{ + "cells": [ + { + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 54f0c8c466abf1a57cb952a5293344e755a8a77a Mon Sep 17 00:00:00 2001 From: OH-Seoyoung Date: Wed, 12 May 2021 11:34:12 +0900 Subject: [PATCH 38/60] 20210512 --- Module_and_Package/README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Module_and_Package/README.md diff --git a/Module_and_Package/README.md b/Module_and_Package/README.md new file mode 100644 index 0000000..99eb0cc --- /dev/null +++ b/Module_and_Package/README.md @@ -0,0 +1,31 @@ +# Python Toolbox (20200728 ~) +- My personal toolbox that contains my daily python tools for datascience and machinelearning + +## Python Basic +### 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/1_Basic_Structure.ipynb) +|No.|Contents|No.|Contents|No.|Contents|No.|Contents| +|------|---|---|---|---|---|---|---| +|1|Print|2|Variable|3|Function|4|Method| +|5|Formatting|6|List and Tuple|7|Dictionary|8|Set| +|9|Collection|10|Lambda Function|11|Copy|12|| + +### 2.Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/2_Standard_Modules.ipynb) +|No.|Contents|No.|Contents| +|------|---|------|---| +|1|Random|2|Time| +|3|Calendar|4|Math| +|5|Statistics|6|Sys| + +## Module and Packages | [[Study]]() | [[Code]]() + + + +## Pytorch Deeplearning | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Deeplearning_with_Pytorch) +- Differentiation, Probability, Neural Networks + + +## Reference +``` +[1] 김상형,『파이썬 정복』, 한빛미디어(2018) +[2] Dive into Deep Learning, http://d2l.ai/ +``` From f65ec32d7534c8ee83869111e75eec9348773e87 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 11:35:31 +0900 Subject: [PATCH 39/60] Update README.md --- Module_and_Package/README.md | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/Module_and_Package/README.md b/Module_and_Package/README.md index 99eb0cc..bbe9682 100644 --- a/Module_and_Package/README.md +++ b/Module_and_Package/README.md @@ -1,31 +1 @@ -# Python Toolbox (20200728 ~) -- My personal toolbox that contains my daily python tools for datascience and machinelearning - -## Python Basic -### 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/1_Basic_Structure.ipynb) -|No.|Contents|No.|Contents|No.|Contents|No.|Contents| -|------|---|---|---|---|---|---|---| -|1|Print|2|Variable|3|Function|4|Method| -|5|Formatting|6|List and Tuple|7|Dictionary|8|Set| -|9|Collection|10|Lambda Function|11|Copy|12|| - -### 2.Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/2_Standard_Modules.ipynb) -|No.|Contents|No.|Contents| -|------|---|------|---| -|1|Random|2|Time| -|3|Calendar|4|Math| -|5|Statistics|6|Sys| - -## Module and Packages | [[Study]]() | [[Code]]() - - - -## Pytorch Deeplearning | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Deeplearning_with_Pytorch) -- Differentiation, Probability, Neural Networks - - -## Reference -``` -[1] 김상형,『파이썬 정복』, 한빛미디어(2018) -[2] Dive into Deep Learning, http://d2l.ai/ -``` +# Module and Package From a6708e7881d0623684f9b67c72d2a1baabf209a5 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 11:35:47 +0900 Subject: [PATCH 40/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99eb0cc..bc74fd0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ |3|Calendar|4|Math| |5|Statistics|6|Sys| -## Module and Packages | [[Study]]() | [[Code]]() +## Module and Packages | [[Study]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Module_and_Package/README.md) | [[Code]]() From def0b04932a83a7eba673dc39e63053c7da059af Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 11:36:12 +0900 Subject: [PATCH 41/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bc74fd0..752c5fa 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ |3|Calendar|4|Math| |5|Statistics|6|Sys| -## Module and Packages | [[Study]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Module_and_Package/README.md) | [[Code]]() +## Module and Packages | [Study](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Module_and_Package/README.md) | [Code]() From 388fc22e51b9af01cc382524faa92e588a749bc0 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 13:17:25 +0900 Subject: [PATCH 42/60] Update README.md --- Module_and_Package/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Module_and_Package/README.md b/Module_and_Package/README.md index bbe9682..d061576 100644 --- a/Module_and_Package/README.md +++ b/Module_and_Package/README.md @@ -1 +1,22 @@ # Module and Package +- Resuable tools in python +- It is in a single file with ".py" file extension, and several modules are managed in a "Package" +- +## Basic structure of python project +``` +ROOT +├── setup.py +└── algorithms + ├── __init__.py + ├── array.py +└── tests + ├── __init__.py + └── test_array.py +``` +- If "__init__.py" file exists in the directory, it is considered a package. +- It uses a module called ```array```, which is being tested from a package called ```algorithms```. + +## test_array.py | [[Code]]() +- ```from [package_name] import [module_name]``` +-> Use modules from packages +-> When a package is referenced from outside, the "__init__.py" in the package is executed. From 22ef0f4243a6affbd9c31133f6abadcb54324e74 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 14:09:12 +0900 Subject: [PATCH 43/60] Update README.md --- Module_and_Package/README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Module_and_Package/README.md b/Module_and_Package/README.md index d061576..b65c672 100644 --- a/Module_and_Package/README.md +++ b/Module_and_Package/README.md @@ -16,7 +16,22 @@ ROOT - If "__init__.py" file exists in the directory, it is considered a package. - It uses a module called ```array```, which is being tested from a package called ```algorithms```. -## test_array.py | [[Code]]() +### test_array.py | [[Code]]() - ```from [package_name] import [module_name]``` -> Use modules from packages --> When a package is referenced from outside, the "__init__.py" in the package is executed. + + +### algorithms/__init__.py | [[Code]]() +- When a package is referenced from outside, the "__init__.py" in the package is executed. + +### setup.py | [[Code]]() +- Determine the top-level directory of the project with ```setup.py``` +- Contains information necessary for testing, building, and deployment of the project. +-> [Using the ```setuptools``` package](https://packaging.python.org/tutorials/packaging-projects/#setup-args). +- Install required packages in execution environment of the project +``` $ python setup.py install``` +- Build and Test the project ("Build" : Packaging steps for publishing the repository, not Compiling) +``` $ python setup.py build``` +``` $ python setup.py test``` + + From 76b72753b0759c7ee49dd0c9fe45d841053c22fc Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 14:09:44 +0900 Subject: [PATCH 44/60] Update README.md --- Module_and_Package/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Module_and_Package/README.md b/Module_and_Package/README.md index b65c672..4c9fa56 100644 --- a/Module_and_Package/README.md +++ b/Module_and_Package/README.md @@ -28,10 +28,10 @@ ROOT - Determine the top-level directory of the project with ```setup.py``` - Contains information necessary for testing, building, and deployment of the project. -> [Using the ```setuptools``` package](https://packaging.python.org/tutorials/packaging-projects/#setup-args). -- Install required packages in execution environment of the project +- Install required packages in execution environment of the project ``` $ python setup.py install``` -- Build and Test the project ("Build" : Packaging steps for publishing the repository, not Compiling) -``` $ python setup.py build``` +- Build and Test the project ("Build" : Packaging steps for publishing the repository, not Compiling) +``` $ python setup.py build``` ``` $ python setup.py test``` From 4c54c72b3b859c34218e8708bd2b9536d8d688d2 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 14:20:13 +0900 Subject: [PATCH 45/60] Update README.md --- Module_and_Package/README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Module_and_Package/README.md b/Module_and_Package/README.md index 4c9fa56..565c795 100644 --- a/Module_and_Package/README.md +++ b/Module_and_Package/README.md @@ -2,10 +2,11 @@ - Resuable tools in python - It is in a single file with ".py" file extension, and several modules are managed in a "Package" - -## Basic structure of python project +## 1. Basic structure of python project ``` ROOT ├── setup.py +├── requirements.txt └── algorithms ├── __init__.py ├── array.py @@ -34,4 +35,33 @@ ROOT ``` $ python setup.py build``` ``` $ python setup.py test``` +## 2. Pip +- Downloading packages from PyPI and integrating them into the project. +1. Pip version check +``` $ pip --version ``` +2. Update +``` $ pip install -U pip``` # On Linux or OS X +``` $ python -m pip install -U pip``` # On Windows +3. Install the package registered in PyPI, Python Package Index +``` $ pip install requests``` +``` $ pip install requests==2.18.0``` +4. Install the package using Requirements Files +``` $ pip install -r requirements.txt``` +- Summary +``` +$ python +$ python hello_world.py +$ python -m unittest +$ python -m unittest tests/test_array.py +$ python setup.py install +$ python setup.py test +$ pip install [package_name] +$ pip install -U [package_name] +$ pip install -U requirements.txt +$ pip install -U -r requirements.txt +``` +## References +``` +[1] 파이썬 프로젝트의 구조, https://www.holaxprogramming.com/2017/06/28/python-project-structures/ +``` From 7ae9bde51745a688f95c740e8bf67942d36b6b1c Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 14:20:59 +0900 Subject: [PATCH 46/60] Update README.md --- Module_and_Package/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Module_and_Package/README.md b/Module_and_Package/README.md index 565c795..d363bca 100644 --- a/Module_and_Package/README.md +++ b/Module_and_Package/README.md @@ -1,7 +1,7 @@ # Module and Package - Resuable tools in python - It is in a single file with ".py" file extension, and several modules are managed in a "Package" -- + ## 1. Basic structure of python project ``` ROOT From 043bb0f605bbb97ff1db7c1d452e6614002acecb Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 14:34:59 +0900 Subject: [PATCH 47/60] Update README.md --- Module_and_Package/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Module_and_Package/README.md b/Module_and_Package/README.md index d363bca..4bc72c8 100644 --- a/Module_and_Package/README.md +++ b/Module_and_Package/README.md @@ -23,7 +23,9 @@ ROOT ### algorithms/__init__.py | [[Code]]() -- When a package is referenced from outside, the "__init__.py" in the package is executed. +- When a package is referenced from outside, the ```__init__.py``` in the package is executed. +- Each directory in the package must have ```__init__.py```. +- ```__init__.py``` may be empty or may provide information about the modules contained in the package. ### setup.py | [[Code]]() - Determine the top-level directory of the project with ```setup.py``` From cb48ae3190267f9140b477955a55449762b74a1d Mon Sep 17 00:00:00 2001 From: OH-Seoyoung Date: Wed, 12 May 2021 14:35:36 +0900 Subject: [PATCH 48/60] 20210512 --- .../Untitled-checkpoint.ipynb | 6 ---- Module_and_Package/Untitled.ipynb | 32 ------------------- Module_and_Package/algorithms/__init__.py | 5 +++ Module_and_Package/algorithms/array.py | 3 ++ Module_and_Package/setup.py | 23 +++++++++++++ Module_and_Package/tests/test_array.py | 7 ++++ 6 files changed, 38 insertions(+), 38 deletions(-) delete mode 100644 Module_and_Package/.ipynb_checkpoints/Untitled-checkpoint.ipynb delete mode 100644 Module_and_Package/Untitled.ipynb create mode 100644 Module_and_Package/algorithms/__init__.py create mode 100644 Module_and_Package/algorithms/array.py create mode 100644 Module_and_Package/setup.py create mode 100644 Module_and_Package/tests/test_array.py diff --git a/Module_and_Package/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/Module_and_Package/.ipynb_checkpoints/Untitled-checkpoint.ipynb deleted file mode 100644 index 7fec515..0000000 --- a/Module_and_Package/.ipynb_checkpoints/Untitled-checkpoint.ipynb +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cells": [], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/Module_and_Package/Untitled.ipynb b/Module_and_Package/Untitled.ipynb deleted file mode 100644 index 35eac67..0000000 --- a/Module_and_Package/Untitled.ipynb +++ /dev/null @@ -1,32 +0,0 @@ -{ - "cells": [ - { - "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.6" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/Module_and_Package/algorithms/__init__.py b/Module_and_Package/algorithms/__init__.py new file mode 100644 index 0000000..194530a --- /dev/null +++ b/Module_and_Package/algorithms/__init__.py @@ -0,0 +1,5 @@ +# Description for Package +from algorithms.array import Array + +__all__ = ['array'] +__version__ = '0.1.0' # Package version diff --git a/Module_and_Package/algorithms/array.py b/Module_and_Package/algorithms/array.py new file mode 100644 index 0000000..0c6a30c --- /dev/null +++ b/Module_and_Package/algorithms/array.py @@ -0,0 +1,3 @@ +class Array(object): + def sum(self, size, array_string): + return 0 diff --git a/Module_and_Package/setup.py b/Module_and_Package/setup.py new file mode 100644 index 0000000..0901c6e --- /dev/null +++ b/Module_and_Package/setup.py @@ -0,0 +1,23 @@ +import io +from setuptools import find_packages, setup + +def long_description(): + with io.open('README.rst', 'r', encoding = 'utf-8') ad f: + readme = f.read() + return readme + +setup(name = 'algorithms', + version = '0.1', + description = 'practice python with solving algorithms', + long_description = long_description(), + url = 'http://github.com/stunstunstun/awesome-algorithms', + author = 'stunstunstun', + author_email = 'agileboys.com@gmail.com', + license = 'MIT', + packages = find_packages(), + classifiers = [ + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + ], + zip_safe = False) diff --git a/Module_and_Package/tests/test_array.py b/Module_and_Package/tests/test_array.py new file mode 100644 index 0000000..48b50c1 --- /dev/null +++ b/Module_and_Package/tests/test_array.py @@ -0,0 +1,7 @@ +import unittest +from algorithms import array + +class TestArray(unittest.TestCase): + # Create class instance + def setUp(self): + self.array = array.Array('1 2 3 4 10 11') From 850dadeacad3dd75757f7aaad7bdc0f495c739c3 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 14:37:09 +0900 Subject: [PATCH 49/60] Update README.md --- Module_and_Package/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Module_and_Package/README.md b/Module_and_Package/README.md index 4bc72c8..ba40e7f 100644 --- a/Module_and_Package/README.md +++ b/Module_and_Package/README.md @@ -14,7 +14,7 @@ ROOT ├── __init__.py └── test_array.py ``` -- If "__init__.py" file exists in the directory, it is considered a package. +- If ```__init__.py``` exists in the directory, it is considered a package. - It uses a module called ```array```, which is being tested from a package called ```algorithms```. ### test_array.py | [[Code]]() From 8d18f70c393a78365124509f942dfb4f6a2a08fb Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 14:37:52 +0900 Subject: [PATCH 50/60] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 752c5fa..cf1faea 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ |3|Calendar|4|Math| |5|Statistics|6|Sys| -## Module and Packages | [Study](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Module_and_Package/README.md) | [Code]() - +## Module and Packages | [Study](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Module_and_Package/README.md) | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Module_and_Package) +- Structure of python project, Pip ## Pytorch Deeplearning | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Deeplearning_with_Pytorch) From cf58a1119e8919111458157a48465d3380e04946 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Wed, 12 May 2021 14:38:14 +0900 Subject: [PATCH 51/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf1faea..454e39d 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ |3|Calendar|4|Math| |5|Statistics|6|Sys| -## Module and Packages | [Study](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Module_and_Package/README.md) | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Module_and_Package) +## Module and Packages | [[Study]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Module_and_Package/README.md) | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Module_and_Package) - Structure of python project, Pip From 2c2fdf7eadb069d8baa7cfe3e95b4ace7ff386ae Mon Sep 17 00:00:00 2001 From: OH-Seoyoung Date: Sat, 29 May 2021 21:26:27 +0900 Subject: [PATCH 52/60] 20210529 --- .../Deeplearning_Computation-checkpoint.ipynb | 838 ++++++++++++++++++ .../Softmax_Regression-checkpoint.ipynb | 6 + .../Deeplearning_Computation.ipynb | 838 ++++++++++++++++++ Deeplearning_with_Pytorch/mlp.params | Bin 0 -> 33487 bytes Deeplearning_with_Pytorch/mydict | Bin 0 -> 1087 bytes Deeplearning_with_Pytorch/x-file | Bin 0 -> 759 bytes Deeplearning_with_Pytorch/x-files | Bin 0 -> 1087 bytes 7 files changed, 1682 insertions(+) create mode 100644 Deeplearning_with_Pytorch/.ipynb_checkpoints/Deeplearning_Computation-checkpoint.ipynb create mode 100644 Deeplearning_with_Pytorch/.ipynb_checkpoints/Softmax_Regression-checkpoint.ipynb create mode 100644 Deeplearning_with_Pytorch/Deeplearning_Computation.ipynb create mode 100644 Deeplearning_with_Pytorch/mlp.params create mode 100644 Deeplearning_with_Pytorch/mydict create mode 100644 Deeplearning_with_Pytorch/x-file create mode 100644 Deeplearning_with_Pytorch/x-files diff --git a/Deeplearning_with_Pytorch/.ipynb_checkpoints/Deeplearning_Computation-checkpoint.ipynb b/Deeplearning_with_Pytorch/.ipynb_checkpoints/Deeplearning_Computation-checkpoint.ipynb new file mode 100644 index 0000000..46397d6 --- /dev/null +++ b/Deeplearning_with_Pytorch/.ipynb_checkpoints/Deeplearning_Computation-checkpoint.ipynb @@ -0,0 +1,838 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Deeplearning computation\n", + "### 1. Layers and Blocks" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[ 0.0242, -0.1950, -0.1941, 0.0628, -0.0397, -0.0054, 0.2011, 0.1221,\n", + " -0.0935, -0.2975],\n", + " [ 0.0496, -0.2916, -0.0864, -0.0426, -0.0730, -0.0218, 0.2579, 0.0508,\n", + " -0.1628, -0.2782]], grad_fn=)" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "from torch import nn\n", + "from torch.nn import functional as F\n", + "\n", + "net = nn.Sequential(nn.Linear(20, 256), nn.ReLU(), nn.Linear(256, 10))\n", + "\n", + "X = torch.rand(2, 20)\n", + "net(X)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "class MLP(nn.Module):\n", + " def __init__(self):\n", + " # Call the constructor of the `MLP` parent class `Module` to perform the necessary initialization.\n", + " # other function arguments can also be specified during class instantiation, such as the model parameters\n", + " super().__init__()\n", + " self.hidden = nn.Linear(20, 256) \n", + " self.out = nn.Linear(256, 10) \n", + "\n", + " # Define the forward propagation\n", + " # required model output based on the input `X`\n", + " def forward(self, X):\n", + " return self.out(F.relu(self.hidden(X)))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[ 0.0699, 0.1001, 0.2061, 0.3083, 0.1851, -0.1136, -0.0931, -0.0112,\n", + " 0.1837, 0.2294],\n", + " [ 0.0458, 0.1339, 0.0996, 0.3237, 0.1989, -0.1045, -0.0070, 0.0321,\n", + " 0.1740, 0.1794]], grad_fn=)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net = MLP()\n", + "net(X)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "class MySequential(nn.Module):\n", + " def __init__(self, *args):\n", + " super().__init__()\n", + " for idx, module in enumerate(args):\n", + " # Here, `module` is an instance of a `Module` subclass. We save it\n", + " # in the member variable `_modules` of the `Module` class, and its\n", + " # type is OrderedDict\n", + " self._modules[str(idx)] = module\n", + "\n", + " def forward(self, X):\n", + " # OrderedDict guarantees that members will be traversed in the order\n", + " # they were added\n", + " for block in self._modules.values():\n", + " X = block(X)\n", + " return X" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[-0.0629, 0.0844, -0.2088, -0.2166, 0.1139, 0.1790, -0.1627, 0.2149,\n", + " -0.0859, -0.0054],\n", + " [-0.0653, 0.0852, -0.1416, -0.0915, 0.1601, 0.2436, -0.2000, 0.2560,\n", + " -0.0263, -0.0032]], grad_fn=)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net = MySequential(nn.Linear(20, 256), nn.ReLU(), nn.Linear(256, 10))\n", + "net(X)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2. Parameter Management" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[0.1365],\n", + " [0.1754]], grad_fn=)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "from torch import nn\n", + "\n", + "net = nn.Sequential(nn.Linear(4, 8), nn.ReLU(), nn.Linear(8, 1))\n", + "X = torch.rand(size=(2, 4))\n", + "net(X)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "OrderedDict([('weight', tensor([[-0.3489, 0.1564, -0.2279, -0.0319, -0.3372, -0.1410, -0.3041, -0.1298]])), ('bias', tensor([0.2592]))])\n" + ] + } + ], + "source": [ + "print(net[2].state_dict())" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[0.3830],\n", + " [0.3830]], grad_fn=)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def block1():\n", + " return nn.Sequential(nn.Linear(4, 8), nn.ReLU(), nn.Linear(8, 4),\n", + " nn.ReLU())\n", + "\n", + "def block2():\n", + " net = nn.Sequential()\n", + " for i in range(4):\n", + " # Nested here\n", + " net.add_module(f'block {i}', block1())\n", + " return net\n", + "\n", + "rgnet = nn.Sequential(block2(), nn.Linear(4, 1))\n", + "rgnet(X)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sequential(\n", + " (0): Sequential(\n", + " (block 0): Sequential(\n", + " (0): Linear(in_features=4, out_features=8, bias=True)\n", + " (1): ReLU()\n", + " (2): Linear(in_features=8, out_features=4, bias=True)\n", + " (3): ReLU()\n", + " )\n", + " (block 1): Sequential(\n", + " (0): Linear(in_features=4, out_features=8, bias=True)\n", + " (1): ReLU()\n", + " (2): Linear(in_features=8, out_features=4, bias=True)\n", + " (3): ReLU()\n", + " )\n", + " (block 2): Sequential(\n", + " (0): Linear(in_features=4, out_features=8, bias=True)\n", + " (1): ReLU()\n", + " (2): Linear(in_features=8, out_features=4, bias=True)\n", + " (3): ReLU()\n", + " )\n", + " (block 3): Sequential(\n", + " (0): Linear(in_features=4, out_features=8, bias=True)\n", + " (1): ReLU()\n", + " (2): Linear(in_features=8, out_features=4, bias=True)\n", + " (3): ReLU()\n", + " )\n", + " )\n", + " (1): Linear(in_features=4, out_features=1, bias=True)\n", + ")\n" + ] + } + ], + "source": [ + "print(rgnet)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([ 0.1514, 0.4772, -0.3789, -0.1574, -0.2709, 0.1434, 0.2604, 0.1770])" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rgnet[0][1][0].bias.data" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(tensor([-0.0056, -0.0058, 0.0093, 0.0013]), tensor(0.))" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def init_normal(m):\n", + " if type(m) == nn.Linear:\n", + " nn.init.normal_(m.weight, mean=0, std=0.01)\n", + " nn.init.zeros_(m.bias)\n", + "\n", + "net.apply(init_normal)\n", + "net[0].weight.data[0], net[0].bias.data[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Init weight torch.Size([8, 4])\n", + "Init weight torch.Size([1, 8])\n" + ] + }, + { + "data": { + "text/plain": [ + "tensor([[-0.0000, -0.0000, -6.6474, 8.8518],\n", + " [ 7.7771, -6.5521, 6.6729, -0.0000]], grad_fn=)" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def my_init(m):\n", + " if type(m) == nn.Linear:\n", + " print(\n", + " \"Init\",\n", + " *[(name, param.shape) for name, param in m.named_parameters()][0])\n", + " nn.init.uniform_(m.weight, -10, 10)\n", + " m.weight.data *= m.weight.data.abs() >= 5\n", + "\n", + "net.apply(my_init)\n", + "net[0].weight[:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "tensor([True, True, True, True, True, True, True, True])\n", + "tensor([True, True, True, True, True, True, True, True])\n" + ] + } + ], + "source": [ + "# We need to give the shared layer a name so that we can refer to its parameters\n", + "shared = nn.Linear(8, 8)\n", + "net = nn.Sequential(nn.Linear(4, 8), nn.ReLU(), shared, nn.ReLU(), shared, nn.ReLU(), nn.Linear(8, 1))\n", + "net(X)\n", + "\n", + "# Check whether the parameters are the same\n", + "print(net[2].weight.data[0] == net[4].weight.data[0])\n", + "net[2].weight.data[0, 0] = 100\n", + "\n", + "# Make sure that they are actually the same object rather than just having thesame value\n", + "print(net[2].weight.data[0] == net[4].weight.data[0])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3. Deferred Initialization" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "import tensorflow as tf\n", + "\n", + "net = tf.keras.models.Sequential([\n", + " tf.keras.layers.Dense(256, activation=tf.nn.relu),\n", + " tf.keras.layers.Dense(10),])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[], []]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[net.layers[i].get_weights() for i in range(len(net.layers))]" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[(20, 256), (256,), (256, 10), (10,)]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "X = tf.random.uniform((2, 20))\n", + "net(X)\n", + "[w.shape for w in net.get_weights()]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 4. Custom layers" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "import torch\n", + "from torch import nn\n", + "from torch.nn import functional as F\n", + "\n", + "class CenteredLayer(nn.Module):\n", + " def __init__(self):\n", + " super().__init__()\n", + "\n", + " def forward(self, X):\n", + " return X - X.mean()" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([-2., -1., 0., 1., 2.])" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "layer = CenteredLayer()\n", + "layer(torch.FloatTensor([1, 2, 3, 4, 5]))" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "net = nn.Sequential(nn.Linear(8, 128), CenteredLayer())" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor(-1.1176e-08, grad_fn=)" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Y = net(torch.rand(4, 8))\n", + "Y.mean()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "class MyLinear(nn.Module):\n", + " def __init__(self, in_units, units):\n", + " super().__init__()\n", + " self.weight = nn.Parameter(torch.randn(in_units, units))\n", + " self.bias = nn.Parameter(torch.randn(units,))\n", + "\n", + " def forward(self, X):\n", + " linear = torch.matmul(X, self.weight.data) + self.bias.data\n", + " return F.relu(linear)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Parameter containing:\n", + "tensor([[-0.5551, -1.0702, 1.0787],\n", + " [ 0.4654, -0.2897, 0.4270],\n", + " [ 1.2058, -0.2476, 0.0780],\n", + " [ 0.2457, 1.3174, -0.6553],\n", + " [ 0.7457, 0.6414, 0.4263]], requires_grad=True)" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dense = MyLinear(5, 3)\n", + "dense.weight" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[2.7336, 2.0793, 0.5800],\n", + " [1.5111, 0.4548, 1.3087]])" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dense(torch.rand(2, 5))" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[0.],\n", + " [0.]])" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net = nn.Sequential(MyLinear(64, 8), MyLinear(8, 1))\n", + "net(torch.rand(2, 64))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 5. File I/O" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "import torch\n", + "from torch import nn\n", + "from torch.nn import functional as F\n", + "\n", + "x = torch.arange(4)\n", + "torch.save(x, 'x-file')" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0, 1, 2, 3])" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x2 = torch.load(\"x-file\")\n", + "x2" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(tensor([0, 1, 2, 3]), tensor([0., 0., 0., 0.]))" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y = torch.zeros(4)\n", + "torch.save([x, y], 'x-files')\n", + "x2, y2 = torch.load('x-files')\n", + "(x2, y2)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'x': tensor([0, 1, 2, 3]), 'y': tensor([0., 0., 0., 0.])}" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mydict = {'x': x, 'y': y}\n", + "torch.save(mydict, 'mydict')\n", + "mydict2 = torch.load('mydict')\n", + "mydict2" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "class MLP(nn.Module):\n", + " def __init__(self):\n", + " super().__init__()\n", + " self.hidden = nn.Linear(20, 256)\n", + " self.output = nn.Linear(256, 10)\n", + "\n", + " def forward(self, x):\n", + " return self.output(F.relu(self.hidden(x)))\n", + "\n", + "net = MLP()\n", + "X = torch.randn(size=(2, 20))\n", + "Y = net(X)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "torch.save(net.state_dict(), 'mlp.params')" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "MLP(\n", + " (hidden): Linear(in_features=20, out_features=256, bias=True)\n", + " (output): Linear(in_features=256, out_features=10, bias=True)\n", + ")" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "clone = MLP()\n", + "clone.load_state_dict(torch.load(\"mlp.params\"))\n", + "clone.eval()" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[True, True, True, True, True, True, True, True, True, True],\n", + " [True, True, True, True, True, True, True, True, True, True]])" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Y_clone = clone(X)\n", + "Y_clone == Y" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 6. GPU" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sat May 29 20:55:15 2021 \n", + "+-----------------------------------------------------------------------------+\n", + "| NVIDIA-SMI 457.30 Driver Version: 457.30 CUDA Version: 11.1 |\n", + "|-------------------------------+----------------------+----------------------+\n", + "| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |\n", + "| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n", + "| | | MIG M. |\n", + "|===============================+======================+======================|\n", + "| 0 GeForce GTX 1660 WDDM | 00000000:01:00.0 On | N/A |\n", + "| 60% 57C P0 56W / 130W | 3794MiB / 6144MiB | 42% Default |\n", + "| | | N/A |\n", + "+-------------------------------+----------------------+----------------------+\n", + " \n", + "+-----------------------------------------------------------------------------+\n", + "| Processes: |\n", + "| GPU GI CI PID Type Process name GPU Memory |\n", + "| ID ID Usage |\n", + "|=============================================================================|\n", + "| 0 N/A N/A 1544 C+G ...in7x64\\steamwebhelper.exe N/A |\n", + "| 0 N/A N/A 1948 C+G ...cw5n1h2txyewy\\LockApp.exe N/A |\n", + "| 0 N/A N/A 3792 C+G ...artMenuExperienceHost.exe N/A |\n", + "| 0 N/A N/A 6556 C+G ...5n1h2txyewy\\SearchApp.exe N/A |\n", + "| 0 N/A N/A 7824 C+G Insufficient Permissions N/A |\n", + "| 0 N/A N/A 9456 C+G ...wekyb3d8bbwe\\Video.UI.exe N/A |\n", + "| 0 N/A N/A 9556 C+G ...y\\ShellExperienceHost.exe N/A |\n", + "| 0 N/A N/A 10116 C+G ...ekyb3d8bbwe\\YourPhone.exe N/A |\n", + "| 0 N/A N/A 13712 C+G ...nputApp\\TextInputHost.exe N/A |\n", + "| 0 N/A N/A 21312 C+G ...ommon\\Rust\\RustClient.exe N/A |\n", + "| 0 N/A N/A 22280 C+G ...\\app-1.0.9002\\Discord.exe N/A |\n", + "| 0 N/A N/A 23280 C+G C:\\Windows\\explorer.exe N/A |\n", + "| 0 N/A N/A 23456 C+G ...oot\\Office16\\POWERPNT.EXE N/A |\n", + "| 0 N/A N/A 25128 C+G ...me\\Application\\chrome.exe N/A |\n", + "+-----------------------------------------------------------------------------+\n" + ] + } + ], + "source": [ + "!nvidia-smi" + ] + } + ], + "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.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Deeplearning_with_Pytorch/.ipynb_checkpoints/Softmax_Regression-checkpoint.ipynb b/Deeplearning_with_Pytorch/.ipynb_checkpoints/Softmax_Regression-checkpoint.ipynb new file mode 100644 index 0000000..7fec515 --- /dev/null +++ b/Deeplearning_with_Pytorch/.ipynb_checkpoints/Softmax_Regression-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Deeplearning_with_Pytorch/Deeplearning_Computation.ipynb b/Deeplearning_with_Pytorch/Deeplearning_Computation.ipynb new file mode 100644 index 0000000..46397d6 --- /dev/null +++ b/Deeplearning_with_Pytorch/Deeplearning_Computation.ipynb @@ -0,0 +1,838 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Deeplearning computation\n", + "### 1. Layers and Blocks" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[ 0.0242, -0.1950, -0.1941, 0.0628, -0.0397, -0.0054, 0.2011, 0.1221,\n", + " -0.0935, -0.2975],\n", + " [ 0.0496, -0.2916, -0.0864, -0.0426, -0.0730, -0.0218, 0.2579, 0.0508,\n", + " -0.1628, -0.2782]], grad_fn=)" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "from torch import nn\n", + "from torch.nn import functional as F\n", + "\n", + "net = nn.Sequential(nn.Linear(20, 256), nn.ReLU(), nn.Linear(256, 10))\n", + "\n", + "X = torch.rand(2, 20)\n", + "net(X)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "class MLP(nn.Module):\n", + " def __init__(self):\n", + " # Call the constructor of the `MLP` parent class `Module` to perform the necessary initialization.\n", + " # other function arguments can also be specified during class instantiation, such as the model parameters\n", + " super().__init__()\n", + " self.hidden = nn.Linear(20, 256) \n", + " self.out = nn.Linear(256, 10) \n", + "\n", + " # Define the forward propagation\n", + " # required model output based on the input `X`\n", + " def forward(self, X):\n", + " return self.out(F.relu(self.hidden(X)))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[ 0.0699, 0.1001, 0.2061, 0.3083, 0.1851, -0.1136, -0.0931, -0.0112,\n", + " 0.1837, 0.2294],\n", + " [ 0.0458, 0.1339, 0.0996, 0.3237, 0.1989, -0.1045, -0.0070, 0.0321,\n", + " 0.1740, 0.1794]], grad_fn=)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net = MLP()\n", + "net(X)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "class MySequential(nn.Module):\n", + " def __init__(self, *args):\n", + " super().__init__()\n", + " for idx, module in enumerate(args):\n", + " # Here, `module` is an instance of a `Module` subclass. We save it\n", + " # in the member variable `_modules` of the `Module` class, and its\n", + " # type is OrderedDict\n", + " self._modules[str(idx)] = module\n", + "\n", + " def forward(self, X):\n", + " # OrderedDict guarantees that members will be traversed in the order\n", + " # they were added\n", + " for block in self._modules.values():\n", + " X = block(X)\n", + " return X" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[-0.0629, 0.0844, -0.2088, -0.2166, 0.1139, 0.1790, -0.1627, 0.2149,\n", + " -0.0859, -0.0054],\n", + " [-0.0653, 0.0852, -0.1416, -0.0915, 0.1601, 0.2436, -0.2000, 0.2560,\n", + " -0.0263, -0.0032]], grad_fn=)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net = MySequential(nn.Linear(20, 256), nn.ReLU(), nn.Linear(256, 10))\n", + "net(X)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2. Parameter Management" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[0.1365],\n", + " [0.1754]], grad_fn=)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import torch\n", + "from torch import nn\n", + "\n", + "net = nn.Sequential(nn.Linear(4, 8), nn.ReLU(), nn.Linear(8, 1))\n", + "X = torch.rand(size=(2, 4))\n", + "net(X)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "OrderedDict([('weight', tensor([[-0.3489, 0.1564, -0.2279, -0.0319, -0.3372, -0.1410, -0.3041, -0.1298]])), ('bias', tensor([0.2592]))])\n" + ] + } + ], + "source": [ + "print(net[2].state_dict())" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[0.3830],\n", + " [0.3830]], grad_fn=)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def block1():\n", + " return nn.Sequential(nn.Linear(4, 8), nn.ReLU(), nn.Linear(8, 4),\n", + " nn.ReLU())\n", + "\n", + "def block2():\n", + " net = nn.Sequential()\n", + " for i in range(4):\n", + " # Nested here\n", + " net.add_module(f'block {i}', block1())\n", + " return net\n", + "\n", + "rgnet = nn.Sequential(block2(), nn.Linear(4, 1))\n", + "rgnet(X)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sequential(\n", + " (0): Sequential(\n", + " (block 0): Sequential(\n", + " (0): Linear(in_features=4, out_features=8, bias=True)\n", + " (1): ReLU()\n", + " (2): Linear(in_features=8, out_features=4, bias=True)\n", + " (3): ReLU()\n", + " )\n", + " (block 1): Sequential(\n", + " (0): Linear(in_features=4, out_features=8, bias=True)\n", + " (1): ReLU()\n", + " (2): Linear(in_features=8, out_features=4, bias=True)\n", + " (3): ReLU()\n", + " )\n", + " (block 2): Sequential(\n", + " (0): Linear(in_features=4, out_features=8, bias=True)\n", + " (1): ReLU()\n", + " (2): Linear(in_features=8, out_features=4, bias=True)\n", + " (3): ReLU()\n", + " )\n", + " (block 3): Sequential(\n", + " (0): Linear(in_features=4, out_features=8, bias=True)\n", + " (1): ReLU()\n", + " (2): Linear(in_features=8, out_features=4, bias=True)\n", + " (3): ReLU()\n", + " )\n", + " )\n", + " (1): Linear(in_features=4, out_features=1, bias=True)\n", + ")\n" + ] + } + ], + "source": [ + "print(rgnet)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([ 0.1514, 0.4772, -0.3789, -0.1574, -0.2709, 0.1434, 0.2604, 0.1770])" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rgnet[0][1][0].bias.data" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(tensor([-0.0056, -0.0058, 0.0093, 0.0013]), tensor(0.))" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def init_normal(m):\n", + " if type(m) == nn.Linear:\n", + " nn.init.normal_(m.weight, mean=0, std=0.01)\n", + " nn.init.zeros_(m.bias)\n", + "\n", + "net.apply(init_normal)\n", + "net[0].weight.data[0], net[0].bias.data[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Init weight torch.Size([8, 4])\n", + "Init weight torch.Size([1, 8])\n" + ] + }, + { + "data": { + "text/plain": [ + "tensor([[-0.0000, -0.0000, -6.6474, 8.8518],\n", + " [ 7.7771, -6.5521, 6.6729, -0.0000]], grad_fn=)" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def my_init(m):\n", + " if type(m) == nn.Linear:\n", + " print(\n", + " \"Init\",\n", + " *[(name, param.shape) for name, param in m.named_parameters()][0])\n", + " nn.init.uniform_(m.weight, -10, 10)\n", + " m.weight.data *= m.weight.data.abs() >= 5\n", + "\n", + "net.apply(my_init)\n", + "net[0].weight[:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "tensor([True, True, True, True, True, True, True, True])\n", + "tensor([True, True, True, True, True, True, True, True])\n" + ] + } + ], + "source": [ + "# We need to give the shared layer a name so that we can refer to its parameters\n", + "shared = nn.Linear(8, 8)\n", + "net = nn.Sequential(nn.Linear(4, 8), nn.ReLU(), shared, nn.ReLU(), shared, nn.ReLU(), nn.Linear(8, 1))\n", + "net(X)\n", + "\n", + "# Check whether the parameters are the same\n", + "print(net[2].weight.data[0] == net[4].weight.data[0])\n", + "net[2].weight.data[0, 0] = 100\n", + "\n", + "# Make sure that they are actually the same object rather than just having thesame value\n", + "print(net[2].weight.data[0] == net[4].weight.data[0])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3. Deferred Initialization" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "import tensorflow as tf\n", + "\n", + "net = tf.keras.models.Sequential([\n", + " tf.keras.layers.Dense(256, activation=tf.nn.relu),\n", + " tf.keras.layers.Dense(10),])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[], []]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[net.layers[i].get_weights() for i in range(len(net.layers))]" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[(20, 256), (256,), (256, 10), (10,)]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "X = tf.random.uniform((2, 20))\n", + "net(X)\n", + "[w.shape for w in net.get_weights()]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 4. Custom layers" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "import torch\n", + "from torch import nn\n", + "from torch.nn import functional as F\n", + "\n", + "class CenteredLayer(nn.Module):\n", + " def __init__(self):\n", + " super().__init__()\n", + "\n", + " def forward(self, X):\n", + " return X - X.mean()" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([-2., -1., 0., 1., 2.])" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "layer = CenteredLayer()\n", + "layer(torch.FloatTensor([1, 2, 3, 4, 5]))" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "net = nn.Sequential(nn.Linear(8, 128), CenteredLayer())" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor(-1.1176e-08, grad_fn=)" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Y = net(torch.rand(4, 8))\n", + "Y.mean()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "class MyLinear(nn.Module):\n", + " def __init__(self, in_units, units):\n", + " super().__init__()\n", + " self.weight = nn.Parameter(torch.randn(in_units, units))\n", + " self.bias = nn.Parameter(torch.randn(units,))\n", + "\n", + " def forward(self, X):\n", + " linear = torch.matmul(X, self.weight.data) + self.bias.data\n", + " return F.relu(linear)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Parameter containing:\n", + "tensor([[-0.5551, -1.0702, 1.0787],\n", + " [ 0.4654, -0.2897, 0.4270],\n", + " [ 1.2058, -0.2476, 0.0780],\n", + " [ 0.2457, 1.3174, -0.6553],\n", + " [ 0.7457, 0.6414, 0.4263]], requires_grad=True)" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dense = MyLinear(5, 3)\n", + "dense.weight" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[2.7336, 2.0793, 0.5800],\n", + " [1.5111, 0.4548, 1.3087]])" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dense(torch.rand(2, 5))" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[0.],\n", + " [0.]])" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net = nn.Sequential(MyLinear(64, 8), MyLinear(8, 1))\n", + "net(torch.rand(2, 64))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 5. File I/O" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "import torch\n", + "from torch import nn\n", + "from torch.nn import functional as F\n", + "\n", + "x = torch.arange(4)\n", + "torch.save(x, 'x-file')" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([0, 1, 2, 3])" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x2 = torch.load(\"x-file\")\n", + "x2" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(tensor([0, 1, 2, 3]), tensor([0., 0., 0., 0.]))" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y = torch.zeros(4)\n", + "torch.save([x, y], 'x-files')\n", + "x2, y2 = torch.load('x-files')\n", + "(x2, y2)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'x': tensor([0, 1, 2, 3]), 'y': tensor([0., 0., 0., 0.])}" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mydict = {'x': x, 'y': y}\n", + "torch.save(mydict, 'mydict')\n", + "mydict2 = torch.load('mydict')\n", + "mydict2" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "class MLP(nn.Module):\n", + " def __init__(self):\n", + " super().__init__()\n", + " self.hidden = nn.Linear(20, 256)\n", + " self.output = nn.Linear(256, 10)\n", + "\n", + " def forward(self, x):\n", + " return self.output(F.relu(self.hidden(x)))\n", + "\n", + "net = MLP()\n", + "X = torch.randn(size=(2, 20))\n", + "Y = net(X)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "torch.save(net.state_dict(), 'mlp.params')" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "MLP(\n", + " (hidden): Linear(in_features=20, out_features=256, bias=True)\n", + " (output): Linear(in_features=256, out_features=10, bias=True)\n", + ")" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "clone = MLP()\n", + "clone.load_state_dict(torch.load(\"mlp.params\"))\n", + "clone.eval()" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tensor([[True, True, True, True, True, True, True, True, True, True],\n", + " [True, True, True, True, True, True, True, True, True, True]])" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Y_clone = clone(X)\n", + "Y_clone == Y" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 6. GPU" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sat May 29 20:55:15 2021 \n", + "+-----------------------------------------------------------------------------+\n", + "| NVIDIA-SMI 457.30 Driver Version: 457.30 CUDA Version: 11.1 |\n", + "|-------------------------------+----------------------+----------------------+\n", + "| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |\n", + "| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n", + "| | | MIG M. |\n", + "|===============================+======================+======================|\n", + "| 0 GeForce GTX 1660 WDDM | 00000000:01:00.0 On | N/A |\n", + "| 60% 57C P0 56W / 130W | 3794MiB / 6144MiB | 42% Default |\n", + "| | | N/A |\n", + "+-------------------------------+----------------------+----------------------+\n", + " \n", + "+-----------------------------------------------------------------------------+\n", + "| Processes: |\n", + "| GPU GI CI PID Type Process name GPU Memory |\n", + "| ID ID Usage |\n", + "|=============================================================================|\n", + "| 0 N/A N/A 1544 C+G ...in7x64\\steamwebhelper.exe N/A |\n", + "| 0 N/A N/A 1948 C+G ...cw5n1h2txyewy\\LockApp.exe N/A |\n", + "| 0 N/A N/A 3792 C+G ...artMenuExperienceHost.exe N/A |\n", + "| 0 N/A N/A 6556 C+G ...5n1h2txyewy\\SearchApp.exe N/A |\n", + "| 0 N/A N/A 7824 C+G Insufficient Permissions N/A |\n", + "| 0 N/A N/A 9456 C+G ...wekyb3d8bbwe\\Video.UI.exe N/A |\n", + "| 0 N/A N/A 9556 C+G ...y\\ShellExperienceHost.exe N/A |\n", + "| 0 N/A N/A 10116 C+G ...ekyb3d8bbwe\\YourPhone.exe N/A |\n", + "| 0 N/A N/A 13712 C+G ...nputApp\\TextInputHost.exe N/A |\n", + "| 0 N/A N/A 21312 C+G ...ommon\\Rust\\RustClient.exe N/A |\n", + "| 0 N/A N/A 22280 C+G ...\\app-1.0.9002\\Discord.exe N/A |\n", + "| 0 N/A N/A 23280 C+G C:\\Windows\\explorer.exe N/A |\n", + "| 0 N/A N/A 23456 C+G ...oot\\Office16\\POWERPNT.EXE N/A |\n", + "| 0 N/A N/A 25128 C+G ...me\\Application\\chrome.exe N/A |\n", + "+-----------------------------------------------------------------------------+\n" + ] + } + ], + "source": [ + "!nvidia-smi" + ] + } + ], + "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.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Deeplearning_with_Pytorch/mlp.params b/Deeplearning_with_Pytorch/mlp.params new file mode 100644 index 0000000000000000000000000000000000000000..9587819ec18e5c8de724d327aa92e8dfb4263112 GIT binary patch literal 33487 zcmZ^~3sg<(_dmQPNs=w8B-)ZB$(D3obJ|i#k|as@2q6?9j>|?maY9IP4{<_BLfUIi zp_9;|L&!ZOp+g8EyzBe@z5n+e|M#-TXzV@KXwCiX=b7ty=I1g4Mz__L$#ivP|F4%^ zW+;o9HzjVy!l{E|W0GR*6K2JGdl<+<|F@S~Ys!?l@$plqB+ZyRXTILpd9hRHO^x-O zF(pYaQPw{&v5iegCnTUJB4)ozsEOuM$G&~gE;BSj$X!t(? zyCx+X1txa;@0jK;NJ?0c^uK5USQZFgdR0=s-Pl}$J*!@4_mEO(% zCvK0VMDxJJp8p-_{~7nc1MT(y9d)RyGz%7S?MF*N75@#oCb9Q_hH3df;rb*cS_LNd zU9c?CI;4a2+oNVrO^W%?3Mcma@4QGeFI|--_FtB0``}6^jBYbOMCbpS ztwg(Ji38*QuZ#aPvPAo3iG%)oal!n__5q{Y>spAjvwCUCWdHdK`2Wo|Gnv`{mTiOn zw?*~#F#dn!-Tz8L(@8s^LNq5eop)DV>5dNhg;bosTX5N3NwI#{ASdf0*x0nC87{0=J*Kn{|A=yVy5QH(m(Skl!wDX()tMhRbznv6HBGGW0pf0y3g3P>VN;)bV)Wnz&=8zVrLW&sKjxzlgx< zwtMJZQC|)kBFCJ0kHw&kk0G-(4}{(;NqIpZ@;Zso@~0`(%5+e9{1Fu7rHJ8KA(%PF z6P1Q(Vzf&)mVIe2HVx?t{HiyqE){9wO`gMsgBF||8V%~3b#5xdWFg?p7%=Z}8d98d zDQ&I>0#=1nL*OXzG0LRssNq=mLPK-II<6?dM4{X5dV!qpXR5I3 zn>ki2cEtKGQ@C(^8r6|4<)kotvsjxq9I|A^`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}L`5IR35o^UBc@gY{V>o!={TQ+&Qq}2bNqQmsRBBlj9Cl z+!*mqf>yYl*I_XZ!3ZL)T^_)+lrzv#(LlU%KI9P<^jgM`U2lheKJM# P+Z1a$`80eeeir)#zGcr5 literal 0 HcmV?d00001 diff --git a/Deeplearning_with_Pytorch/x-file b/Deeplearning_with_Pytorch/x-file new file mode 100644 index 0000000000000000000000000000000000000000..28e2c807c0850c6ac510fcf28ba695c6ba15ba3b GIT binary patch literal 759 zcmWIWW@cev;NW1u00Im`42ea_8JT6N`YDMeiFyUuIc`pT3{fbcfhoBpAE-(%zO*DW zr6xs6vKzUSv9>eImk=-tZqV*$?hpZblxX{f( zb|F8CIR(I=gP8;McYrq=n+{Zw9J4N5IV@0N^kJyXC1~ga^?}kE!&GQ2fP@3QS=m5h L%s>cI4^ayMum6fn literal 0 HcmV?d00001 diff --git a/Deeplearning_with_Pytorch/x-files b/Deeplearning_with_Pytorch/x-files new file mode 100644 index 0000000000000000000000000000000000000000..b284ebaebbe3d895b2f93fb3c34483c249258285 GIT binary patch literal 1087 zcmah|%}&BV5MH1bTvQM}7!SrHCJG4taPc59^{^&Zj0rI@Sj&bsHq>nw&R#rtGQNNh z;nkArE&1Bo{%zWQ`JFAnFf>0)depntAkl~q@J)q@|!Hv?*wWBrW z(79x{$qR;xCU-?-som$c;21U9UZ;VwNZtTWNvei%6qOS#p?ykKA7O zbhw9Esx>P@s+HaC>Sm>~wOy~&nbJy$J@cl|rij9sdO{FU?pT^6?pWsDG+oD`Cb!+5 zkB_|$^=Rk7HaTX~YfXkZ%Qo4JCBUr_pys#+A0y7nh&#JGbv9=ONVyOx4@mR(78ERS zw$NmYw4{@CX7BkS`z5%6>l0;MM*EVCWvM-_u@@6mQuqH4fgM;PT$AAnqJaTXTtJVj z;vM`iqDvEqf+|{L@mHdvq-211MqWPhVi$ZeUJlj9cmwMB;s~`y`B#uXWT;_4e0}Pk zLFeE)NdzK{W;%LIz(}_EgvYa^+AT||heGmbwtTShI#EsJI-e8kfbQ`+(N1#`pG(p8 yh)<}ePE>V03|dKTjKjr^4{Wq%!|8bogaZjxxU1+roFe$GlPMMU6!Ad(F!mdK9n>`d literal 0 HcmV?d00001 From f4b98e3ff2191a660af376c0bec439b8250f9044 Mon Sep 17 00:00:00 2001 From: OH-Seoyoung Date: Sat, 29 May 2021 21:27:09 +0900 Subject: [PATCH 53/60] 20210529 --- .../Deeplearning_Computation-checkpoint.ipynb | 838 ------------------ .../Softmax_Regression-checkpoint.ipynb | 6 - 2 files changed, 844 deletions(-) delete mode 100644 Deeplearning_with_Pytorch/.ipynb_checkpoints/Deeplearning_Computation-checkpoint.ipynb delete mode 100644 Deeplearning_with_Pytorch/.ipynb_checkpoints/Softmax_Regression-checkpoint.ipynb diff --git a/Deeplearning_with_Pytorch/.ipynb_checkpoints/Deeplearning_Computation-checkpoint.ipynb b/Deeplearning_with_Pytorch/.ipynb_checkpoints/Deeplearning_Computation-checkpoint.ipynb deleted file mode 100644 index 46397d6..0000000 --- a/Deeplearning_with_Pytorch/.ipynb_checkpoints/Deeplearning_Computation-checkpoint.ipynb +++ /dev/null @@ -1,838 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Deeplearning computation\n", - "### 1. Layers and Blocks" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([[ 0.0242, -0.1950, -0.1941, 0.0628, -0.0397, -0.0054, 0.2011, 0.1221,\n", - " -0.0935, -0.2975],\n", - " [ 0.0496, -0.2916, -0.0864, -0.0426, -0.0730, -0.0218, 0.2579, 0.0508,\n", - " -0.1628, -0.2782]], grad_fn=)" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import torch\n", - "from torch import nn\n", - "from torch.nn import functional as F\n", - "\n", - "net = nn.Sequential(nn.Linear(20, 256), nn.ReLU(), nn.Linear(256, 10))\n", - "\n", - "X = torch.rand(2, 20)\n", - "net(X)" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "class MLP(nn.Module):\n", - " def __init__(self):\n", - " # Call the constructor of the `MLP` parent class `Module` to perform the necessary initialization.\n", - " # other function arguments can also be specified during class instantiation, such as the model parameters\n", - " super().__init__()\n", - " self.hidden = nn.Linear(20, 256) \n", - " self.out = nn.Linear(256, 10) \n", - "\n", - " # Define the forward propagation\n", - " # required model output based on the input `X`\n", - " def forward(self, X):\n", - " return self.out(F.relu(self.hidden(X)))" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([[ 0.0699, 0.1001, 0.2061, 0.3083, 0.1851, -0.1136, -0.0931, -0.0112,\n", - " 0.1837, 0.2294],\n", - " [ 0.0458, 0.1339, 0.0996, 0.3237, 0.1989, -0.1045, -0.0070, 0.0321,\n", - " 0.1740, 0.1794]], grad_fn=)" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "net = MLP()\n", - "net(X)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "class MySequential(nn.Module):\n", - " def __init__(self, *args):\n", - " super().__init__()\n", - " for idx, module in enumerate(args):\n", - " # Here, `module` is an instance of a `Module` subclass. We save it\n", - " # in the member variable `_modules` of the `Module` class, and its\n", - " # type is OrderedDict\n", - " self._modules[str(idx)] = module\n", - "\n", - " def forward(self, X):\n", - " # OrderedDict guarantees that members will be traversed in the order\n", - " # they were added\n", - " for block in self._modules.values():\n", - " X = block(X)\n", - " return X" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([[-0.0629, 0.0844, -0.2088, -0.2166, 0.1139, 0.1790, -0.1627, 0.2149,\n", - " -0.0859, -0.0054],\n", - " [-0.0653, 0.0852, -0.1416, -0.0915, 0.1601, 0.2436, -0.2000, 0.2560,\n", - " -0.0263, -0.0032]], grad_fn=)" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "net = MySequential(nn.Linear(20, 256), nn.ReLU(), nn.Linear(256, 10))\n", - "net(X)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 2. Parameter Management" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([[0.1365],\n", - " [0.1754]], grad_fn=)" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import torch\n", - "from torch import nn\n", - "\n", - "net = nn.Sequential(nn.Linear(4, 8), nn.ReLU(), nn.Linear(8, 1))\n", - "X = torch.rand(size=(2, 4))\n", - "net(X)" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "OrderedDict([('weight', tensor([[-0.3489, 0.1564, -0.2279, -0.0319, -0.3372, -0.1410, -0.3041, -0.1298]])), ('bias', tensor([0.2592]))])\n" - ] - } - ], - "source": [ - "print(net[2].state_dict())" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([[0.3830],\n", - " [0.3830]], grad_fn=)" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def block1():\n", - " return nn.Sequential(nn.Linear(4, 8), nn.ReLU(), nn.Linear(8, 4),\n", - " nn.ReLU())\n", - "\n", - "def block2():\n", - " net = nn.Sequential()\n", - " for i in range(4):\n", - " # Nested here\n", - " net.add_module(f'block {i}', block1())\n", - " return net\n", - "\n", - "rgnet = nn.Sequential(block2(), nn.Linear(4, 1))\n", - "rgnet(X)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Sequential(\n", - " (0): Sequential(\n", - " (block 0): Sequential(\n", - " (0): Linear(in_features=4, out_features=8, bias=True)\n", - " (1): ReLU()\n", - " (2): Linear(in_features=8, out_features=4, bias=True)\n", - " (3): ReLU()\n", - " )\n", - " (block 1): Sequential(\n", - " (0): Linear(in_features=4, out_features=8, bias=True)\n", - " (1): ReLU()\n", - " (2): Linear(in_features=8, out_features=4, bias=True)\n", - " (3): ReLU()\n", - " )\n", - " (block 2): Sequential(\n", - " (0): Linear(in_features=4, out_features=8, bias=True)\n", - " (1): ReLU()\n", - " (2): Linear(in_features=8, out_features=4, bias=True)\n", - " (3): ReLU()\n", - " )\n", - " (block 3): Sequential(\n", - " (0): Linear(in_features=4, out_features=8, bias=True)\n", - " (1): ReLU()\n", - " (2): Linear(in_features=8, out_features=4, bias=True)\n", - " (3): ReLU()\n", - " )\n", - " )\n", - " (1): Linear(in_features=4, out_features=1, bias=True)\n", - ")\n" - ] - } - ], - "source": [ - "print(rgnet)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([ 0.1514, 0.4772, -0.3789, -0.1574, -0.2709, 0.1434, 0.2604, 0.1770])" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "rgnet[0][1][0].bias.data" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(tensor([-0.0056, -0.0058, 0.0093, 0.0013]), tensor(0.))" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def init_normal(m):\n", - " if type(m) == nn.Linear:\n", - " nn.init.normal_(m.weight, mean=0, std=0.01)\n", - " nn.init.zeros_(m.bias)\n", - "\n", - "net.apply(init_normal)\n", - "net[0].weight.data[0], net[0].bias.data[0]" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Init weight torch.Size([8, 4])\n", - "Init weight torch.Size([1, 8])\n" - ] - }, - { - "data": { - "text/plain": [ - "tensor([[-0.0000, -0.0000, -6.6474, 8.8518],\n", - " [ 7.7771, -6.5521, 6.6729, -0.0000]], grad_fn=)" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def my_init(m):\n", - " if type(m) == nn.Linear:\n", - " print(\n", - " \"Init\",\n", - " *[(name, param.shape) for name, param in m.named_parameters()][0])\n", - " nn.init.uniform_(m.weight, -10, 10)\n", - " m.weight.data *= m.weight.data.abs() >= 5\n", - "\n", - "net.apply(my_init)\n", - "net[0].weight[:2]" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "tensor([True, True, True, True, True, True, True, True])\n", - "tensor([True, True, True, True, True, True, True, True])\n" - ] - } - ], - "source": [ - "# We need to give the shared layer a name so that we can refer to its parameters\n", - "shared = nn.Linear(8, 8)\n", - "net = nn.Sequential(nn.Linear(4, 8), nn.ReLU(), shared, nn.ReLU(), shared, nn.ReLU(), nn.Linear(8, 1))\n", - "net(X)\n", - "\n", - "# Check whether the parameters are the same\n", - "print(net[2].weight.data[0] == net[4].weight.data[0])\n", - "net[2].weight.data[0, 0] = 100\n", - "\n", - "# Make sure that they are actually the same object rather than just having thesame value\n", - "print(net[2].weight.data[0] == net[4].weight.data[0])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 3. Deferred Initialization" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [], - "source": [ - "import tensorflow as tf\n", - "\n", - "net = tf.keras.models.Sequential([\n", - " tf.keras.layers.Dense(256, activation=tf.nn.relu),\n", - " tf.keras.layers.Dense(10),])" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[[], []]" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "[net.layers[i].get_weights() for i in range(len(net.layers))]" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[(20, 256), (256,), (256, 10), (10,)]" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "X = tf.random.uniform((2, 20))\n", - "net(X)\n", - "[w.shape for w in net.get_weights()]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 4. Custom layers" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [], - "source": [ - "import torch\n", - "from torch import nn\n", - "from torch.nn import functional as F\n", - "\n", - "class CenteredLayer(nn.Module):\n", - " def __init__(self):\n", - " super().__init__()\n", - "\n", - " def forward(self, X):\n", - " return X - X.mean()" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([-2., -1., 0., 1., 2.])" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "layer = CenteredLayer()\n", - "layer(torch.FloatTensor([1, 2, 3, 4, 5]))" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [], - "source": [ - "net = nn.Sequential(nn.Linear(8, 128), CenteredLayer())" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor(-1.1176e-08, grad_fn=)" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "Y = net(torch.rand(4, 8))\n", - "Y.mean()" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [], - "source": [ - "class MyLinear(nn.Module):\n", - " def __init__(self, in_units, units):\n", - " super().__init__()\n", - " self.weight = nn.Parameter(torch.randn(in_units, units))\n", - " self.bias = nn.Parameter(torch.randn(units,))\n", - "\n", - " def forward(self, X):\n", - " linear = torch.matmul(X, self.weight.data) + self.bias.data\n", - " return F.relu(linear)" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Parameter containing:\n", - "tensor([[-0.5551, -1.0702, 1.0787],\n", - " [ 0.4654, -0.2897, 0.4270],\n", - " [ 1.2058, -0.2476, 0.0780],\n", - " [ 0.2457, 1.3174, -0.6553],\n", - " [ 0.7457, 0.6414, 0.4263]], requires_grad=True)" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dense = MyLinear(5, 3)\n", - "dense.weight" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([[2.7336, 2.0793, 0.5800],\n", - " [1.5111, 0.4548, 1.3087]])" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dense(torch.rand(2, 5))" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([[0.],\n", - " [0.]])" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "net = nn.Sequential(MyLinear(64, 8), MyLinear(8, 1))\n", - "net(torch.rand(2, 64))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 5. File I/O" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": {}, - "outputs": [], - "source": [ - "import torch\n", - "from torch import nn\n", - "from torch.nn import functional as F\n", - "\n", - "x = torch.arange(4)\n", - "torch.save(x, 'x-file')" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([0, 1, 2, 3])" - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x2 = torch.load(\"x-file\")\n", - "x2" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(tensor([0, 1, 2, 3]), tensor([0., 0., 0., 0.]))" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "y = torch.zeros(4)\n", - "torch.save([x, y], 'x-files')\n", - "x2, y2 = torch.load('x-files')\n", - "(x2, y2)" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'x': tensor([0, 1, 2, 3]), 'y': tensor([0., 0., 0., 0.])}" - ] - }, - "execution_count": 29, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mydict = {'x': x, 'y': y}\n", - "torch.save(mydict, 'mydict')\n", - "mydict2 = torch.load('mydict')\n", - "mydict2" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [], - "source": [ - "class MLP(nn.Module):\n", - " def __init__(self):\n", - " super().__init__()\n", - " self.hidden = nn.Linear(20, 256)\n", - " self.output = nn.Linear(256, 10)\n", - "\n", - " def forward(self, x):\n", - " return self.output(F.relu(self.hidden(x)))\n", - "\n", - "net = MLP()\n", - "X = torch.randn(size=(2, 20))\n", - "Y = net(X)" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [], - "source": [ - "torch.save(net.state_dict(), 'mlp.params')" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "MLP(\n", - " (hidden): Linear(in_features=20, out_features=256, bias=True)\n", - " (output): Linear(in_features=256, out_features=10, bias=True)\n", - ")" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "clone = MLP()\n", - "clone.load_state_dict(torch.load(\"mlp.params\"))\n", - "clone.eval()" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tensor([[True, True, True, True, True, True, True, True, True, True],\n", - " [True, True, True, True, True, True, True, True, True, True]])" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "Y_clone = clone(X)\n", - "Y_clone == Y" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 6. GPU" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Sat May 29 20:55:15 2021 \n", - "+-----------------------------------------------------------------------------+\n", - "| NVIDIA-SMI 457.30 Driver Version: 457.30 CUDA Version: 11.1 |\n", - "|-------------------------------+----------------------+----------------------+\n", - "| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |\n", - "| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n", - "| | | MIG M. |\n", - "|===============================+======================+======================|\n", - "| 0 GeForce GTX 1660 WDDM | 00000000:01:00.0 On | N/A |\n", - "| 60% 57C P0 56W / 130W | 3794MiB / 6144MiB | 42% Default |\n", - "| | | N/A |\n", - "+-------------------------------+----------------------+----------------------+\n", - " \n", - "+-----------------------------------------------------------------------------+\n", - "| Processes: |\n", - "| GPU GI CI PID Type Process name GPU Memory |\n", - "| ID ID Usage |\n", - "|=============================================================================|\n", - "| 0 N/A N/A 1544 C+G ...in7x64\\steamwebhelper.exe N/A |\n", - "| 0 N/A N/A 1948 C+G ...cw5n1h2txyewy\\LockApp.exe N/A |\n", - "| 0 N/A N/A 3792 C+G ...artMenuExperienceHost.exe N/A |\n", - "| 0 N/A N/A 6556 C+G ...5n1h2txyewy\\SearchApp.exe N/A |\n", - "| 0 N/A N/A 7824 C+G Insufficient Permissions N/A |\n", - "| 0 N/A N/A 9456 C+G ...wekyb3d8bbwe\\Video.UI.exe N/A |\n", - "| 0 N/A N/A 9556 C+G ...y\\ShellExperienceHost.exe N/A |\n", - "| 0 N/A N/A 10116 C+G ...ekyb3d8bbwe\\YourPhone.exe N/A |\n", - "| 0 N/A N/A 13712 C+G ...nputApp\\TextInputHost.exe N/A |\n", - "| 0 N/A N/A 21312 C+G ...ommon\\Rust\\RustClient.exe N/A |\n", - "| 0 N/A N/A 22280 C+G ...\\app-1.0.9002\\Discord.exe N/A |\n", - "| 0 N/A N/A 23280 C+G C:\\Windows\\explorer.exe N/A |\n", - "| 0 N/A N/A 23456 C+G ...oot\\Office16\\POWERPNT.EXE N/A |\n", - "| 0 N/A N/A 25128 C+G ...me\\Application\\chrome.exe N/A |\n", - "+-----------------------------------------------------------------------------+\n" - ] - } - ], - "source": [ - "!nvidia-smi" - ] - } - ], - "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.8.5" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/Deeplearning_with_Pytorch/.ipynb_checkpoints/Softmax_Regression-checkpoint.ipynb b/Deeplearning_with_Pytorch/.ipynb_checkpoints/Softmax_Regression-checkpoint.ipynb deleted file mode 100644 index 7fec515..0000000 --- a/Deeplearning_with_Pytorch/.ipynb_checkpoints/Softmax_Regression-checkpoint.ipynb +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cells": [], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 4 -} From 761e6ba070ca6cbdb504311813b2bb3259655fd0 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Sat, 29 May 2021 21:28:39 +0900 Subject: [PATCH 54/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 454e39d..b0188b4 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ ## Pytorch Deeplearning | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Deeplearning_with_Pytorch) - Differentiation, Probability, Neural Networks - +- Layers and Blocks, Parameter Management, Custom layers, File I/O, GPU ## Reference ``` From 7a0eee3b5f2138a0695222c24c7c5136bb37e1d9 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Tue, 1 Jun 2021 12:58:42 +0900 Subject: [PATCH 55/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b0188b4..98ba071 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,6 @@ ## Reference ``` -[1] 김상형,『파이썬 정복』, 한빛미디어(2018) +[1] 김상형,『파이썬 정복』, 한빛미디어(2018) [2] Dive into Deep Learning, http://d2l.ai/ ``` From 3d68eed98263e0d7a48a57716fbbe1458451bd4b Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Tue, 29 Jun 2021 22:07:57 +0900 Subject: [PATCH 56/60] Update README.md --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 98ba071..3a228d6 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,27 @@ -# Python Toolbox (20200728 ~) +# Python Toolbox - My personal toolbox that contains my daily python tools for datascience and machinelearning +- Jul. 28, 2020 ## Python Basic -### 1. Basic Structure | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/1_Basic_Structure.ipynb) +### 1. Basic Structure | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/1_Basic_Structure.ipynb) |No.|Contents|No.|Contents|No.|Contents|No.|Contents| |------|---|---|---|---|---|---|---| |1|Print|2|Variable|3|Function|4|Method| |5|Formatting|6|List and Tuple|7|Dictionary|8|Set| |9|Collection|10|Lambda Function|11|Copy|12|| -### 2.Standard Modules | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/2_Standard_Modules.ipynb) +### 2.Standard Modules | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/2_Standard_Modules.ipynb) |No.|Contents|No.|Contents| |------|---|------|---| |1|Random|2|Time| |3|Calendar|4|Math| |5|Statistics|6|Sys| -## Module and Packages | [[Study]](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Module_and_Package/README.md) | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Module_and_Package) +## Module and Packages | [Study](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Module_and_Package/README.md) | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Module_and_Package) - Structure of python project, Pip -## Pytorch Deeplearning | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Deeplearning_with_Pytorch) +## Pytorch Deeplearning | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Deeplearning_with_Pytorch) - Differentiation, Probability, Neural Networks - Layers and Blocks, Parameter Management, Custom layers, File I/O, GPU From 4eb1f7735670817f535ccaafb2712f1ac4c0c044 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Tue, 29 Jun 2021 22:08:47 +0900 Subject: [PATCH 57/60] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a228d6..f29f615 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ |3|Calendar|4|Math| |5|Statistics|6|Sys| -## Module and Packages | [Study](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Module_and_Package/README.md) | [[Code]](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Module_and_Package) +## Module and Packages | [Study, Code](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Module_and_Package) - Structure of python project, Pip From 81a8bfb0cc6824e214caface35c263466048a316 Mon Sep 17 00:00:00 2001 From: Oh seoyoung Date: Tue, 29 Jun 2021 22:09:21 +0900 Subject: [PATCH 58/60] Update README.md --- Module_and_Package/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Module_and_Package/README.md b/Module_and_Package/README.md index ba40e7f..565899b 100644 --- a/Module_and_Package/README.md +++ b/Module_and_Package/README.md @@ -17,17 +17,17 @@ ROOT - If ```__init__.py``` exists in the directory, it is considered a package. - It uses a module called ```array```, which is being tested from a package called ```algorithms```. -### test_array.py | [[Code]]() +### test_array.py - ```from [package_name] import [module_name]``` -> Use modules from packages -### algorithms/__init__.py | [[Code]]() +### algorithms/__init__.py - When a package is referenced from outside, the ```__init__.py``` in the package is executed. - Each directory in the package must have ```__init__.py```. - ```__init__.py``` may be empty or may provide information about the modules contained in the package. -### setup.py | [[Code]]() +### setup.py - Determine the top-level directory of the project with ```setup.py``` - Contains information necessary for testing, building, and deployment of the project. -> [Using the ```setuptools``` package](https://packaging.python.org/tutorials/packaging-projects/#setup-args). From 1025de48af055f307a6cb0070c0e9ce1cf08ec84 Mon Sep 17 00:00:00 2001 From: standing-o Date: Wed, 30 Oct 2024 22:40:30 +0900 Subject: [PATCH 59/60] :memo: Update --- .gitignore | 51 ++++++++++++++++++ Deeplearning_with_Pytorch/.gitignore | 53 +++++++++++++++++++ ....ipynb => automatic_differentiation.ipynb} | 0 ...gression.ipynb => linear_regression.ipynb} | 0 Module_and_Package/.gitignore | 53 +++++++++++++++++++ Python_Advanced/.gitignore | 53 +++++++++++++++++++ Python_Basic/.gitignore | 53 +++++++++++++++++++ ..._Structure.ipynb => basic_structure.ipynb} | 0 ...d_Modules.ipynb => standard_modules.ipynb} | 0 README.md | 35 ++++++++---- 10 files changed, 289 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 Deeplearning_with_Pytorch/.gitignore rename Deeplearning_with_Pytorch/{Automatic Differentiation.ipynb => automatic_differentiation.ipynb} (100%) rename Deeplearning_with_Pytorch/{Linear Regression.ipynb => linear_regression.ipynb} (100%) create mode 100644 Module_and_Package/.gitignore create mode 100644 Python_Advanced/.gitignore create mode 100644 Python_Basic/.gitignore rename Python_Basic/{1_Basic_Structure.ipynb => basic_structure.ipynb} (100%) rename Python_Basic/{2_Standard_Modules.ipynb => standard_modules.ipynb} (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a263ce0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,51 @@ +# Ignore OS generated files +.DS_Store +Thumbs.db + +# Ignore node dependencies and logs +node_modules/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Ignore build and cache files +dist/ +build/ +.cache/ +tmp/ +*.log + +# Ignore environment variable files +.env +.env.local +.env.*.local + +# Python +__pycache__/ +*.py[cod] +*.pyo +*.pyd +*.pdb +.Python +venv/ +env/ + +# IDE and editor specific files +.vscode/ +.idea/ +*.sublime-project +*.sublime-workspace + +# Ignore Mac-specific files +*.DS_Store + +# Ignore package files +*.bak +*.orig +*.swp +*~ + +# Misc +*.temp +*.tmp +*.lock \ No newline at end of file diff --git a/Deeplearning_with_Pytorch/.gitignore b/Deeplearning_with_Pytorch/.gitignore new file mode 100644 index 0000000..391213d --- /dev/null +++ b/Deeplearning_with_Pytorch/.gitignore @@ -0,0 +1,53 @@ +# Ignore OS generated files +.DS_Store +Thumbs.db + +# Ignore node dependencies and logs +node_modules/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Ignore build and cache files +dist/ +build/ +.cache/ +tmp/ +*.log + +# Ignore environment variable files +.env +.env.local +.env.*.local + +# Python +__pycache__/ +*.py[cod] +*.pyo +*.pyd +*.pdb +.Python +venv/ +env/ + +# IDE and editor specific files +.vscode/ +.idea/ +*.sublime-project +*.sublime-workspace + +# Ignore Mac-specific files +*.DS_Store + +# Ignore package files +*.bak +*.orig +*.swp +*~ + +# Misc +*.temp +*.tmp +*.lock + +/.ipynb_checkpoints \ No newline at end of file diff --git a/Deeplearning_with_Pytorch/Automatic Differentiation.ipynb b/Deeplearning_with_Pytorch/automatic_differentiation.ipynb similarity index 100% rename from Deeplearning_with_Pytorch/Automatic Differentiation.ipynb rename to Deeplearning_with_Pytorch/automatic_differentiation.ipynb diff --git a/Deeplearning_with_Pytorch/Linear Regression.ipynb b/Deeplearning_with_Pytorch/linear_regression.ipynb similarity index 100% rename from Deeplearning_with_Pytorch/Linear Regression.ipynb rename to Deeplearning_with_Pytorch/linear_regression.ipynb diff --git a/Module_and_Package/.gitignore b/Module_and_Package/.gitignore new file mode 100644 index 0000000..391213d --- /dev/null +++ b/Module_and_Package/.gitignore @@ -0,0 +1,53 @@ +# Ignore OS generated files +.DS_Store +Thumbs.db + +# Ignore node dependencies and logs +node_modules/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Ignore build and cache files +dist/ +build/ +.cache/ +tmp/ +*.log + +# Ignore environment variable files +.env +.env.local +.env.*.local + +# Python +__pycache__/ +*.py[cod] +*.pyo +*.pyd +*.pdb +.Python +venv/ +env/ + +# IDE and editor specific files +.vscode/ +.idea/ +*.sublime-project +*.sublime-workspace + +# Ignore Mac-specific files +*.DS_Store + +# Ignore package files +*.bak +*.orig +*.swp +*~ + +# Misc +*.temp +*.tmp +*.lock + +/.ipynb_checkpoints \ No newline at end of file diff --git a/Python_Advanced/.gitignore b/Python_Advanced/.gitignore new file mode 100644 index 0000000..391213d --- /dev/null +++ b/Python_Advanced/.gitignore @@ -0,0 +1,53 @@ +# Ignore OS generated files +.DS_Store +Thumbs.db + +# Ignore node dependencies and logs +node_modules/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Ignore build and cache files +dist/ +build/ +.cache/ +tmp/ +*.log + +# Ignore environment variable files +.env +.env.local +.env.*.local + +# Python +__pycache__/ +*.py[cod] +*.pyo +*.pyd +*.pdb +.Python +venv/ +env/ + +# IDE and editor specific files +.vscode/ +.idea/ +*.sublime-project +*.sublime-workspace + +# Ignore Mac-specific files +*.DS_Store + +# Ignore package files +*.bak +*.orig +*.swp +*~ + +# Misc +*.temp +*.tmp +*.lock + +/.ipynb_checkpoints \ No newline at end of file diff --git a/Python_Basic/.gitignore b/Python_Basic/.gitignore new file mode 100644 index 0000000..391213d --- /dev/null +++ b/Python_Basic/.gitignore @@ -0,0 +1,53 @@ +# Ignore OS generated files +.DS_Store +Thumbs.db + +# Ignore node dependencies and logs +node_modules/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Ignore build and cache files +dist/ +build/ +.cache/ +tmp/ +*.log + +# Ignore environment variable files +.env +.env.local +.env.*.local + +# Python +__pycache__/ +*.py[cod] +*.pyo +*.pyd +*.pdb +.Python +venv/ +env/ + +# IDE and editor specific files +.vscode/ +.idea/ +*.sublime-project +*.sublime-workspace + +# Ignore Mac-specific files +*.DS_Store + +# Ignore package files +*.bak +*.orig +*.swp +*~ + +# Misc +*.temp +*.tmp +*.lock + +/.ipynb_checkpoints \ No newline at end of file diff --git a/Python_Basic/1_Basic_Structure.ipynb b/Python_Basic/basic_structure.ipynb similarity index 100% rename from Python_Basic/1_Basic_Structure.ipynb rename to Python_Basic/basic_structure.ipynb diff --git a/Python_Basic/2_Standard_Modules.ipynb b/Python_Basic/standard_modules.ipynb similarity index 100% rename from Python_Basic/2_Standard_Modules.ipynb rename to Python_Basic/standard_modules.ipynb diff --git a/README.md b/README.md index f29f615..5d270ca 100644 --- a/README.md +++ b/README.md @@ -2,28 +2,45 @@ - My personal toolbox that contains my daily python tools for datascience and machinelearning - Jul. 28, 2020 + +  +  +  + + +## Module and Packages | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Module_and_Package) +- Structure of python project, Pip + +  +  +  + +## Pytorch Deeplearning | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Deeplearning_with_Pytorch) +- Differentiation, Probability, Neural Networks +- Layers and Blocks, Parameter Management, Custom layers, File I/O, GPU + +  +  +  + ## Python Basic -### 1. Basic Structure | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/1_Basic_Structure.ipynb) +### 1. Basic Structure | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/basic_structure.ipynb) |No.|Contents|No.|Contents|No.|Contents|No.|Contents| |------|---|---|---|---|---|---|---| |1|Print|2|Variable|3|Function|4|Method| |5|Formatting|6|List and Tuple|7|Dictionary|8|Set| |9|Collection|10|Lambda Function|11|Copy|12|| -### 2.Standard Modules | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/2_Standard_Modules.ipynb) +### 2.Standard Modules | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/blob/master/Python_Basic/standard_modules.ipynb) |No.|Contents|No.|Contents| |------|---|------|---| |1|Random|2|Time| |3|Calendar|4|Math| |5|Statistics|6|Sys| -## Module and Packages | [Study, Code](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Module_and_Package) -- Structure of python project, Pip - - -## Pytorch Deeplearning | [Code](https://github.com/OH-Seoyoung/Python_Toolbox/tree/master/Deeplearning_with_Pytorch) -- Differentiation, Probability, Neural Networks -- Layers and Blocks, Parameter Management, Custom layers, File I/O, GPU +  +  +  ## Reference ``` From f1de67156d64b58353695537d678f7cb49b4e519 Mon Sep 17 00:00:00 2001 From: standing-o Date: Wed, 30 Oct 2024 22:41:31 +0900 Subject: [PATCH 60/60] :memo: Add Scope --- Python_Advanced/scope.ipynb | 289 ++++++++++++++++++++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 Python_Advanced/scope.ipynb diff --git a/Python_Advanced/scope.ipynb b/Python_Advanced/scope.ipynb new file mode 100644 index 0000000..13851fb --- /dev/null +++ b/Python_Advanced/scope.ipynb @@ -0,0 +1,289 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "3f944790", + "metadata": {}, + "source": [ + "# Scope\n", + "### 1. Local Variable & Global Variable\n", + "- **`Global variables`** are primarily used for constants or **fixed values** that do not change. \n", + " - Modifying global variables within local scopes is generally discouraged.\n", + "- **`Local variables`** are limited to resolving logic within functions, with a lifecycle that ends when the function completes execution. " + ] + }, + { + "cell_type": "markdown", + "id": "9f1cdd36", + "metadata": {}, + "source": [ + "```\n", + "UnboundLocalError: local variable 'c' referenced before assignment\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "c9806b50", + "metadata": {}, + "outputs": [], + "source": [ + "c = 40\n", + "\n", + "def foobar():\n", + " c = c + 10\n", + " print(c)\n", + " \n", + "foobar() " + ] + }, + { + "cell_type": "markdown", + "id": "91c0c2eb", + "metadata": {}, + "source": [ + "- Avoid using global variables. However, it works." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "e24de27f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "50\n" + ] + } + ], + "source": [ + "d = 40\n", + "\n", + "def barfoo():\n", + " global d\n", + " \n", + " d = d + 10\n", + " print(d)\n", + " \n", + "barfoo() " + ] + }, + { + "cell_type": "markdown", + "id": "66a4cc0e", + "metadata": {}, + "source": [ + "```\n", + "local variable 'e' referenced before assignment\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "ed161cbd", + "metadata": {}, + "outputs": [], + "source": [ + "def outer():\n", + " e = 70\n", + " def inner():\n", + " e += 10\n", + " print(e)\n", + " return inner\n", + "\n", + "func = outer()\n", + "func()" + ] + }, + { + "cell_type": "markdown", + "id": "dcc1ea9d", + "metadata": {}, + "source": [ + "- nonlocal" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "139426c5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n" + ] + } + ], + "source": [ + "def outer_():\n", + " f = 70\n", + " def inner_():\n", + " nonlocal f\n", + " f += 10\n", + " print(f)\n", + " return inner_\n", + "\n", + "func_= outer_()\n", + "func_()" + ] + }, + { + "cell_type": "markdown", + "id": "13eac792", + "metadata": {}, + "source": [ + "- Increases in value with each call." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "35480457", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "90\n", + "100\n", + "110\n" + ] + } + ], + "source": [ + "func_()\n", + "func_()\n", + "func_()" + ] + }, + { + "cell_type": "markdown", + "id": "89844b37", + "metadata": {}, + "source": [ + "- Print local variables and functions as a dictionary.\n", + " - Useful for debugging" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "99c44622", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'var': 'Hi', 'x': 10, 'printer': .printer at 0x00000222513759D0>}\n" + ] + } + ], + "source": [ + "def func(var):\n", + " x = 10\n", + " def printer():\n", + " print(\"Printer Function\")\n", + " print(locals())\n", + " \n", + "func(\"Hi\")" + ] + }, + { + "cell_type": "markdown", + "id": "1c4e2c3a", + "metadata": {}, + "source": [ + "- Print all of the global variables and functions as a dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "50eb1a93", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'__name__': '__main__', '__doc__': 'Automatically created module for IPython interactive environment', '__package__': None, '__loader__': None, '__spec__': None, '__builtin__': , '__builtins__': , '_ih': ['', 'd = 40\\n\\ndef barfoo():\\n global d\\n \\n d = d + 10\\n print(d)\\n \\nbarfoo() ', 'def outer_():\\n f = 70\\n def inner_():\\n nonlocal f\\n f += 10\\n print(f)\\n return inner_\\n\\nfunc_= outer_()\\nfunc_()', 'func_()\\nfunc_()\\nfunc_()', 'def func(var):\\n x = 10\\n def printer():\\n print(\"Printer Function\")\\n print(locals())\\n \\nfunc(\"Hi\")', 'print(globals())'], '_oh': {}, '_dh': [WindowsPath('C:/Users/osy/Desktop/Github/Python_Toolbox/Variable_Scope')], 'In': ['', 'd = 40\\n\\ndef barfoo():\\n global d\\n \\n d = d + 10\\n print(d)\\n \\nbarfoo() ', 'def outer_():\\n f = 70\\n def inner_():\\n nonlocal f\\n f += 10\\n print(f)\\n return inner_\\n\\nfunc_= outer_()\\nfunc_()', 'func_()\\nfunc_()\\nfunc_()', 'def func(var):\\n x = 10\\n def printer():\\n print(\"Printer Function\")\\n print(locals())\\n \\nfunc(\"Hi\")', 'print(globals())'], 'Out': {}, 'get_ipython': >, 'exit': , 'quit': , 'open': , '_': '', '__': '', '___': '', '_i': 'def func(var):\\n x = 10\\n def printer():\\n print(\"Printer Function\")\\n print(locals())\\n \\nfunc(\"Hi\")', '_ii': 'func_()\\nfunc_()\\nfunc_()', '_iii': 'def outer_():\\n f = 70\\n def inner_():\\n nonlocal f\\n f += 10\\n print(f)\\n return inner_\\n\\nfunc_= outer_()\\nfunc_()', '_i1': 'd = 40\\n\\ndef barfoo():\\n global d\\n \\n d = d + 10\\n print(d)\\n \\nbarfoo() ', 'd': 50, 'barfoo': , '_i2': 'def outer_():\\n f = 70\\n def inner_():\\n nonlocal f\\n f += 10\\n print(f)\\n return inner_\\n\\nfunc_= outer_()\\nfunc_()', 'outer_': , 'func_': .inner_ at 0x0000022251375EE0>, '_i3': 'func_()\\nfunc_()\\nfunc_()', '_i4': 'def func(var):\\n x = 10\\n def printer():\\n print(\"Printer Function\")\\n print(locals())\\n \\nfunc(\"Hi\")', 'func': , '_i5': 'print(globals())'}\n" + ] + } + ], + "source": [ + "print(globals())" + ] + }, + { + "cell_type": "markdown", + "id": "b5eefbf3", + "metadata": {}, + "source": [ + "```\n", + "test_variable = 10\n", + "<-> globals()['test_variable'] = 100\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "ef8bd3cf", + "metadata": {}, + "source": [ + "- We can create global variables dynamically." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "2c812d96", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], + "source": [ + "for i in range(10):\n", + " globals()['Test_{}'.format(i)] = i\n", + " \n", + "print(Test_1)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "dacon", + "language": "python", + "name": "dacon" + }, + "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.8.17" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}