Skip to content
Snippets Groups Projects
Commit da5cd50a authored by Luc Giffon's avatar Luc Giffon
Browse files

add steph's special chi2 kernel with normalization and tan

parent 26e01d39
Branches
No related tags found
No related merge requests found
......@@ -26,6 +26,23 @@ def keras_chi_square_CPD(args):
K = - tf.reduce_sum(quotient_without_nan, axis=2)
return K
def chi2_kernel(args):
x = args[0]
y = tf.concat(args[1:], 0)
x = tf.nn.l2_normalize(x, axis=-1)
y = tf.nn.l2_normalize(y, axis=-1)
# the drawing of the matrix X expanded looks like a wall
wall = tf.expand_dims(x, axis=1)
# the drawing of the matrix Y expanded looks like a floor
floor = tf.expand_dims(y, axis=0)
numerator = tf.square(tf.subtract(wall, floor))
denominator = tf.add(wall, floor) + 0.001
quotient = numerator / denominator
quotient_without_nan = quotient #replace_nan(quotient)
K = - tf.reduce_sum(quotient_without_nan, axis=2)
return tf.tanh(K)
if __name__ == '__main__':
a = tf.Constant(value=0)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment