def K(self, X, X2=None): """ Computes the Laplace kernel matrix between inputs X (and X2) belonging to a SPD manifold. Parameters ---------- :param X: input points on the SPD manifold (Mandel notation) Optional parameters ------------------- :param X2: input points on the SPD manifold (Mandel notation) Returns ------- :return: kernel matrix of X or between X and X2 """ # Transform input vector to matrices X = vector_to_symmetric_matrix_tf(X, self.matrix_dim) if X2 is None: X2 = X else: X2 = vector_to_symmetric_matrix_tf(X2, self.matrix_dim) # Compute beta value from beta_shifted beta = self.beta_shifted + self.beta_min_value # Compute the kernel aff_inv_dist = affine_invariant_distance_tf(X, X2, full_dist_mat=True) aff_inv_dist = tf.multiply(aff_inv_dist, beta) return tf.multiply(self.variance, tf.exp(-aff_inv_dist))
def K(self, X, X2=None): """ Computes the Stein kernel matrix between inputs X (and X2) belonging to a SPD manifold. Parameters ---------- :param X: input points on the SPD manifold (Mandel notation) Optional parameters ------------------- :param X2: input points on the SPD manifold (Mandel notation) Returns ------- :return: kernel matrix of X or between X and X2 """ # Transform input vector to matrices X = vector_to_symmetric_matrix_tf(X, self.matrix_dim) if X2 is None: X2 = X else: X2 = vector_to_symmetric_matrix_tf(X2, self.matrix_dim) # Compute beta value from beta_shifted beta = self.beta_shifted + self.continuous_param_space_limit # Compute the kernel X = tf.expand_dims(X, 1) X2 = tf.expand_dims(X2, 0) X = tf.tile(X, [1, tf.shape(X2)[1], 1, 1]) X2 = tf.tile(X2, [tf.shape(X)[0], 1, 1, 1]) mult_XX2 = tf.matmul(X, X2) add_halfXX2 = 0.5 * tf.add(X, X2) detmult_XX2 = tf.linalg.det(mult_XX2) detadd_halfXX2 = tf.linalg.det(add_halfXX2) dist = tf.divide(tf.math.pow(detmult_XX2, beta), tf.math.pow(detadd_halfXX2, beta)) return tf.multiply(self.variance, dist)
def K(self, X, X2=None): """ Computes the Log-Euclidean kernel matrix between inputs X (and X2) belonging to a SPD manifold. Parameters ---------- :param X: input points on the SPD manifold (Mandel notation) Optional parameters ------------------- :param X2: input points on the SPD manifold (Mandel notation) Returns ------- :return: kernel matrix of X or between X and X2 """ # Transform input vector to matrices X = vector_to_symmetric_matrix_tf(X, self.matrix_dim) if X2 is None: X2 = X else: X2 = vector_to_symmetric_matrix_tf(X2, self.matrix_dim) # Compute the kernel X = tf.expand_dims(X, 1) X2 = tf.expand_dims(X2, 0) X = tf.tile(X, [1, tf.shape(X2)[1], 1, 1]) X2 = tf.tile(X2, [tf.shape(X)[0], 1, 1, 1]) diff_XX2 = tf.cast(tf.subtract(tf.linalg.logm(tf.cast(X, dtype=tf.complex64)), tf.linalg.logm(tf.cast(X2, dtype=tf.complex64))), dtype=tf.float64) logeucl_dist = tf.norm(diff_XX2, axis=(-2, -1)) logeucl_dist2 = tf.square(logeucl_dist) logeucl_dist2 = tf.multiply(logeucl_dist2, self.beta_param) return tf.multiply(self.variance, tf.exp(-logeucl_dist2))