You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

260 lines
5.1 KiB
Plaintext

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{
"cells": [
{
"cell_type": "markdown",
"id": "f4893f14",
"metadata": {},
"source": [
"## 1.神经元"
]
},
{
"cell_type": "markdown",
"id": "94bf19cc",
"metadata": {},
"source": [
"<div>\n",
"<img src='nn1.jpg' width=45% align=left>\n",
"<img src='nn2.jpg' width=45% align=right>\n",
"</div>"
]
},
{
"cell_type": "markdown",
"id": "2be5b67b",
"metadata": {},
"source": [
"## 2.数学模型"
]
},
{
"cell_type": "markdown",
"id": "8033dba5",
"metadata": {},
"source": [
"<img src='math_nn.png' width=50% align=center>"
]
},
{
"cell_type": "markdown",
"id": "65adb74a",
"metadata": {},
"source": [
"## 3.Python代码"
]
},
{
"cell_type": "markdown",
"id": "a5a9e122",
"metadata": {},
"source": [
"### 3.1 一个数据,三个特征,一个神经元"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "a59d2aed",
"metadata": {},
"outputs": [],
"source": [
"X = [1, 2, 3] #数据3\n",
"weight = [2, -1, 1] #权重\n",
"bias = 2#偏置"
]
},
{
"cell_type": "markdown",
"id": "72b0c310",
"metadata": {},
"source": [
"$$output = X[0] \\times weight[0] + X[1] \\times weight[1] + X[2] \\times weight[2] + bias$$"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "52612463",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"output = 0 \n",
"for x, w in zip(X, weight):\n",
" output += x * w\n",
"output += bias\n",
"output"
]
},
{
"cell_type": "markdown",
"id": "e7047e45",
"metadata": {},
"source": [
"### 3.2 一个数据,三个特征,二个神经元"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "276a5d16",
"metadata": {},
"outputs": [],
"source": [
"X = [1, 2, 3] #数据3\n",
"weight = [[2, -1, 1],\n",
" [2, 3, 1]] #权重\n",
"bias = [2, 3]#偏置"
]
},
{
"cell_type": "markdown",
"id": "88130792",
"metadata": {},
"source": [
"$$outputs[0] = X[0] \\times weight[0][0] + X[1] \\times weight[0][1] + X[2] \\times weight[0][2] + bias[0]$$\n",
"$$outputs[1] = X[0] \\times weight[1][0] + X[1] \\times weight[1][1] + X[2] \\times weight[1][2] + bias[1]$$"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "171cf7ed",
"metadata": {},
"outputs": [],
"source": [
"outputs = []\n",
"for n in range(len(weight)):\n",
" output = 0\n",
" for x, w in zip(X, weight[n]):\n",
" output += x * w#输入特征*权重\n",
" output += bias[n]#加上偏置\n",
" outputs.append(output)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "2b29da7e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[5, 14]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"outputs"
]
},
{
"cell_type": "markdown",
"id": "c5d44a2e",
"metadata": {},
"source": [
"### 3.3 三个数据,三个特征,二个神经元"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "e789cbb0",
"metadata": {},
"outputs": [],
"source": [
"X = [[1, 2, 3],\n",
" [2, 3, 4],\n",
" [4, 5, 6]] #数据3 3\n",
"weight = [[2, -1, 1],\n",
" [2, 3, 1]] #权重\n",
"bias = [2, 3]#偏置"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ec7c1216",
"metadata": {},
"outputs": [],
"source": [
"n_outputs = []\n",
"for i in range(len(X)):\n",
" outputs = []\n",
" for n in range(len(weight)):\n",
" output = 0\n",
" for x, w in zip(X[i], weight[n]):\n",
" output += x * w#输入特征*权重\n",
" output += bias[n]#加上偏置\n",
" outputs.append(output)\n",
" n_outputs.append(outputs)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "47bdc39b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[5, 14], [7, 20], [11, 32]]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"n_outputs"
]
},
{
"cell_type": "markdown",
"id": "08742560",
"metadata": {},
"source": [
"作业请写出n_outputsXweight的计算"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}