From 0f47a6b35feca3bd744601d7a7abec23cfa48432 Mon Sep 17 00:00:00 2001 From: Zhenwen Dai Date: Tue, 9 Sep 2014 11:46:19 +0100 Subject: [PATCH 1/4] adapt the numerical stability strategy from VarDTC to VarDTC_minibatch --- .../var_dtc_parallel.py | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/GPy/inference/latent_function_inference/var_dtc_parallel.py b/GPy/inference/latent_function_inference/var_dtc_parallel.py index a7e2a800..c5cf08d1 100644 --- a/GPy/inference/latent_function_inference/var_dtc_parallel.py +++ b/GPy/inference/latent_function_inference/var_dtc_parallel.py @@ -2,7 +2,7 @@ # Licensed under the BSD 3-clause license (see LICENSE.txt) 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 ...core.parameterization.variational import VariationalPosterior import numpy as np @@ -144,6 +144,7 @@ class VarDTC_minibatch(LatentFunctionInference): """ num_data, output_dim = Y.shape + input_dim = Z.shape[0] if self.mpi_comm != None: 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]) @@ -167,32 +168,23 @@ class VarDTC_minibatch(LatentFunctionInference): #====================================================================== from ...util.debug import checkFullRank - + Kmm = kern.K(Z).copy() diag.add(Kmm, self.const_jitter) r1 = checkFullRank(Kmm,name='Kmm') - Lm = jitchol(Kmm) - LmInv = dtrtri(Lm) + KmmInv,Lm,LmInv,_ = pdinv(Kmm) - #LmInvPsi2LmInvT = LmInv.dot(psi2_full).dot(LmInv.T) - LmInvPsi2LmInvT = backsub_both_sides(Lm,psi2_full,transpose='right') + LmInvPsi2LmInvT = LmInv.dot(psi2_full).dot(LmInv.T) Lambda = np.eye(Kmm.shape[0])+LmInvPsi2LmInvT r2 = checkFullRank(Lambda,name='Lambda') - if (not r1) or (not r2): - raise - LL = jitchol(Lambda) - LL = np.dot(Lm,LL) - b,_ = dtrtrs(LL, psi1Y_full.T) +# if (not r1) or (not r2): +# raise + LInv,LL,LLInv,logdet_L = pdinv(Lambda) + b = LLInv.dot(LmInv.dot(psi1Y_full.T)) bbt = np.square(b).sum() - v,_ = dtrtrs(LL.T,b,lower=False) - vvt = np.einsum('md,od->mo',v,v) + v = LmInv.T.dot(LLInv.T.dot(b)) - Psi2LLInvT = dtrtrs(LL,psi2_full)[0].T - 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 + 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. # Cache intermediate results self.midRes['dL_dpsi2R'] = dL_dpsi2R @@ -205,20 +197,21 @@ class VarDTC_minibatch(LatentFunctionInference): logL_R = -np.log(beta).sum() else: 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 #====================================================================== - 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 - KmmInv.dot(psi2_full).dot(KmmInv)/2. #====================================================================== # Compute the Posterior distribution of inducing points p(u|Y) #====================================================================== 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: post = None From 5697a533e7f1912ca180a71aeade309304a9a101 Mon Sep 17 00:00:00 2001 From: Zhenwen Dai Date: Tue, 9 Sep 2014 12:17:29 +0100 Subject: [PATCH 2/4] a bug fix for VarDTC_minibatch --- GPy/inference/latent_function_inference/var_dtc_parallel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPy/inference/latent_function_inference/var_dtc_parallel.py b/GPy/inference/latent_function_inference/var_dtc_parallel.py index c5cf08d1..53b31dab 100644 --- a/GPy/inference/latent_function_inference/var_dtc_parallel.py +++ b/GPy/inference/latent_function_inference/var_dtc_parallel.py @@ -204,7 +204,7 @@ class VarDTC_minibatch(LatentFunctionInference): #====================================================================== # dL_dKmm = -(output_dim*np.einsum('md,od->mo',KmmInvPsi2LLInvT,KmmInvPsi2LLInvT) + vvt)/2. - dL_dKmm = dL_dpsi2R - KmmInv.dot(psi2_full).dot(KmmInv)/2. + dL_dKmm = dL_dpsi2R - output_dim*KmmInv.dot(psi2_full).dot(KmmInv)/2. #====================================================================== # Compute the Posterior distribution of inducing points p(u|Y) From 47b12c20a30f22f58fe92af3b0e267b4ce810d2c Mon Sep 17 00:00:00 2001 From: Zhenwen Dai Date: Thu, 11 Sep 2014 13:21:35 +0100 Subject: [PATCH 3/4] remove nose from install_requires --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d9a6ab5e..847088ec 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ setup(name = 'GPy', package_data = {'GPy': ['defaults.cfg', 'installation.cfg', 'util/data_resources.json', 'util/football_teams.json']}, py_modules = ['GPy.__init__'], 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 = { 'docs':['Sphinx', 'ipython'], }, From 97d7fa69551ccc9eb0c8814adaee89b8ad8f01c0 Mon Sep 17 00:00:00 2001 From: Zhenwen Dai Date: Thu, 11 Sep 2014 14:29:50 +0100 Subject: [PATCH 4/4] add the Windows installation instructions for GPy --- doc/GPy.testing.rst | 8 ++++++++ doc/index.rst | 3 +++ doc/installation.rst | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 doc/installation.rst diff --git a/doc/GPy.testing.rst b/doc/GPy.testing.rst index 2d1132d7..657d0638 100644 --- a/doc/GPy.testing.rst +++ b/doc/GPy.testing.rst @@ -84,6 +84,14 @@ GPy.testing.prior_tests module :undoc-members: :show-inheritance: +GPy.testing.tie_tests module +---------------------------- + +.. automodule:: GPy.testing.tie_tests + :members: + :undoc-members: + :show-inheritance: + Module contents --------------- diff --git a/doc/index.rst b/doc/index.rst index 87d80be3..c00f31d3 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -19,6 +19,9 @@ You may also be interested by some examples in the GPy/examples folder. Contents: .. toctree:: + :maxdepth: 2 + + installation GPy diff --git a/doc/installation.rst b/doc/installation.rst new file mode 100644 index 00000000..8059e89a --- /dev/null +++ b/doc/installation.rst @@ -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 `_. +* 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 `_. 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 `_. + + +MacOSX +=================================== +