-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlikelihoods.py
31 lines (21 loc) · 1013 Bytes
/
likelihoods.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
# Credit to GPFlow.
import tensorflow as tf
import numpy as np
class Gaussian(object):
def logdensity(self, x, mu, var):
return -0.5 * (np.log(2 * np.pi) + tf.log(var) + tf.square(mu-x) / var)
def __init__(self, variance=1.0, **kwargs):
self.variance = tf.exp(tf.Variable(np.log(variance), dtype=tf.float64, name='lik_log_variance'))
def logp(self, F, Y):
return self.logdensity(Y, F, self.variance)
def conditional_mean(self, F):
return tf.identity(F)
def conditional_variance(self, F):
return tf.fill(tf.shape(F), tf.squeeze(self.variance))
def predict_mean_and_var(self, Fmu, Fvar):
return tf.identity(Fmu), Fvar + self.variance
def predict_density(self, Fmu, Fvar, Y):
return self.logdensity(Y, Fmu, Fvar + self.variance)
def variational_expectations(self, Fmu, Fvar, Y):
return -0.5 * np.log(2 * np.pi) - 0.5 * tf.log(self.variance) \
- 0.5 * (tf.square(Y - Fmu) + Fvar) / self.variance