I want to define a operation in tensorflow that calculates something like:
x is provided by a tensor. Finally the operation should be compared to a known value and parameters alpha, beta i and b should be learned.
(I guess) The product of all inputs causes trouble. This is one version that I tried to deploy, with no success.
# input
X = tf.placeholder(tf.float32, [None, 2], name="X")
Y = tf.placeholder(tf.float32, [None, 1], name="Y")
# hidden
beta = tf.get_variable("beta", shape=[2], initializer=tf.contrib.layers.xavier_initializer())
powered = tf.pow(X,beta)
productLayer = tf.contrib.keras.layers.multiply(powered) # bad line
# output
w_o = tf.get_variable("w_o", shape=[1], initializer=tf.contrib.layers.xavier_initializer())
b_o = tf.get_variable("bias", shape=[1], initializer=tf.zeros([1]))
output = tf.add(tf.matmul(productLayer,w_o), b_o)
loss = tf.reduce_sum(tf.square(output - Y)) # tf.nn.l2_loss(yhat - Y)
File "h2o_test_opti.py", line 13, in
productLayer = tf.contrib.keras.layers.multiply(powered) ValueError: A merge layer should be called on a list of inputs.
I found an working solution to my idea by changing:
productLayer = tf.contrib.keras.layers.multiply(powered) # bad line
to:
productLayer = tf.reshape(tf.reduce_prod(X,1), (-1,1))
It should work. Maybe someone can use this too.