第3章 完整神经网络算法
import tensorflow as tf from numpy.random import RandomState # 这是随机种子的那个东西 # 1定义神经网络的参数,输入和输出节点 batch_size = 8 w1= tf.Variable(tf.random_normal([2, 3], stddev=1, seed=1)) w2= tf.Variable(tf.random_normal([3, 1], stddev=1, seed=1)) x = tf.placeholder(tf.float32, shape=(None, 2), name="x-input") y_= tf.placeholder(tf.float32, shape=(None, 1), name='y-input') # 2定义前向传播过程,损失函数及反向传播算法 a = tf.matmul(x, w1) y = tf.matmul(a, w2) y = tf.sigmoid(y) cross_entropy = -tf.reduce_mean(y_ * tf.log(tf.clip_by_value(y, 1e-10, 1.0)) + (1 - y_) * tf.log(tf.clip_by_value(1 - y, 1e-10, 1.0))) train_step = tf.train