mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-03 16:52:39 +02:00
Merge branch 'devel' of github.com:SheffieldML/GPy into devel
This commit is contained in:
commit
31ace537a5
5 changed files with 61 additions and 23 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||||
|
|
||||||
from posterior import Posterior
|
from posterior import Posterior
|
||||||
from ...util.linalg import jitchol, backsub_both_sides, tdot, dtrtrs, dtrtri
|
from ...util.linalg import jitchol, backsub_both_sides, tdot, dtrtrs, dtrtri,pdinv
|
||||||
from ...util import diag
|
from ...util import diag
|
||||||
from ...core.parameterization.variational import VariationalPosterior
|
from ...core.parameterization.variational import VariationalPosterior
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
@ -144,6 +144,7 @@ class VarDTC_minibatch(LatentFunctionInference):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
num_data, output_dim = Y.shape
|
num_data, output_dim = Y.shape
|
||||||
|
input_dim = Z.shape[0]
|
||||||
if self.mpi_comm != None:
|
if self.mpi_comm != None:
|
||||||
num_data_all = np.array(num_data,dtype=np.int32)
|
num_data_all = np.array(num_data,dtype=np.int32)
|
||||||
self.mpi_comm.Allreduce([np.int32(num_data), MPI.INT], [num_data_all, MPI.INT])
|
self.mpi_comm.Allreduce([np.int32(num_data), MPI.INT], [num_data_all, MPI.INT])
|
||||||
|
|
@ -171,28 +172,19 @@ class VarDTC_minibatch(LatentFunctionInference):
|
||||||
Kmm = kern.K(Z).copy()
|
Kmm = kern.K(Z).copy()
|
||||||
diag.add(Kmm, self.const_jitter)
|
diag.add(Kmm, self.const_jitter)
|
||||||
r1 = checkFullRank(Kmm,name='Kmm')
|
r1 = checkFullRank(Kmm,name='Kmm')
|
||||||
Lm = jitchol(Kmm)
|
KmmInv,Lm,LmInv,_ = pdinv(Kmm)
|
||||||
LmInv = dtrtri(Lm)
|
|
||||||
|
|
||||||
#LmInvPsi2LmInvT = LmInv.dot(psi2_full).dot(LmInv.T)
|
LmInvPsi2LmInvT = LmInv.dot(psi2_full).dot(LmInv.T)
|
||||||
LmInvPsi2LmInvT = backsub_both_sides(Lm,psi2_full,transpose='right')
|
|
||||||
Lambda = np.eye(Kmm.shape[0])+LmInvPsi2LmInvT
|
Lambda = np.eye(Kmm.shape[0])+LmInvPsi2LmInvT
|
||||||
r2 = checkFullRank(Lambda,name='Lambda')
|
r2 = checkFullRank(Lambda,name='Lambda')
|
||||||
if (not r1) or (not r2):
|
# if (not r1) or (not r2):
|
||||||
raise
|
# raise
|
||||||
LL = jitchol(Lambda)
|
LInv,LL,LLInv,logdet_L = pdinv(Lambda)
|
||||||
LL = np.dot(Lm,LL)
|
b = LLInv.dot(LmInv.dot(psi1Y_full.T))
|
||||||
b,_ = dtrtrs(LL, psi1Y_full.T)
|
|
||||||
bbt = np.square(b).sum()
|
bbt = np.square(b).sum()
|
||||||
v,_ = dtrtrs(LL.T,b,lower=False)
|
v = LmInv.T.dot(LLInv.T.dot(b))
|
||||||
vvt = np.einsum('md,od->mo',v,v)
|
|
||||||
|
|
||||||
Psi2LLInvT = dtrtrs(LL,psi2_full)[0].T
|
dL_dpsi2R = LmInv.T.dot(-LLInv.T.dot(tdot(b)+output_dim*np.eye(input_dim)).dot(LLInv)+output_dim*np.eye(input_dim)).dot(LmInv)/2.
|
||||||
LmInvPsi2LLInvT= dtrtrs(Lm,Psi2LLInvT)[0]
|
|
||||||
KmmInvPsi2LLInvT = dtrtrs(Lm,LmInvPsi2LLInvT,trans=True)[0]
|
|
||||||
KmmInvPsi2P = dtrtrs(LL,KmmInvPsi2LLInvT.T, trans=True)[0].T
|
|
||||||
|
|
||||||
dL_dpsi2R = (output_dim*KmmInvPsi2P - vvt)/2. # dL_dpsi2 with R inside psi2
|
|
||||||
|
|
||||||
# Cache intermediate results
|
# Cache intermediate results
|
||||||
self.midRes['dL_dpsi2R'] = dL_dpsi2R
|
self.midRes['dL_dpsi2R'] = dL_dpsi2R
|
||||||
|
|
@ -205,20 +197,21 @@ class VarDTC_minibatch(LatentFunctionInference):
|
||||||
logL_R = -np.log(beta).sum()
|
logL_R = -np.log(beta).sum()
|
||||||
else:
|
else:
|
||||||
logL_R = -num_data*np.log(beta)
|
logL_R = -num_data*np.log(beta)
|
||||||
logL = -(output_dim*(num_data*log_2_pi+logL_R+psi0_full-np.trace(LmInvPsi2LmInvT))+YRY_full-bbt)/2.-output_dim*(-np.log(np.diag(Lm)).sum()+np.log(np.diag(LL)).sum())
|
logL = -(output_dim*(num_data*log_2_pi+logL_R+psi0_full-np.trace(LmInvPsi2LmInvT))+YRY_full-bbt)/2.-output_dim*logdet_L/2.
|
||||||
|
|
||||||
#======================================================================
|
#======================================================================
|
||||||
# Compute dL_dKmm
|
# Compute dL_dKmm
|
||||||
#======================================================================
|
#======================================================================
|
||||||
|
|
||||||
dL_dKmm = -(output_dim*np.einsum('md,od->mo',KmmInvPsi2LLInvT,KmmInvPsi2LLInvT) + vvt)/2.
|
# dL_dKmm = -(output_dim*np.einsum('md,od->mo',KmmInvPsi2LLInvT,KmmInvPsi2LLInvT) + vvt)/2.
|
||||||
|
dL_dKmm = dL_dpsi2R - output_dim*KmmInv.dot(psi2_full).dot(KmmInv)/2.
|
||||||
|
|
||||||
#======================================================================
|
#======================================================================
|
||||||
# Compute the Posterior distribution of inducing points p(u|Y)
|
# Compute the Posterior distribution of inducing points p(u|Y)
|
||||||
#======================================================================
|
#======================================================================
|
||||||
|
|
||||||
if not self.Y_speedup or het_noise:
|
if not self.Y_speedup or het_noise:
|
||||||
post = Posterior(woodbury_inv=KmmInvPsi2P, woodbury_vector=v, K=Kmm, mean=None, cov=None, K_chol=Lm)
|
post = Posterior(woodbury_inv=LmInv.T.dot(np.eye(input_dim)-LInv).dot(LmInv), woodbury_vector=v, K=Kmm, mean=None, cov=None, K_chol=Lm)
|
||||||
else:
|
else:
|
||||||
post = None
|
post = None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,14 @@ GPy.testing.prior_tests module
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
|
GPy.testing.tie_tests module
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
.. automodule:: GPy.testing.tie_tests
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
|
|
||||||
Module contents
|
Module contents
|
||||||
---------------
|
---------------
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@ You may also be interested by some examples in the GPy/examples folder.
|
||||||
Contents:
|
Contents:
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
|
||||||
|
installation
|
||||||
GPy
|
GPy
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
34
doc/installation.rst
Normal file
34
doc/installation.rst
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
==============
|
||||||
|
Installation
|
||||||
|
==============
|
||||||
|
|
||||||
|
|
||||||
|
Linux
|
||||||
|
============
|
||||||
|
|
||||||
|
|
||||||
|
Windows
|
||||||
|
======================
|
||||||
|
One easy way to get a Python distribution with the required packages is to use the Anaconda environment from Continuum Analytics.
|
||||||
|
|
||||||
|
* Download and install the free version of Anaconda according to your operating system from `their website <https://store.continuum.io>`_.
|
||||||
|
* Open a (new) terminal window:
|
||||||
|
|
||||||
|
* Navigate to Applications/Accessories/cmd, or
|
||||||
|
* open *anaconda Command Prompt* from windows *start*
|
||||||
|
|
||||||
|
You should now be able to launch a Python interpreter by typing *ipython* in the terminal. In the ipython prompt, you can check your installation by importing the libraries we will need later:
|
||||||
|
::
|
||||||
|
$ import numpy
|
||||||
|
$ import pylab
|
||||||
|
|
||||||
|
To install the latest version of GPy, *git* is required. A *git* client on Windows can be found `here <http://git-scm.com/download/win>`_. It is recommened to install with the option "*Use Git from the Windows Command Prompt*". Then, GPy can be installed with the following command
|
||||||
|
::
|
||||||
|
pip install git+https://github.com/SheffieldML/GPy.git@devel
|
||||||
|
|
||||||
|
Note that some of the functionalities in GPy require a *C/C++* compiler. One option would be to install a MSVC compiler, e.g., an Express Edition can be found `here <http://www.microsoft.com/express/download>`_.
|
||||||
|
|
||||||
|
|
||||||
|
MacOSX
|
||||||
|
===================================
|
||||||
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -24,7 +24,7 @@ setup(name = 'GPy',
|
||||||
package_data = {'GPy': ['defaults.cfg', 'installation.cfg', 'util/data_resources.json', 'util/football_teams.json']},
|
package_data = {'GPy': ['defaults.cfg', 'installation.cfg', 'util/data_resources.json', 'util/football_teams.json']},
|
||||||
py_modules = ['GPy.__init__'],
|
py_modules = ['GPy.__init__'],
|
||||||
long_description=read('README.md'),
|
long_description=read('README.md'),
|
||||||
install_requires=['numpy>=1.6', 'scipy>=0.9','matplotlib>=1.1', 'nose'],
|
install_requires=['numpy>=1.6', 'scipy>=0.9','matplotlib>=1.1'],
|
||||||
extras_require = {
|
extras_require = {
|
||||||
'docs':['Sphinx', 'ipython'],
|
'docs':['Sphinx', 'ipython'],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue