书名
chapter 1 Use Python
1.准备:
Matplotlib Python3 Numpy
新建anaconda环境后,启动,检查环境:
2. 基本函数:
#建立anaconda虚拟环境 命名python341 python版本3.4.1
conda create --name python341 python=3.4.1
#命令串口启动虚拟环境
activate python341
#查看python版本
python --version
#启动python
python
#Mathematical operations 运算:加+ 减- 乘* 除/ 幂**
#Datatypes 类型:查看type()
#Variables 变量:答应print()
#Lists 列表:序号从 0 开始
x = [1, 2, 3, 4, 5]
print(x) # -> [1, 2, 3, 4, 5]
len(x) # -> 5
x[0:2] # -> [1, 2] 0号开始,数2个
x[1:] # -> [2, 3, 4, 5] 1号开始,到最后
x[:3] # -> 0号开始,数3个
x[:-1] # -> 0号开始,到倒数第2个
x[:-2] # -> 0号开始,到倒数第3个
#Dictionaries 字典:key-value
a = {'weight' = 65}#创建
a['height'] = 190 #加入新的元素
print(a) # -> {'weight': 65, 'height': 190}
#Boolean 布尔:True False
a = True
b = False
not a # -> False 非运算
a and b # -> False 与运算
a or b # -> True 或运算
#If statements:if True: ,else:
#For statements:for ... in ... :
#Functions:def name (values):
#save 保存:在cmd中运行python文件,必须先要设置python的环境变量,之后
F:#打开F盘
cd F:\研0\nerual\Neural-Network-for-Beginners-main\Chapter 01 #move to the directory
python HelloWorld.py
#Classes 类:
class name:
def __init__(self, argument, ...):
def method name 1(self, argument, ...):
3.Numpy 基本函数
#Numpy
import numpy as np
#创建array排列
a = np.array([5.0, 15.0, 10.0])
print(a) # -> [5. 15. 10.]
type(a) # -> 格式<class 'numpy.ndarray'>
#Mathematical operations in Numpy:+ - * /(排列对应对应元素运算)
多维排列:
#N-dimensional多维
x = np.array([[5, 6], [7, 8]])
print(x)
# -> [[5 6]
# [7 8]]
x.shape # -> 大小 (2, 2)
d.dtype # -> 格式dtype('int32')
Broadcasting:
#Broadcasting 广播:扩展元素至同大小 用于numpy构建神经网络
x = np.array([[1, 2], [3, 4]])
y = np.array([10, 20])
x * y
# -> array([[10,40],
# [30, 80]])
broadcasting
访问排列元素:
#Accessing elements访问元素:序号从0号开始
A = np.array([[21, 25],[54, 59], [0, 4]])
A[0] # -> array([21, 25]) 0号行
A[0][1] # -> 25 (0,1)元素
for i in A:
print(i) # -> [21 25](/n)[54 59](/n)[0 4]
A = A.flatten() # -> [21 25 54 59 0 4] 展平
A[np.array([0, 2, 4])] # -> array([21, 54, 0]) 取0号、2号、4号构成新array
A > 15 # -> array([True, True, True, True, False, False]) 判断array为bool型
A[A>15] # -> array([21, 25, 54, 59]) 取满足条件的元素构建新的array
4.Matplotlib 基本函数
draw a simple:
#Matplotlib
#draw a simple
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 8, 0.2) # 排列:从0到8,间隔0.2
y = np.sin(x)
plt.plot(x, y, linestyle="-")
plt.show()
Feature of pyplot:
#Matplotlib
#Feature of pyplot
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 8, 0.2) # 排列:从0到8,间隔0.2
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x, y1, label="sin")
plt.plot(x, y2, linestyle="-", label="cos")
plt.xlabel("x") #横坐标
plt.ylabel("y") #纵坐标
plt.title('sin & cos') #标题
plt.legend() #图例
plt.show()
Displaying images:# ! imshow()在matplotlib.pyplot,imread()在matplotlib.image
# ! imread完, 再imshow()
#Matplotlib
#Displaying images
#!!! imshow()在matplotlib.pyplot,imread()在matplotlib.image
#!imread完, 再imshow()
#../返回上层文件夹找, ./同层文件夹中找
import matplotlib.pyplot as plt
from matplotlib.image import imread
img = imread('./dataset/demo.png')
plt.imshow(img)
plt.show()
chapter 2 perception感知器
这章内容是介绍感知器机制
1.definition of perceptron
基本结构:输入x,输出y,权重w,圆圈:神经元或者节点 和 方程组方程组
2.simple logic circuts
(1)AND gates:
需要通过调整参数做出的感知器,可以实现逻辑门的功能,会有加权值超出阈值的问题
模型和真值表:
(2)NAND and OR gates:
当感知器参数被正确修改时,就会变为逻辑门:与门、与非门和或门
模型和真值表:
3.weights and bias introduction
(1)implementation with weights and bias
与门、与非门、或门
(2)limitations of perceptron:
AND、NAND、OR gate可以用感知器实现
(3)XOR gate:
是一个门系统,当输入都为1时输出为1,具有排他性;方程组是一条直线,将区域分为两个部分
注:(0,0)是一个圆,(0,1)(1,0)(1,1)是三角,直线没办法分开OR的结果
4.Linear and nonlinear
5.multilayer perceptron
(1)combination of gates
可以这样说,XOR门,是由几个逻辑门组合而成的
(2)XOR gate implementation
! 不再是单层感知器,有了层次,结构可以引申为:
6.a computer from NAND
多层感知器允许非线性表示,并且可以描述计算机原则上的工作
7.conclusion
具有输入和输出的算法是一个感知器。 如果收到特定输入,则生成固定值;
感知器包含“重量”和“偏差”的参数;
感知可用于描述AND和OR门等逻辑电路;
单层感知器不能在XOR门上表示;
XOR门可以使用双层感知器显示;
单层感知器只能表示线性区域,而多层感知器是非线性的;
多层可以描绘计算机(理论上)