From da5cd50ad9d998df09ba27daee2d0ad0b0488af4 Mon Sep 17 00:00:00 2001
From: Luc Giffon <luc.giffon@lis-lab.fr>
Date: Tue, 27 Nov 2018 10:39:54 +0100
Subject: [PATCH] add steph's special chi2 kernel with normalization and tan

---
 skluc/main/keras_/kernel.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/skluc/main/keras_/kernel.py b/skluc/main/keras_/kernel.py
index 653be6c..807a335 100644
--- a/skluc/main/keras_/kernel.py
+++ b/skluc/main/keras_/kernel.py
@@ -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
-- 
GitLab