这是完全简单的事情。对于“一个输入”,你会得到类似的东西:
def build_column(x, input_size):
w = tf.Variable(tf.random_normal([input_size, 20]))
b = tf.Variable(tf.random_normal([20]))
processing1 = tf.nn.sigmoid(tf.matmul(x, w) + b)
w = tf.Variable(tf.random_normal([20, 3]))
b = tf.Variable(tf.random_normal([3]))
return tf.nn.sigmoid(tf.matmul(processing1, w) + b)
input1 = tf.placeholder(tf.float32, [None, 2])
output1 = build_column(input1, 2) # 2-20-3 network
您可以简单地添加更多此类“列”并随时合并它们
input1 = tf.placeholder(tf.float32, [None, 2])
output1 = build_column(input1, 2)
input2 = tf.placeholder(tf.float32, [None, 10])
output2 = build_column(input1, 10)
input3 = tf.placeholder(tf.float32, [None, 5])
output3 = build_column(input1, 5)
whole_model = output1 + output2 + output3 # since they are all the same size
你会得到如下所示的网络:
2-20-3\
\
10-20-3--SUM (dimension-wise)
/
5-20-3/
或进行单值输出
w1 = tf.Variable(tf.random_normal([3, 1]))
w2 = tf.Variable(tf.random_normal([3, 1]))
w3 = tf.Variable(tf.random_normal([3, 1]))
whole_model = tf.matmul(output1, w1) + tf.matmul(output2, w2) + tf.matmul(output3, w3)
to get
2-20-3\
\
10-20-3--1---
/
5-20-3/