forked from KrishnaswamyLab/SAUCIE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
executable file
·28 lines (22 loc) · 907 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import math
import tensorflow as tf
import numpy as np
def asinh(x, scale=5.):
"""Asinh transform."""
f = np.vectorize(lambda y: math.asinh(y / scale))
return f(x)
def sinh(x, scale=5.):
"""Reverse transform for asinh."""
return scale * np.sinh(x)
def lrelu(x, leak=0.2, name="lrelu"):
"""Leaky ReLU activation."""
return tf.maximum(x, leak * x)
def tbn(name):
"""Get the tensor in the default graph of the given name."""
return tf.get_default_graph().get_tensor_by_name(name)
def obn(name):
"""Get the operation node in the default graph of the given name."""
return tf.get_default_graph().get_operation_by_name(name)
def calculate_mmd(k1, k2, k12):
""" Calculates MMD given kernels for batch1, batch2, and between batches """
return k1.sum()/(k1.shape[0]*k1.shape[1]) + k2.sum()/(k2.shape[0]*k2.shape[1]) - 2*k12.sum()/(k12.shape[0]*k12.shape[1])