# neural network class definition
import self as self
class neuralNetwork:
# initialise(初始化) the neural network
def _init_(self, inputnodes, hiddennodes, outputnodes, learningrate):
# set number of nodes in each input, hidden, output layer
self.inodes = inputnodes
self.hnodes = hiddennodes
self.onodes = outputnodes
# learning rate
self.lr = learningrate
pass
# train thr neural network
def train():
pass
# query(查询) the neural network
def query():
pass
# number of input, hidden and output nodes
# set a 3*3 neural network
input_nodes = 3
hidden_nodes = 3
output_nodes = 3
# learning is 0.5
learning_rate = 0.5
# create a instance of neural network
nw = neuralNetwork(input_nodes, hidden_nodes, output_nodes, learning_rate)
很离谱。。。因为我是用jupyter lab写的代码,没有代码自动补全与提示。
我上面的构造函数那写成了_init_,只写了一个_,init两边应该每边都有两个_的,
正确的写出来是__init__
# neural network class definition
import self as self
class neuralNetwork:
# initialise(初始化) the neural network
def __init__(self, inputnodes, hiddennodes, outputnodes, learningrate):
# set number of nodes in each input, hidden, output layer
self.inodes = inputnodes
self.hnodes = hiddennodes
self.onodes = outputnodes
# learning rate
self.lr = learningrate
pass
# train thr neural network
def train():
pass
# query(查询) the neural network
def query():
pass
# number of input, hidden and output nodes
# set a 3*3 neural network
input_nodes = 3
hidden_nodes = 3
output_nodes = 3
# learning is 0.5
learning_rate = 0.5
# create a instance of neural network
nw = neuralNetwork(input_nodes, hidden_nodes, output_nodes, learning_rate)