gitHub代码链接:https://github.com/justDoForever/deep_learning(python2.7)
具体理论详尽分析请转到我另一篇博客:零基础入门深度学习(6) - 原生实现长短时记忆网络(LSTM)
python原生实现一个感知器(实现and运算),将输入标签替换成or真值表对应结果,
def getTrainDataset():
#and 真值表
inputs = [[0,0],[0,1],[1,0],[1,1]];
#and
labels = [0,0,0,1];
#or
# labels = [0,1,1,1];
return inputs,labels;
则该感知器变为实现or运算。
具体代码如下:
# coding:utf-8
class Perception(object):
def __init__(self,input_num,activator):
self.weights = [0.0 for _ in range(input_num)];
self.activator = activator;
self.bias = 0.0;
def train(self, inputs, labels,n, learning_rate):
#训练样本,不断使预测值与标签值相接近并得到此时的每个