import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
tf.compat.v1.disable_eager_execution()defadd_layer(inputs,in_size,out_size,activation_function=None):#add one more layer and return the output of this layer#with tf.name_scope('layer'):#大框架#with tf.name_scope('weights'):#小部件#
Weights = tf.Variable(tf.random.normal([in_size,out_size]),name='W')with tf.name_scope('biases'):
biases = tf.Variable(tf.zeros([1,out_size])+0.1,name='b')with tf.name_scope('Wx_plus_b'):
Wx_plus_b = tf.add(tf.matmul(inputs,Weights),biases)#activation_function 先忽略,因为如果选定了的话他自己默认就有名字,比如选relu就叫relu,所以可以暂时不用处理他的名字 if activation_function isNone:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)return outputs
#make up some real data#
x_data = np.linspace(-1,1,300)[:,np.newaxis]
noise = np.random.normal(0,0.05,x_data.shape)
y_data =