Browse Source

Improve some description

pull/5/head
bushuhui 3 years ago
parent
commit
177f7428e5
4 changed files with 4179 additions and 4702 deletions
  1. +10
    -8
      5_nn/1-Perceptron.ipynb
  2. +4080
    -4616
      5_nn/2-mlp_bp.ipynb
  3. +1
    -1
      5_nn/3-softmax_ce.ipynb
  4. +88
    -77
      6_pytorch/0_basic/1-Tensor-and-Variable.ipynb

+ 10
- 8
5_nn/1-Perceptron.ipynb View File

@@ -70,7 +70,7 @@
"\n",
"这样,假设超平面S的总的误分类点集合为M,那么所有误分类点到S的距离之和为\n",
"$$\n",
"-\\frac{1}{||w||} \\sum_{x_i \\in M} y_i (w \\cdot x_i + b)\n",
"-\\frac{1}{||w||} \\sum_{x_i \\in M} |w \\cdot x_i + b|\n",
"$$\n",
"不考虑1/||w||,就得到了感知机学习的损失函数。\n",
"\n",
@@ -156,10 +156,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
"update weight and bias: 1.0 3.0 0.5\n",
"update weight and bias: -2.5 1.5 0.0\n",
"w = [-2.5, 1.5]\n",
"b = 0.0\n",
"update weight and bias: 0.5 1.5 0.5\n",
"update weight and bias: -3.0 0.0 0.0\n",
"update weight and bias: -2.0 3.0 0.5\n",
"w = [-2.0, 3.0]\n",
"b = 0.5\n",
"ground_truth: [1, 1, 1, 1, -1, -1, -1, -1]\n",
"predicted: [1, 1, 1, 1, -1, -1, -1, -1]\n"
]
@@ -175,16 +176,17 @@
" else: return -1\n",
" \n",
"def perceptron_train(train_data, eta=0.5, n_iter=100):\n",
" weight = [0, 0] # 权重\n",
" bias = 0 # 偏置量\n",
" weight = [0, 0] # 权重\n",
" bias = 0 # 偏置量\n",
" learning_rate = eta # 学习速率\n",
"\n",
" train_num = n_iter # 迭代次数\n",
"\n",
" for i in range(train_num):\n",
" #FIXME: the random chose sample is to slow\n",
" # need improve to cover all samples\n",
" train = random.choice(train_data)\n",
" x1, x2, y = train\n",
" \n",
" predict = sign(weight[0] * x1 + weight[1] * x2 + bias) # 输出\n",
" #print(\"train data: x: (%2d, %2d) y: %2d ==> predict: %2d\" % (x1, x2, y, predict))\n",
" \n",


+ 4080
- 4616
5_nn/2-mlp_bp.ipynb
File diff suppressed because it is too large
View File


+ 1
- 1
5_nn/3-softmax_ce.ipynb View File

@@ -268,7 +268,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.8.5"
}
},
"nbformat": 4,


+ 88
- 77
6_pytorch/0_basic/1-Tensor-and-Variable.ipynb
File diff suppressed because it is too large
View File


Loading…
Cancel
Save