Skip to content

Commit 58932c4

Browse files
change pairwise distance
1 parent 5be0904 commit 58932c4

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ var/
1919
*.egg
2020
docs_build/
2121
docs/html/
22-
docs/doctrees/
22+
docs/doctrees/
23+
adapt/datasets.py
24+
datasets/

adapt/feature_based/_ccsa.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ def pairwise_y(X, Y):
1717
Y = tf.tile(tf.expand_dims(Y, -1), [1, 1, batch_size_x])
1818
return tf.reduce_sum(tf.abs(X-tf.transpose(Y)), 1)/2
1919

20+
2021
def pairwise_X(X, Y):
21-
batch_size_x = tf.shape(X)[0]
22-
batch_size_y = tf.shape(Y)[0]
23-
dim = tf.reduce_prod(tf.shape(X)[1:])
24-
X = tf.reshape(X, (batch_size_x, dim))
25-
Y = tf.reshape(Y, (batch_size_y, dim))
26-
X = tf.tile(tf.expand_dims(X, -1), [1, 1, batch_size_y])
27-
Y = tf.tile(tf.expand_dims(Y, -1), [1, 1, batch_size_x])
28-
return tf.reduce_sum(tf.square(X-tf.transpose(Y)), 1)
22+
X2 = tf.tile(tf.reduce_sum(tf.square(X), axis=1, keepdims=True), [1, tf.shape(Y)[0]])
23+
Y2 = tf.tile(tf.reduce_sum(tf.square(Y), axis=1, keepdims=True), [1, tf.shape(X)[0]])
24+
XY = tf.matmul(X, tf.transpose(Y))
25+
return X2 + tf.transpose(Y2) - 2*XY
2926

3027

3128
@make_insert_doc(["encoder", "task"], supervised=True)

adapt/feature_based/_fmmd.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88

99

1010
def pairwise_X(X, Y):
11-
batch_size_x = tf.shape(X)[0]
12-
batch_size_y = tf.shape(Y)[0]
13-
dim = tf.reduce_prod(tf.shape(X)[1:])
14-
X = tf.reshape(X, (batch_size_x, dim))
15-
Y = tf.reshape(Y, (batch_size_y, dim))
16-
X = tf.tile(tf.expand_dims(X, -1), [1, 1, batch_size_y])
17-
Y = tf.tile(tf.expand_dims(Y, -1), [1, 1, batch_size_x])
18-
return tf.reduce_sum(tf.square(X-tf.transpose(Y)), 1)
11+
X2 = tf.tile(tf.reduce_sum(tf.square(X), axis=1, keepdims=True), [1, tf.shape(Y)[0]])
12+
Y2 = tf.tile(tf.reduce_sum(tf.square(Y), axis=1, keepdims=True), [1, tf.shape(X)[0]])
13+
XY = tf.matmul(X, tf.transpose(Y))
14+
return X2 + tf.transpose(Y2) - 2*XY
1915

2016

2117
def _get_optim_function(Xs, Xt, kernel="linear", gamma=1., degree=2, coef=1.):

0 commit comments

Comments
 (0)