-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfixphase.py
36 lines (29 loc) · 1.12 KB
/
fixphase.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
29
30
31
32
33
34
35
36
# taken from https://github.com/gparracl/MOSM
import numpy as np
import tensorflow as tf
import gpflow
class FixPhase(gpflow.transforms.Transform):
def __init__(self):
gpflow.transforms.Transform.__init__(self)
self.fixed_inds = np.array([0])
self.fixed_vals = np.zeros([1])
def forward(self, x):
total_size = x.shape[0] + self.fixed_inds.shape[0]
nonfixed_inds = np.setdiff1d(np.arange(total_size), self.fixed_inds)
y = np.empty(total_size)
y[nonfixed_inds] = x
y[self.fixed_inds] = self.fixed_vals
return y
def backward(self, y):
nonfixed_inds = np.setdiff1d(np.arange(y.shape[0]), self.fixed_inds)
x = y[nonfixed_inds]
return x
def forward_tensor(self, x):
total_size = tf.shape(x)[0] + self.fixed_inds.shape[0]
nonfixed_inds = tf.setdiff1d(tf.range(total_size), self.fixed_inds)[0]
y = tf.dynamic_stitch([self.fixed_inds, nonfixed_inds], [self.fixed_vals, x])
return y
def log_jacobian_tensor(self, x):
return 0.0
def __str__(self):
return 'PartiallyFixed'