mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-08 15:05:15 +02:00
Merge branch 'devel' of github.com:/sheffieldml/GPy into devel
This commit is contained in:
commit
ad92e5cd9b
3 changed files with 21 additions and 2 deletions
|
|
@ -121,7 +121,7 @@ class LinearSlopeBasisFuncKernel(BasisFuncKernel):
|
|||
|
||||
class ChangePointBasisFuncKernel(BasisFuncKernel):
|
||||
def __init__(self, input_dim, changepoint, variance=1., active_dims=None, ARD=False, name='changepoint'):
|
||||
self.changepoint = changepoint
|
||||
self.changepoint = np.array(changepoint)
|
||||
super(ChangePointBasisFuncKernel, self).__init__(input_dim, variance, active_dims, ARD, name)
|
||||
|
||||
@Cache_this(limit=3, ignore_args=())
|
||||
|
|
|
|||
|
|
@ -50,3 +50,11 @@ class LinalgTests(np.testing.TestCase):
|
|||
pure = np.einsum('ijk,jlk->il', A, B)
|
||||
quick = GPy.util.linalg.ijk_jlk_to_il(A,B)
|
||||
np.testing.assert_allclose(pure, quick)
|
||||
|
||||
def test_einsum_ijk_ljk_to_ilk(self):
|
||||
A = np.random.randn(150, 20, 5)
|
||||
B = np.random.randn(150, 20, 5)
|
||||
#B = A.copy()
|
||||
pure = np.einsum('ijk,ljk->ilk', A, B)
|
||||
quick = GPy.util.linalg.ijk_ljk_to_ilk(A,B)
|
||||
np.testing.assert_allclose(pure, quick)
|
||||
|
|
|
|||
|
|
@ -463,5 +463,16 @@ def ijk_jlk_to_il(A, B):
|
|||
Faster version of einsum einsum('ijk,jlk->il', A,B)
|
||||
"""
|
||||
res = np.zeros((A.shape[0], B.shape[1]))
|
||||
[np.add(np.dot(A[:,:,k], B[:,:,k]), res, res) for k in range(B.shape[-1])]
|
||||
[np.add(np.dot(A[:,:,k], B[:,:,k]), res, out=res) for k in range(B.shape[-1])]
|
||||
return res
|
||||
|
||||
def ijk_ljk_to_ilk(A, B):
|
||||
"""
|
||||
Faster version of einsum np.einsum('ijk,ljk->ilk', A, B)
|
||||
|
||||
I.e A.dot(B.T) for every dimension
|
||||
"""
|
||||
res = np.zeros((A.shape[-1], A.shape[0], B.shape[0]))
|
||||
[np.dot(A[:,:,i], B[:,:,i].T, out=res[i,:,:]) for i in range(A.shape[-1])]
|
||||
res = res.swapaxes(0, 2).swapaxes(0,1)
|
||||
return res
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue