# encoding:utf-8
import numpy as np
import math
import random
def rand(a, b):
return (b-a)*random.random() + a
def make_matrix(m, n, fill=0.0):
mat = []
for i in range(m):
mat.append([fill]*n)
return mat
def sigmoid(x):
return 1.0 / (1.0+math.exp(-x))
def sigmoid_derivate(x):
return x*(1-x)
class BPNeuralNetwork:
def __init__(self):
self.input_n = 0
self.hidden_n = 0
self.output_n = 0
self.input_cells = []
self.hidden_cells = []
self.output_cells = []
self.input_weights = []
self.output_weights = []
def setup(self, ni, nh, no):
self.input_n = ni +1
self.hidden_n = nh
self.output_n = no
self.input_cells = [1.0] * self.input_n
self.hidden_cells = [1.0] * self.hidden_n
self.output_cells = [1.0] * self.output_n
self.input_weight
BP神经网络Python实现
最新推荐文章于 2024-03-09 16:30:01 发布