Skip to content

Commit

Permalink
add linear mean function to mean_functions and to example
Browse files Browse the repository at this point in the history
  • Loading branch information
t-vi committed Oct 26, 2017
1 parent bbc64fd commit 89a5eee
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 68 deletions.
4 changes: 2 additions & 2 deletions candlegp/densities.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def gammaln(x):


def gaussian(x, mu, var):
return -0.5 * (float(numpy.log(2 * numpy.pi)) + torch.log(var) + torch.square(mu-x)/var)
return -0.5 * (float(numpy.log(2 * numpy.pi)) + torch.log(var) + (mu-x)**2/var)

def lognormal(x, mu, var):
lnx = torch.log(x)
Expand All @@ -54,7 +54,7 @@ def gamma(shape, scale, x):
def student_t(x, mean, scale, deg_free): # todo
const = tf.lgamma(tf.cast((deg_free + 1.) * 0.5, float_type))\
- tf.lgamma(tf.cast(deg_free * 0.5, float_type))\
- 0.5*(tf.log(tf.square(scale)) + tf.cast(tf.log(deg_free), float_type)
- 0.5*(2*tf.log(scale) + tf.cast(tf.log(deg_free), float_type)
+ np.log(np.pi))
const = tf.cast(const, float_type)
return const - 0.5*(deg_free + 1.) * \
Expand Down
9 changes: 5 additions & 4 deletions candlegp/mean_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ def __init__(self, A=None, b=None):
A = torch.ones((1, 1)) if A is None else A
b = torch.zeros(1) if b is None else b
MeanFunction.__init__(self)
self.A = Parameter(np.atleast_2d(A))
self.b = Parameter(b)
if A.dim()==1:
A = A.unsqueeze(1)
self.A = parameter.Param(A)
self.b = parameter.Param(b)

#@params_as_tensors
def __call__(self, X):
return tf.matmul(X, self.A) + self.b
return torch.matmul(X, self.A.get()) + self.b.get()
Loading

0 comments on commit 89a5eee

Please sign in to comment.