Skip to content

Commit

Permalink
add triangular parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
t-vi committed Oct 31, 2017
1 parent 5448a52 commit a8164e5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions candlegp/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,30 @@ def get(self):
return self
def log_jacobian(self):
return Variable(self.data.new(1).zero_()) # dimension?


class LowerTriangularParam(ParamWithPrior):
"""
A transform of the form
tri_mat = vec_to_tri(x)
x is a free variable, y is always a list of lower triangular matrices sized
(N x N x D).
"""
@staticmethod
def untransform(t, out=None):
ii,jj = numpy.tril_indices(t.size(0))
return t[ii,jj]
def get(self):
numel = self.size(0)
N = int((2*numel+0.25)**0.5-0.5)
ii,jj = numpy.tril_indices(N)
if self.dim()==2:
mat = Variable(self.data.new(N,N, self.size(1)).zero_())
else:
mat = Variable(self.data.new(N,N).zero_())
mat[ii,jj] = self
return mat
def log_jacobian(self):
return Variable(self.data.new(1).zero_()) # dimension?

0 comments on commit a8164e5

Please sign in to comment.