Browse Source

Small improvements of perceptron and bp

pull/1/MERGE
Shuhui Bu 6 years ago
parent
commit
e81fc14b00
3 changed files with 2043 additions and 2009 deletions
  1. +17
    -2
      1_nn/Perceptron.ipynb
  2. +1
    -0
      1_nn/Perceptron.py
  3. +2025
    -2007
      1_nn/mlp_bp.ipynb

+ 17
- 2
1_nn/Perceptron.ipynb View File

@@ -141,11 +141,25 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": { "metadata": {
"lines_to_end_of_cell_marker": 2 "lines_to_end_of_cell_marker": 2
}, },
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"update weight and bias: 1.0 3.0 0.5\n",
"update weight and bias: -0.5 2.5 0.0\n",
"update weight and bias: -2.5 2.0 -0.5\n",
"w = [-2.5, 2.0]\n",
"b = -0.5\n",
"[ 1 1 1 1 -1 -1 -1 -1]\n",
"[1, 1, 1, 1, -1, -1, -1, -1]\n"
]
}
],
"source": [ "source": [
"import random\n", "import random\n",
"import numpy as np\n", "import numpy as np\n",
@@ -163,6 +177,7 @@
" train_num = n_iter # 迭代次数\n", " train_num = n_iter # 迭代次数\n",
"\n", "\n",
" for i in range(train_num):\n", " for i in range(train_num):\n",
" #FIXME: the random chose sample is to slow\n",
" train = random.choice(train_data)\n", " train = random.choice(train_data)\n",
" x1, x2, y = train\n", " x1, x2, y = train\n",
" predict = sign(weight[0] * x1 + weight[1] * x2 + bias) # 输出\n", " predict = sign(weight[0] * x1 + weight[1] * x2 + bias) # 输出\n",


+ 1
- 0
1_nn/Perceptron.py View File

@@ -154,6 +154,7 @@ def perceptron_train(train_data, eta=0.5, n_iter=100):
train_num = n_iter # 迭代次数 train_num = n_iter # 迭代次数


for i in range(train_num): for i in range(train_num):
#FIXME: the random chose sample is to slow
train = random.choice(train_data) train = random.choice(train_data)
x1, x2, y = train x1, x2, y = train
predict = sign(weight[0] * x1 + weight[1] * x2 + bias) # 输出 predict = sign(weight[0] * x1 + weight[1] * x2 + bias) # 输出


+ 2025
- 2007
1_nn/mlp_bp.ipynb
File diff suppressed because it is too large
View File


Loading…
Cancel
Save