mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-15 06:52:39 +02:00
commit
013064fa41
66 changed files with 302 additions and 71 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -46,3 +46,6 @@ iterate.dat
|
||||||
# git merge files #
|
# git merge files #
|
||||||
###################
|
###################
|
||||||
*.orig
|
*.orig
|
||||||
|
|
||||||
|
# pycharm IDE stuff
|
||||||
|
.idea/
|
||||||
|
|
|
||||||
100
CHANGELOG.md
100
CHANGELOG.md
|
|
@ -1,5 +1,105 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v1.6.1 (2017-02-28)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
* Beiwang will add GMM in full. [mzwiessele]
|
||||||
|
|
||||||
|
### Other
|
||||||
|
|
||||||
|
* Bump version: 1.6.0 → 1.6.1. [mzwiessele]
|
||||||
|
|
||||||
|
|
||||||
|
## v1.6.0 (2017-02-28)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
* Kernel tests and variational tests. [mzwiessele]
|
||||||
|
|
||||||
|
* Plotting tests for new matplotlib. [mzwiessele]
|
||||||
|
|
||||||
|
* Model tests numpy integer error. [mzwiessele]
|
||||||
|
|
||||||
|
* Replot with new matplotlib. [mzwiessele]
|
||||||
|
|
||||||
|
* Offline plotting workaround with squeezing arrays. [mzwiessele]
|
||||||
|
|
||||||
|
* Fixed numpy 1.12 indexing and shape preservation. [mzwiessele]
|
||||||
|
|
||||||
|
### Other
|
||||||
|
|
||||||
|
* Bump version: 1.5.9 → 1.6.0. [mzwiessele]
|
||||||
|
|
||||||
|
* Merge branch 'devel' into alexfeld-offline_plotly. [mzwiessele]
|
||||||
|
|
||||||
|
* Merge branch 'devel' into alexfeld-offline_plotly. [mzwiessele]
|
||||||
|
|
||||||
|
* Merge branch 'offline_plotly' of git://github.com/alexfeld/GPy into alexfeld-offline_plotly. [mzwiessele]
|
||||||
|
|
||||||
|
* Provide two classes for plotly plots to remove global variable. [Alex Feldstein]
|
||||||
|
|
||||||
|
* Add offline plotting for plotly. [Alex Feldstein]
|
||||||
|
|
||||||
|
|
||||||
|
## v1.5.9 (2017-02-23)
|
||||||
|
|
||||||
|
### Other
|
||||||
|
|
||||||
|
* Bump version: 1.5.8 → 1.5.9. [mzwiessele]
|
||||||
|
|
||||||
|
* Merge remote-tracking branch 'origin/deploy' into devel. [mzwiessele]
|
||||||
|
|
||||||
|
* Merge pull request #455 from SheffieldML/devel. [Max Zwiessele]
|
||||||
|
|
||||||
|
1.5.6
|
||||||
|
|
||||||
|
|
||||||
|
## v1.5.8 (2017-02-23)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
* Predictive_gradients for new posterior class. [mzwiessele]
|
||||||
|
|
||||||
|
* Removed additional dict line. [mzwiessele]
|
||||||
|
|
||||||
|
* Plotting also allows 3D (capitals) [mzwiessele]
|
||||||
|
|
||||||
|
* Fallback for when no environment variables are set (#467) [Safrone]
|
||||||
|
|
||||||
|
* fix: dev: add or in home directory getting
|
||||||
|
|
||||||
|
adds another or when getting the home directory with os.getenv() so that if neither $HOME nor $USERPROFILE environment variable is set, os.path.join() will not fail by getting a None and the config will revert to the default configuration file.
|
||||||
|
|
||||||
|
* fix: remove extra statement
|
||||||
|
|
||||||
|
### Other
|
||||||
|
|
||||||
|
* Bump version: 1.5.7 → 1.5.8. [mzwiessele]
|
||||||
|
|
||||||
|
* Update ss_gplvm.py. [Zhenwen Dai]
|
||||||
|
|
||||||
|
resolve the future warning: FutureWarning:comparison to `None` will result in an elementwise object comparison in the future.
|
||||||
|
|
||||||
|
* Merge pull request #472 from SheffieldML/predictive_gradients. [Max Zwiessele]
|
||||||
|
|
||||||
|
fix: predictive_gradients for new posterior class
|
||||||
|
|
||||||
|
* Merge pull request #470 from SheffieldML/plotting_fix. [Max Zwiessele]
|
||||||
|
|
||||||
|
Plotting fix
|
||||||
|
|
||||||
|
* Bump version: 1.5.6 → 1.5.7. [mzwiessele]
|
||||||
|
|
||||||
|
* Changed the order of the operations, ensuring that the covariance matrix is symmetric despite numerical precision issues. Suggested by Alan. [Teo de Campos]
|
||||||
|
|
||||||
|
* Delete gmm_bayesian_gplvm.py. [beiwang]
|
||||||
|
|
||||||
|
* Gmm_creation. [beiwang]
|
||||||
|
|
||||||
|
* Gmm_creation. [beiwang]
|
||||||
|
|
||||||
|
|
||||||
## v1.5.6 (2016-11-07)
|
## v1.5.6 (2016-11-07)
|
||||||
|
|
||||||
### New
|
### New
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
__version__ = "1.5.6"
|
__version__ = "1.6.1"
|
||||||
|
|
|
||||||
|
|
@ -339,9 +339,17 @@ class GP(Model):
|
||||||
# gradients wrt the diagonal part k_{xx}
|
# gradients wrt the diagonal part k_{xx}
|
||||||
dv_dX = kern.gradients_X(np.eye(Xnew.shape[0]), Xnew)
|
dv_dX = kern.gradients_X(np.eye(Xnew.shape[0]), Xnew)
|
||||||
#grads wrt 'Schur' part K_{xf}K_{ff}^{-1}K_{fx}
|
#grads wrt 'Schur' part K_{xf}K_{ff}^{-1}K_{fx}
|
||||||
alpha = -2.*np.dot(kern.K(Xnew, self._predictive_variable), self.posterior.woodbury_inv)
|
if self.posterior.woodbury_inv.ndim == 3:
|
||||||
dv_dX += kern.gradients_X(alpha, Xnew, self._predictive_variable)
|
tmp = np.empty(dv_dX.shape + (self.posterior.woodbury_inv.shape[2],))
|
||||||
return mean_jac, dv_dX
|
tmp[:] = dv_dX[:,:,None]
|
||||||
|
for i in range(self.posterior.woodbury_inv.shape[2]):
|
||||||
|
alpha = -2.*np.dot(kern.K(Xnew, self._predictive_variable), self.posterior.woodbury_inv[:, :, i])
|
||||||
|
tmp[:, :, i] += kern.gradients_X(alpha, Xnew, self._predictive_variable)
|
||||||
|
else:
|
||||||
|
tmp = dv_dX
|
||||||
|
alpha = -2.*np.dot(kern.K(Xnew, self._predictive_variable), self.posterior.woodbury_inv)
|
||||||
|
tmp += kern.gradients_X(alpha, Xnew, self._predictive_variable)
|
||||||
|
return mean_jac, tmp
|
||||||
|
|
||||||
def predict_jacobian(self, Xnew, kern=None, full_cov=False):
|
def predict_jacobian(self, Xnew, kern=None, full_cov=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -68,12 +68,12 @@ class GpGrid(GP):
|
||||||
for b in (B.T):
|
for b in (B.T):
|
||||||
x = b
|
x = b
|
||||||
N = 1
|
N = 1
|
||||||
G = np.zeros(D)
|
G = np.zeros(D, dtype=np.int_)
|
||||||
for d in range(D):
|
for d in range(D):
|
||||||
G[d] = len(A[d])
|
G[d] = len(A[d])
|
||||||
N = np.prod(G)
|
N = np.prod(G)
|
||||||
for d in range(D-1, -1, -1):
|
for d in range(D-1, -1, -1):
|
||||||
X = np.reshape(x, (G[d], np.round(N/G[d])), order='F')
|
X = np.reshape(x, (G[d], int(np.round(N/G[d]))), order='F')
|
||||||
Z = np.dot(A[d], X)
|
Z = np.dot(A[d], X)
|
||||||
Z = Z.T
|
Z = Z.T
|
||||||
x = np.reshape(Z, (-1, 1), order='F')
|
x = np.reshape(Z, (-1, 1), order='F')
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ def _simulate_sincos(D1, D2, D3, N, num_inducing, plot_sim=False):
|
||||||
|
|
||||||
x = _np.linspace(0, 4 * _np.pi, N)[:, None]
|
x = _np.linspace(0, 4 * _np.pi, N)[:, None]
|
||||||
s1 = _np.vectorize(lambda x: _np.sin(x))
|
s1 = _np.vectorize(lambda x: _np.sin(x))
|
||||||
s2 = _np.vectorize(lambda x: _np.cos(x) ** 2)
|
s2 = _np.vectorize(lambda x: _np.cos(x))
|
||||||
s3 = _np.vectorize(lambda x:-_np.exp(-_np.cos(2 * x)))
|
s3 = _np.vectorize(lambda x:-_np.exp(-_np.cos(2 * x)))
|
||||||
sS = _np.vectorize(lambda x: _np.cos(x))
|
sS = _np.vectorize(lambda x: _np.cos(x))
|
||||||
|
|
||||||
|
|
@ -302,8 +302,8 @@ def _simulate_sincos(D1, D2, D3, N, num_inducing, plot_sim=False):
|
||||||
|
|
||||||
def _generate_high_dimensional_output(D1, D2, D3, s1, s2, s3, sS):
|
def _generate_high_dimensional_output(D1, D2, D3, s1, s2, s3, sS):
|
||||||
S1 = _np.hstack([s1, sS])
|
S1 = _np.hstack([s1, sS])
|
||||||
S2 = _np.hstack([s2, s3, sS])
|
S2 = _np.hstack([sS])
|
||||||
S3 = _np.hstack([s3, sS])
|
S3 = _np.hstack([s1, s3, sS])
|
||||||
Y1 = S1.dot(_np.random.randn(S1.shape[1], D1))
|
Y1 = S1.dot(_np.random.randn(S1.shape[1], D1))
|
||||||
Y2 = S2.dot(_np.random.randn(S2.shape[1], D2))
|
Y2 = S2.dot(_np.random.randn(S2.shape[1], D2))
|
||||||
Y3 = S3.dot(_np.random.randn(S3.shape[1], D3))
|
Y3 = S3.dot(_np.random.randn(S3.shape[1], D3))
|
||||||
|
|
|
||||||
|
|
@ -36,12 +36,12 @@ class GaussianGridInference(LatentFunctionInference):
|
||||||
x = b
|
x = b
|
||||||
N = 1
|
N = 1
|
||||||
D = len(A)
|
D = len(A)
|
||||||
G = np.zeros((D,1))
|
G = np.zeros((D), dtype=np.int_)
|
||||||
for d in range(0, D):
|
for d in range(0, D):
|
||||||
G[d] = len(A[d])
|
G[d] = len(A[d])
|
||||||
N = np.prod(G)
|
N = np.prod(G)
|
||||||
for d in range(D-1, -1, -1):
|
for d in range(D-1, -1, -1):
|
||||||
X = np.reshape(x, (G[d], np.round(N/G[d])), order='F')
|
X = np.reshape(x, (G[d], int(np.round(N/G[d]))), order='F')
|
||||||
Z = np.dot(A[d], X)
|
Z = np.dot(A[d], X)
|
||||||
Z = Z.T
|
Z = Z.T
|
||||||
x = np.reshape(Z, (-1, 1), order='F')
|
x = np.reshape(Z, (-1, 1), order='F')
|
||||||
|
|
|
||||||
|
|
@ -46,11 +46,11 @@ class Kern(Parameterized):
|
||||||
self.input_dim = int(input_dim)
|
self.input_dim = int(input_dim)
|
||||||
|
|
||||||
if active_dims is None:
|
if active_dims is None:
|
||||||
active_dims = np.arange(input_dim)
|
active_dims = np.arange(input_dim, dtype=np.int_)
|
||||||
|
|
||||||
self.active_dims = np.atleast_1d(np.asarray(active_dims, np.int_))
|
self.active_dims = np.atleast_1d(np.asarray(active_dims, np.int_))
|
||||||
|
|
||||||
self._all_dims_active = np.atleast_1d(self.active_dims).astype(int)
|
self._all_dims_active = np.atleast_1d(self.active_dims).astype(np.int_)
|
||||||
|
|
||||||
assert self.active_dims.size == self.input_dim, "input_dim={} does not match len(active_dim)={}".format(self.input_dim, self._all_dims_active.size)
|
assert self.active_dims.size == self.input_dim, "input_dim={} does not match len(active_dim)={}".format(self.input_dim, self._all_dims_active.size)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,6 @@ class StdPeriodic(Kern):
|
||||||
|
|
||||||
def __init__(self, input_dim, variance=1., period=None, lengthscale=None, ARD1=False, ARD2=False, active_dims=None, name='std_periodic',useGPU=False):
|
def __init__(self, input_dim, variance=1., period=None, lengthscale=None, ARD1=False, ARD2=False, active_dims=None, name='std_periodic',useGPU=False):
|
||||||
super(StdPeriodic, self).__init__(input_dim, active_dims, name, useGPU=useGPU)
|
super(StdPeriodic, self).__init__(input_dim, active_dims, name, useGPU=useGPU)
|
||||||
self.input_dim = input_dim
|
|
||||||
self.ARD1 = ARD1 # correspond to periods
|
self.ARD1 = ARD1 # correspond to periods
|
||||||
self.ARD2 = ARD2 # correspond to lengthscales
|
self.ARD2 = ARD2 # correspond to lengthscales
|
||||||
|
|
||||||
|
|
@ -66,7 +65,7 @@ class StdPeriodic(Kern):
|
||||||
period = np.asarray(period)
|
period = np.asarray(period)
|
||||||
assert period.size == 1, "Only one period needed for non-ARD kernel"
|
assert period.size == 1, "Only one period needed for non-ARD kernel"
|
||||||
else:
|
else:
|
||||||
period = np.ones(1.0)
|
period = np.ones(1)
|
||||||
else:
|
else:
|
||||||
if period is not None:
|
if period is not None:
|
||||||
period = np.asarray(period)
|
period = np.asarray(period)
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ class Stationary(Kern):
|
||||||
#X2, = self._slice_X(X2)
|
#X2, = self._slice_X(X2)
|
||||||
X1sq = np.sum(np.square(X),1)
|
X1sq = np.sum(np.square(X),1)
|
||||||
X2sq = np.sum(np.square(X2),1)
|
X2sq = np.sum(np.square(X2),1)
|
||||||
r2 = -2.*np.dot(X, X2.T) + X1sq[:,None] + X2sq[None,:]
|
r2 = -2.*np.dot(X, X2.T) + (X1sq[:,None] + X2sq[None,:])
|
||||||
r2 = np.clip(r2, 0, np.inf)
|
r2 = np.clip(r2, 0, np.inf)
|
||||||
return np.sqrt(r2)
|
return np.sqrt(r2)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,8 @@ class Binomial(Likelihood):
|
||||||
:rtype: float
|
:rtype: float
|
||||||
"""
|
"""
|
||||||
N = Y_metadata['trials']
|
N = Y_metadata['trials']
|
||||||
assert N.shape == y.shape
|
np.testing.assert_array_equal(N.shape, y.shape)
|
||||||
|
|
||||||
nchoosey = special.gammaln(N+1) - special.gammaln(y+1) - special.gammaln(N-y+1)
|
nchoosey = special.gammaln(N+1) - special.gammaln(y+1) - special.gammaln(N-y+1)
|
||||||
return nchoosey + y*np.log(inv_link_f) + (N-y)*np.log(1.-inv_link_f)
|
return nchoosey + y*np.log(inv_link_f) + (N-y)*np.log(1.-inv_link_f)
|
||||||
|
|
||||||
|
|
@ -83,7 +84,8 @@ class Binomial(Likelihood):
|
||||||
:rtype: Nx1 array
|
:rtype: Nx1 array
|
||||||
"""
|
"""
|
||||||
N = Y_metadata['trials']
|
N = Y_metadata['trials']
|
||||||
assert N.shape == y.shape
|
np.testing.assert_array_equal(N.shape, y.shape)
|
||||||
|
|
||||||
return y/inv_link_f - (N-y)/(1.-inv_link_f)
|
return y/inv_link_f - (N-y)/(1.-inv_link_f)
|
||||||
|
|
||||||
def d2logpdf_dlink2(self, inv_link_f, y, Y_metadata=None):
|
def d2logpdf_dlink2(self, inv_link_f, y, Y_metadata=None):
|
||||||
|
|
@ -108,7 +110,7 @@ class Binomial(Likelihood):
|
||||||
(the distribution for y_i depends only on inverse link of f_i not on inverse link of f_(j!=i)
|
(the distribution for y_i depends only on inverse link of f_i not on inverse link of f_(j!=i)
|
||||||
"""
|
"""
|
||||||
N = Y_metadata['trials']
|
N = Y_metadata['trials']
|
||||||
assert N.shape == y.shape
|
np.testing.assert_array_equal(N.shape, y.shape)
|
||||||
return -y/np.square(inv_link_f) - (N-y)/np.square(1.-inv_link_f)
|
return -y/np.square(inv_link_f) - (N-y)/np.square(1.-inv_link_f)
|
||||||
|
|
||||||
def d3logpdf_dlink3(self, inv_link_f, y, Y_metadata=None):
|
def d3logpdf_dlink3(self, inv_link_f, y, Y_metadata=None):
|
||||||
|
|
@ -131,7 +133,8 @@ class Binomial(Likelihood):
|
||||||
(the distribution for y_i depends only on inverse link of f_i not on inverse link of f_(j!=i)
|
(the distribution for y_i depends only on inverse link of f_i not on inverse link of f_(j!=i)
|
||||||
"""
|
"""
|
||||||
N = Y_metadata['trials']
|
N = Y_metadata['trials']
|
||||||
assert N.shape == y.shape
|
np.testing.assert_array_equal(N.shape, y.shape)
|
||||||
|
|
||||||
inv_link_f2 = np.square(inv_link_f)
|
inv_link_f2 = np.square(inv_link_f)
|
||||||
return 2*y/inv_link_f**3 - 2*(N-y)/(1.-inv_link_f)**3
|
return 2*y/inv_link_f**3 - 2*(N-y)/(1.-inv_link_f)**3
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ class SSGPLVM(SparseGP_MPI):
|
||||||
self.init = init
|
self.init = init
|
||||||
self.sharedX = sharedX
|
self.sharedX = sharedX
|
||||||
|
|
||||||
if X == None:
|
if X is None:
|
||||||
from ..util.initialization import initialize_latent
|
from ..util.initialization import initialize_latent
|
||||||
X, fracs = initialize_latent(init, input_dim, Y)
|
X, fracs = initialize_latent(init, input_dim, Y)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -293,13 +293,13 @@ class StateSpace(Model):
|
||||||
|
|
||||||
# Update step (only if there is data)
|
# Update step (only if there is data)
|
||||||
if not np.isnan(Y[:,k]):
|
if not np.isnan(Y[:,k]):
|
||||||
if Y.shape[0]==1:
|
if Y.shape[0]==1:
|
||||||
K = PF[:,:,k].dot(H.T)/(H.dot(PF[:,:,k]).dot(H.T) + R)
|
K = PF[:,:,k].dot(H.T)/(H.dot(PF[:,:,k]).dot(H.T) + R)
|
||||||
else:
|
else:
|
||||||
LL = linalg.cho_factor(H.dot(PF[:,:,k]).dot(H.T) + R)
|
LL = linalg.cho_factor(H.dot(PF[:,:,k]).dot(H.T) + R)
|
||||||
K = linalg.cho_solve(LL, H.dot(PF[:,:,k].T)).T
|
K = linalg.cho_solve(LL, H.dot(PF[:,:,k].T)).T
|
||||||
MF[:,k] += K.dot(Y[:,k]-H.dot(MF[:,k]))
|
MF[:,k] += K.dot(Y[:,k]-H.dot(MF[:,k]))
|
||||||
PF[:,:,k] -= K.dot(H).dot(PF[:,:,k])
|
PF[:,:,k] -= K.dot(H).dot(PF[:,:,k])
|
||||||
|
|
||||||
# Return values
|
# Return values
|
||||||
return (MF, PF)
|
return (MF, PF)
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ class R_handling_Python(Measurement_Callables_Class):
|
||||||
inv_R_square_root(k)
|
inv_R_square_root(k)
|
||||||
"""
|
"""
|
||||||
self.R = R
|
self.R = R
|
||||||
self.index = index
|
self.index = np.asarray(index, np.int_)
|
||||||
self.R_time_var_index = int(R_time_var_index)
|
self.R_time_var_index = int(R_time_var_index)
|
||||||
self.dR = dR
|
self.dR = dR
|
||||||
|
|
||||||
|
|
@ -350,7 +350,7 @@ class Q_handling_Python(Dynamic_Callables_Class):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.Q = Q
|
self.Q = Q
|
||||||
self.index = index
|
self.index = np.asarray(index, np.int_)
|
||||||
self.Q_time_var_index = Q_time_var_index
|
self.Q_time_var_index = Q_time_var_index
|
||||||
self.dQ = dQ
|
self.dQ = dQ
|
||||||
|
|
||||||
|
|
@ -427,7 +427,7 @@ class Std_Dynamic_Callables_Python(Q_handling_Class):
|
||||||
self).__init__(Q, index, Q_time_var_index, unique_Q_number, dQ)
|
self).__init__(Q, index, Q_time_var_index, unique_Q_number, dQ)
|
||||||
|
|
||||||
self.A = A
|
self.A = A
|
||||||
self.A_time_var_index = A_time_var_index
|
self.A_time_var_index = np.asarray(A_time_var_index, np.int_)
|
||||||
self.dA = dA
|
self.dA = dA
|
||||||
|
|
||||||
def f_a(self, k, m, A):
|
def f_a(self, k, m, A):
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||||
current_lib = [None]
|
current_lib = [None]
|
||||||
|
|
||||||
supported_libraries = ['matplotlib', 'plotly', 'none']
|
supported_libraries = ['matplotlib', 'plotly', 'plotly_online', 'plotly_offline', 'none']
|
||||||
error_suggestion = "Please make sure you specify your plotting library in your configuration file (<User>/.config/GPy/user.cfg).\n\n[plotting]\nlibrary = <library>\n\nCurrently supported libraries: {}".format(", ".join(supported_libraries))
|
error_suggestion = "Please make sure you specify your plotting library in your configuration file (<User>/.config/GPy/user.cfg).\n\n[plotting]\nlibrary = <library>\n\nCurrently supported libraries: {}".format(", ".join(supported_libraries))
|
||||||
|
|
||||||
def change_plotting_library(lib):
|
def change_plotting_library(lib, **kwargs):
|
||||||
try:
|
try:
|
||||||
#===========================================================================
|
#===========================================================================
|
||||||
# Load in your plotting library here and
|
# Load in your plotting library here and
|
||||||
|
|
@ -19,10 +19,14 @@ def change_plotting_library(lib):
|
||||||
from .matplot_dep.plot_definitions import MatplotlibPlots
|
from .matplot_dep.plot_definitions import MatplotlibPlots
|
||||||
from .matplot_dep import visualize, mapping_plots, priors_plots, ssgplvm, svig_plots, variational_plots, img_plots
|
from .matplot_dep import visualize, mapping_plots, priors_plots, ssgplvm, svig_plots, variational_plots, img_plots
|
||||||
current_lib[0] = MatplotlibPlots()
|
current_lib[0] = MatplotlibPlots()
|
||||||
if lib == 'plotly':
|
if lib in ['plotly', 'plotly_online']:
|
||||||
import plotly
|
import plotly
|
||||||
from .plotly_dep.plot_definitions import PlotlyPlots
|
from .plotly_dep.plot_definitions import PlotlyPlotsOnline
|
||||||
current_lib[0] = PlotlyPlots()
|
current_lib[0] = PlotlyPlotsOnline(**kwargs)
|
||||||
|
if lib == 'plotly_offline':
|
||||||
|
import plotly
|
||||||
|
from .plotly_dep.plot_definitions import PlotlyPlotsOffline
|
||||||
|
current_lib[0] = PlotlyPlotsOffline(**kwargs)
|
||||||
if lib == 'none':
|
if lib == 'none':
|
||||||
current_lib[0] = None
|
current_lib[0] = None
|
||||||
inject_plotting()
|
inject_plotting()
|
||||||
|
|
|
||||||
|
|
@ -88,12 +88,12 @@ def _plot_mean(self, canvas, helper_data, helper_prediction,
|
||||||
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_1d) # @UndefinedVariable
|
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_1d) # @UndefinedVariable
|
||||||
plots = dict(gpmean=[pl().plot(canvas, Xgrid[:, free_dims], mu, label=label, **kwargs)])
|
plots = dict(gpmean=[pl().plot(canvas, Xgrid[:, free_dims], mu, label=label, **kwargs)])
|
||||||
else:
|
else:
|
||||||
if projection == '2d':
|
if projection.lower() in '2d':
|
||||||
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_2d) # @UndefinedVariable
|
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_2d) # @UndefinedVariable
|
||||||
plots = dict(gpmean=[pl().contour(canvas, x[:,0], y[0,:],
|
plots = dict(gpmean=[pl().contour(canvas, x[:,0], y[0,:],
|
||||||
mu.reshape(resolution, resolution).T,
|
mu.reshape(resolution, resolution).T,
|
||||||
levels=levels, label=label, **kwargs)])
|
levels=levels, label=label, **kwargs)])
|
||||||
elif projection == '3d':
|
elif projection.lower() in '3d':
|
||||||
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_3d) # @UndefinedVariable
|
update_not_existing_kwargs(kwargs, pl().defaults.meanplot_3d) # @UndefinedVariable
|
||||||
plots = dict(gpmean=[pl().surface(canvas, x, y,
|
plots = dict(gpmean=[pl().surface(canvas, x, y,
|
||||||
mu.reshape(resolution, resolution),
|
mu.reshape(resolution, resolution),
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ class MatplotlibPlots(AbstractPlottingLibrary):
|
||||||
if title is not None: ax.figure.suptitle(title)
|
if title is not None: ax.figure.suptitle(title)
|
||||||
return ax
|
return ax
|
||||||
|
|
||||||
def show_canvas(self, ax):
|
def show_canvas(self, ax, **kwargs):
|
||||||
ax.figure.canvas.draw()
|
ax.figure.canvas.draw()
|
||||||
return ax.figure
|
return ax.figure
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ import numpy as np
|
||||||
from ..abstract_plotting_library import AbstractPlottingLibrary
|
from ..abstract_plotting_library import AbstractPlottingLibrary
|
||||||
from .. import Tango
|
from .. import Tango
|
||||||
from . import defaults
|
from . import defaults
|
||||||
|
import plotly
|
||||||
from plotly import tools
|
from plotly import tools
|
||||||
from plotly import plotly as py
|
|
||||||
from plotly.graph_objs import Scatter, Scatter3d, Line,\
|
from plotly.graph_objs import Scatter, Scatter3d, Line,\
|
||||||
Marker, ErrorX, ErrorY, Bar, Heatmap, Trace,\
|
Marker, ErrorX, ErrorY, Bar, Heatmap, Trace,\
|
||||||
Annotations, Annotation, Contour, Font, Surface
|
Annotations, Annotation, Contour, Font, Surface
|
||||||
|
|
@ -52,9 +52,9 @@ SYMBOL_MAP = {
|
||||||
'd': 'diamond',
|
'd': 'diamond',
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlotlyPlots(AbstractPlottingLibrary):
|
class PlotlyPlotsBase(AbstractPlottingLibrary):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(PlotlyPlots, self).__init__()
|
super(PlotlyPlotsBase, self).__init__()
|
||||||
self._defaults = defaults.__dict__
|
self._defaults = defaults.__dict__
|
||||||
self.current_states = dict()
|
self.current_states = dict()
|
||||||
|
|
||||||
|
|
@ -96,7 +96,10 @@ class PlotlyPlots(AbstractPlottingLibrary):
|
||||||
xref, yref = figure._grid_ref[row-1][col-1]
|
xref, yref = figure._grid_ref[row-1][col-1]
|
||||||
for a in traces:
|
for a in traces:
|
||||||
append_annotation(a, xref, yref)
|
append_annotation(a, xref, yref)
|
||||||
elif isinstance(traces, (Trace)):
|
# elif isinstance(traces, (Trace)): # doesn't work
|
||||||
|
# elif type(traces) in [v for k,v in go.__dict__.iteritems()]:
|
||||||
|
elif isinstance(traces, (Scatter, Scatter3d, ErrorX,
|
||||||
|
ErrorY, Bar, Heatmap, Trace, Contour, Surface)):
|
||||||
try:
|
try:
|
||||||
append_trace(traces, row, col)
|
append_trace(traces, row, col)
|
||||||
except PlotlyDictKeyError:
|
except PlotlyDictKeyError:
|
||||||
|
|
@ -114,15 +117,7 @@ class PlotlyPlots(AbstractPlottingLibrary):
|
||||||
return canvas
|
return canvas
|
||||||
|
|
||||||
def show_canvas(self, canvas, filename=None, **kwargs):
|
def show_canvas(self, canvas, filename=None, **kwargs):
|
||||||
figure, _, _ = canvas
|
return NotImplementedError
|
||||||
if len(figure.data) == 0:
|
|
||||||
# add mock data
|
|
||||||
figure.append_trace(Scatter(x=[], y=[], name='', showlegend=False), 1, 1)
|
|
||||||
from ..gpy_plot.plot_util import in_ipynb
|
|
||||||
if in_ipynb():
|
|
||||||
return py.iplot(figure, filename=filename)#self.current_states[hex(id(figure))]['filename'])
|
|
||||||
else:
|
|
||||||
return py.plot(figure, filename=filename)#self.current_states[hex(id(figure))]['filename'])
|
|
||||||
|
|
||||||
def scatter(self, ax, X, Y, Z=None, color=Tango.colorsHex['mediumBlue'], cmap=None, label=None, marker='o', marker_kwargs=None, **kwargs):
|
def scatter(self, ax, X, Y, Z=None, color=Tango.colorsHex['mediumBlue'], cmap=None, label=None, marker='o', marker_kwargs=None, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
|
@ -133,7 +128,9 @@ class PlotlyPlots(AbstractPlottingLibrary):
|
||||||
marker_kwargs = marker_kwargs or {}
|
marker_kwargs = marker_kwargs or {}
|
||||||
if 'symbol' not in marker_kwargs:
|
if 'symbol' not in marker_kwargs:
|
||||||
marker_kwargs['symbol'] = marker
|
marker_kwargs['symbol'] = marker
|
||||||
|
X, Y = np.squeeze(X), np.squeeze(Y)
|
||||||
if Z is not None:
|
if Z is not None:
|
||||||
|
Z = np.squeeze(Z)
|
||||||
return Scatter3d(x=X, y=Y, z=Z, mode='markers',
|
return Scatter3d(x=X, y=Y, z=Z, mode='markers',
|
||||||
showlegend=label is not None,
|
showlegend=label is not None,
|
||||||
marker=Marker(color=color, colorscale=cmap, **marker_kwargs),
|
marker=Marker(color=color, colorscale=cmap, **marker_kwargs),
|
||||||
|
|
@ -145,7 +142,9 @@ class PlotlyPlots(AbstractPlottingLibrary):
|
||||||
def plot(self, ax, X, Y, Z=None, color=None, label=None, line_kwargs=None, **kwargs):
|
def plot(self, ax, X, Y, Z=None, color=None, label=None, line_kwargs=None, **kwargs):
|
||||||
if 'mode' not in kwargs:
|
if 'mode' not in kwargs:
|
||||||
kwargs['mode'] = 'lines'
|
kwargs['mode'] = 'lines'
|
||||||
|
X, Y = np.squeeze(X), np.squeeze(Y)
|
||||||
if Z is not None:
|
if Z is not None:
|
||||||
|
Z = np.squeeze(Z)
|
||||||
return Scatter3d(x=X, y=Y, z=Z, showlegend=label is not None, line=Line(color=color, **line_kwargs or {}), name=label, **kwargs)
|
return Scatter3d(x=X, y=Y, z=Z, showlegend=label is not None, line=Line(color=color, **line_kwargs or {}), name=label, **kwargs)
|
||||||
return Scatter(x=X, y=Y, showlegend=label is not None, line=Line(color=color, **line_kwargs or {}), name=label, **kwargs)
|
return Scatter(x=X, y=Y, showlegend=label is not None, line=Line(color=color, **line_kwargs or {}), name=label, **kwargs)
|
||||||
|
|
||||||
|
|
@ -191,7 +190,9 @@ class PlotlyPlots(AbstractPlottingLibrary):
|
||||||
error_kwargs.update(dict(array=error[1], arrayminus=error[0], symmetric=False))
|
error_kwargs.update(dict(array=error[1], arrayminus=error[0], symmetric=False))
|
||||||
else:
|
else:
|
||||||
error_kwargs.update(dict(array=error, symmetric=True))
|
error_kwargs.update(dict(array=error, symmetric=True))
|
||||||
|
X, Y = np.squeeze(X), np.squeeze(Y)
|
||||||
if Z is not None:
|
if Z is not None:
|
||||||
|
Z = np.squeeze(Z)
|
||||||
return Scatter3d(x=X, y=Y, z=Z, mode='markers',
|
return Scatter3d(x=X, y=Y, z=Z, mode='markers',
|
||||||
error_x=ErrorX(color=color, **error_kwargs or {}),
|
error_x=ErrorX(color=color, **error_kwargs or {}),
|
||||||
marker=Marker(size='0'), name=label,
|
marker=Marker(size='0'), name=label,
|
||||||
|
|
@ -208,7 +209,9 @@ class PlotlyPlots(AbstractPlottingLibrary):
|
||||||
error_kwargs.update(dict(array=error[1], arrayminus=error[0], symmetric=False))
|
error_kwargs.update(dict(array=error[1], arrayminus=error[0], symmetric=False))
|
||||||
else:
|
else:
|
||||||
error_kwargs.update(dict(array=error, symmetric=True))
|
error_kwargs.update(dict(array=error, symmetric=True))
|
||||||
|
X, Y = np.squeeze(X), np.squeeze(Y)
|
||||||
if Z is not None:
|
if Z is not None:
|
||||||
|
Z = np.squeeze(Z)
|
||||||
return Scatter3d(x=X, y=Y, z=Z, mode='markers',
|
return Scatter3d(x=X, y=Y, z=Z, mode='markers',
|
||||||
error_y=ErrorY(color=color, **error_kwargs or {}),
|
error_y=ErrorY(color=color, **error_kwargs or {}),
|
||||||
marker=Marker(size='0'), name=label,
|
marker=Marker(size='0'), name=label,
|
||||||
|
|
@ -232,7 +235,7 @@ class PlotlyPlots(AbstractPlottingLibrary):
|
||||||
|
|
||||||
def imshow_interact(self, ax, plot_function, extent=None, label=None, resolution=None, vmin=None, vmax=None, **imshow_kwargs):
|
def imshow_interact(self, ax, plot_function, extent=None, label=None, resolution=None, vmin=None, vmax=None, **imshow_kwargs):
|
||||||
# TODO stream interaction?
|
# TODO stream interaction?
|
||||||
super(PlotlyPlots, self).imshow_interact(ax, plot_function)
|
super(PlotlyPlotsBase, self).imshow_interact(ax, plot_function)
|
||||||
|
|
||||||
def annotation_heatmap(self, ax, X, annotation, extent=None, label='Gradient', imshow_kwargs=None, **annotation_kwargs):
|
def annotation_heatmap(self, ax, X, annotation, extent=None, label='Gradient', imshow_kwargs=None, **annotation_kwargs):
|
||||||
imshow_kwargs.setdefault('label', label)
|
imshow_kwargs.setdefault('label', label)
|
||||||
|
|
@ -259,7 +262,7 @@ class PlotlyPlots(AbstractPlottingLibrary):
|
||||||
return imshow, annotations
|
return imshow, annotations
|
||||||
|
|
||||||
def annotation_heatmap_interact(self, ax, plot_function, extent, label=None, resolution=15, imshow_kwargs=None, **annotation_kwargs):
|
def annotation_heatmap_interact(self, ax, plot_function, extent, label=None, resolution=15, imshow_kwargs=None, **annotation_kwargs):
|
||||||
super(PlotlyPlots, self).annotation_heatmap_interact(ax, plot_function, extent)
|
super(PlotlyPlotsBase, self).annotation_heatmap_interact(ax, plot_function, extent)
|
||||||
|
|
||||||
def contour(self, ax, X, Y, C, levels=20, label=None, **kwargs):
|
def contour(self, ax, X, Y, C, levels=20, label=None, **kwargs):
|
||||||
return Contour(x=X, y=Y, z=C,
|
return Contour(x=X, y=Y, z=C,
|
||||||
|
|
@ -312,3 +315,35 @@ class PlotlyPlots(AbstractPlottingLibrary):
|
||||||
name=None, line=Line(width=1, smoothing=0, color=fcolor), mode='none', fill='tonextx',
|
name=None, line=Line(width=1, smoothing=0, color=fcolor), mode='none', fill='tonextx',
|
||||||
legendgroup='density', hoverinfo='none', **kwargs))
|
legendgroup='density', hoverinfo='none', **kwargs))
|
||||||
return polycol
|
return polycol
|
||||||
|
|
||||||
|
|
||||||
|
class PlotlyPlotsOnline(PlotlyPlotsBase):
|
||||||
|
def __init__(self):
|
||||||
|
super(PlotlyPlotsOnline, self).__init__()
|
||||||
|
|
||||||
|
def show_canvas(self, canvas, filename=None, **kwargs):
|
||||||
|
figure, _, _ = canvas
|
||||||
|
if len(figure.data) == 0:
|
||||||
|
# add mock data
|
||||||
|
figure.append_trace(Scatter(x=[], y=[], name='', showlegend=False), 1, 1)
|
||||||
|
from ..gpy_plot.plot_util import in_ipynb
|
||||||
|
if in_ipynb():
|
||||||
|
return plotly.plotly.iplot(figure, filename=filename, **kwargs)
|
||||||
|
else:
|
||||||
|
return plotly.plotly.plot(figure, filename=filename, **kwargs)#self.current_states[hex(id(figure))]['filename'])
|
||||||
|
|
||||||
|
class PlotlyPlotsOffline(PlotlyPlotsBase):
|
||||||
|
def __init__(self):
|
||||||
|
super(PlotlyPlotsOffline, self).__init__()
|
||||||
|
|
||||||
|
def show_canvas(self, canvas, filename=None, **kwargs):
|
||||||
|
figure, _, _ = canvas
|
||||||
|
if len(figure.data) == 0:
|
||||||
|
# add mock data
|
||||||
|
figure.append_trace(Scatter(x=[], y=[], name='', showlegend=False), 1, 1)
|
||||||
|
from ..gpy_plot.plot_util import in_ipynb
|
||||||
|
if in_ipynb():
|
||||||
|
plotly.offline.init_notebook_mode(connected=True)
|
||||||
|
return plotly.offline.iplot(figure, filename=filename, **kwargs)#self.current_states[hex(id(figure))]['filename'])
|
||||||
|
else:
|
||||||
|
return plotly.offline.plot(figure, filename=filename, **kwargs)
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -421,6 +421,21 @@ class KernelGradientTestsContinuous(unittest.TestCase):
|
||||||
k.randomize()
|
k.randomize()
|
||||||
self.assertTrue(check_kernel_gradient_functions(k, X=self.X, X2=self.X2, verbose=verbose))
|
self.assertTrue(check_kernel_gradient_functions(k, X=self.X, X2=self.X2, verbose=verbose))
|
||||||
|
|
||||||
|
def test_OU(self):
|
||||||
|
k = GPy.kern.OU(self.D-1, ARD=True)
|
||||||
|
k.randomize()
|
||||||
|
self.assertTrue(check_kernel_gradient_functions(k, X=self.X, X2=self.X2, verbose=verbose))
|
||||||
|
|
||||||
|
def test_RatQuad(self):
|
||||||
|
k = GPy.kern.RatQuad(self.D-1, ARD=True)
|
||||||
|
k.randomize()
|
||||||
|
self.assertTrue(check_kernel_gradient_functions(k, X=self.X, X2=self.X2, verbose=verbose))
|
||||||
|
|
||||||
|
def test_ExpQuad(self):
|
||||||
|
k = GPy.kern.ExpQuad(self.D-1, ARD=True)
|
||||||
|
k.randomize()
|
||||||
|
self.assertTrue(check_kernel_gradient_functions(k, X=self.X, X2=self.X2, verbose=verbose))
|
||||||
|
|
||||||
def test_integral(self):
|
def test_integral(self):
|
||||||
k = GPy.kern.Integral(1)
|
k = GPy.kern.Integral(1)
|
||||||
k.randomize()
|
k.randomize()
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ class TestNoiseModels(object):
|
||||||
self.integer_Y = np.where(tmp > 0, tmp, 0)
|
self.integer_Y = np.where(tmp > 0, tmp, 0)
|
||||||
self.ns = np.random.poisson(50, size=self.N)[:, None]
|
self.ns = np.random.poisson(50, size=self.N)[:, None]
|
||||||
p = np.abs(np.cos(2*np.pi*self.X + np.random.normal(scale=.2, size=(self.N, self.D)))).mean(1)
|
p = np.abs(np.cos(2*np.pi*self.X + np.random.normal(scale=.2, size=(self.N, self.D)))).mean(1)
|
||||||
self.binomial_Y = np.array([np.random.binomial(self.ns[i], p[i]) for i in range(p.shape[0])])[:, None]
|
self.binomial_Y = np.array([np.random.binomial(int(self.ns[i]), p[i]) for i in range(p.shape[0])])[:, None]
|
||||||
|
|
||||||
self.var = 0.2
|
self.var = 0.2
|
||||||
self.deg_free = 4.0
|
self.deg_free = 4.0
|
||||||
|
|
@ -570,7 +570,6 @@ class TestNoiseModels(object):
|
||||||
white_var = 1e-4
|
white_var = 1e-4
|
||||||
kernel = GPy.kern.RBF(X.shape[1]) + GPy.kern.White(X.shape[1])
|
kernel = GPy.kern.RBF(X.shape[1]) + GPy.kern.White(X.shape[1])
|
||||||
laplace_likelihood = GPy.inference.latent_function_inference.Laplace()
|
laplace_likelihood = GPy.inference.latent_function_inference.Laplace()
|
||||||
|
|
||||||
m = GPy.core.GP(X.copy(), Y.copy(), kernel, likelihood=model, Y_metadata=Y_metadata, inference_method=laplace_likelihood)
|
m = GPy.core.GP(X.copy(), Y.copy(), kernel, likelihood=model, Y_metadata=Y_metadata, inference_method=laplace_likelihood)
|
||||||
m.kern.white.constrain_fixed(white_var)
|
m.kern.white.constrain_fixed(white_var)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (c) 2012, GPy authors (see AUTHORS.txt).
|
# Copyright (c) 2012, GPy authors (see AUTHORS.txt).
|
||||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
@ -54,7 +54,7 @@ class MiscTests(unittest.TestCase):
|
||||||
m.randomize()
|
m.randomize()
|
||||||
m.optimize()
|
m.optimize()
|
||||||
# Compute the mean of model prediction on 1e5 Monte Carlo samples
|
# Compute the mean of model prediction on 1e5 Monte Carlo samples
|
||||||
Xp = np.random.uniform(size=(1e5,2))
|
Xp = np.random.uniform(size=(int(1e5),2))
|
||||||
Xp[:,0] = Xp[:,0]*15-5
|
Xp[:,0] = Xp[:,0]*15-5
|
||||||
Xp[:,1] = Xp[:,1]*15
|
Xp[:,1] = Xp[:,1]*15
|
||||||
_, var = m.predict(Xp)
|
_, var = m.predict(Xp)
|
||||||
|
|
@ -759,16 +759,18 @@ class GradientTests(np.testing.TestCase):
|
||||||
|
|
||||||
def test_GP_EP_probit(self):
|
def test_GP_EP_probit(self):
|
||||||
N = 20
|
N = 20
|
||||||
X = np.hstack([np.random.normal(5, 2, N / 2), np.random.normal(10, 2, N / 2)])[:, None]
|
Nhalf = int(N/2)
|
||||||
Y = np.hstack([np.ones(N / 2), np.zeros(N / 2)])[:, None]
|
X = np.hstack([np.random.normal(5, 2, Nhalf), np.random.normal(10, 2, Nhalf)])[:, None]
|
||||||
|
Y = np.hstack([np.ones(Nhalf), np.zeros(Nhalf)])[:, None]
|
||||||
kernel = GPy.kern.RBF(1)
|
kernel = GPy.kern.RBF(1)
|
||||||
m = GPy.models.GPClassification(X, Y, kernel=kernel)
|
m = GPy.models.GPClassification(X, Y, kernel=kernel)
|
||||||
self.assertTrue(m.checkgrad())
|
self.assertTrue(m.checkgrad())
|
||||||
|
|
||||||
def test_sparse_EP_DTC_probit(self):
|
def test_sparse_EP_DTC_probit(self):
|
||||||
N = 20
|
N = 20
|
||||||
X = np.hstack([np.random.normal(5, 2, N / 2), np.random.normal(10, 2, N / 2)])[:, None]
|
Nhalf = int(N/2)
|
||||||
Y = np.hstack([np.ones(N / 2), np.zeros(N / 2)])[:, None]
|
X = np.hstack([np.random.normal(5, 2, Nhalf), np.random.normal(10, 2, Nhalf)])[:, None]
|
||||||
|
Y = np.hstack([np.ones(Nhalf), np.zeros(Nhalf)])[:, None]
|
||||||
Z = np.linspace(0, 15, 4)[:, None]
|
Z = np.linspace(0, 15, 4)[:, None]
|
||||||
kernel = GPy.kern.RBF(1)
|
kernel = GPy.kern.RBF(1)
|
||||||
m = GPy.models.SparseGPClassification(X, Y, kernel=kernel, Z=Z)
|
m = GPy.models.SparseGPClassification(X, Y, kernel=kernel, Z=Z)
|
||||||
|
|
@ -776,8 +778,9 @@ class GradientTests(np.testing.TestCase):
|
||||||
|
|
||||||
def test_sparse_EP_DTC_probit_uncertain_inputs(self):
|
def test_sparse_EP_DTC_probit_uncertain_inputs(self):
|
||||||
N = 20
|
N = 20
|
||||||
X = np.hstack([np.random.normal(5, 2, N / 2), np.random.normal(10, 2, N / 2)])[:, None]
|
Nhalf = int(N/2)
|
||||||
Y = np.hstack([np.ones(N / 2), np.zeros(N / 2)])[:, None]
|
X = np.hstack([np.random.normal(5, 2, Nhalf), np.random.normal(10, 2, Nhalf)])[:, None]
|
||||||
|
Y = np.hstack([np.ones(Nhalf), np.zeros(Nhalf)])[:, None]
|
||||||
Z = np.linspace(0, 15, 4)[:, None]
|
Z = np.linspace(0, 15, 4)[:, None]
|
||||||
X_var = np.random.uniform(0.1, 0.2, X.shape)
|
X_var = np.random.uniform(0.1, 0.2, X.shape)
|
||||||
kernel = GPy.kern.RBF(1)
|
kernel = GPy.kern.RBF(1)
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ def test_figure():
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter("ignore")
|
warnings.simplefilter("ignore")
|
||||||
|
|
||||||
ax, _ = pl().new_canvas(num=1)
|
ax, _ = pl().new_canvas(num="imshow_interact")
|
||||||
def test_func(x):
|
def test_func(x):
|
||||||
return x[:, 0].reshape(3,3)
|
return x[:, 0].reshape(3,3)
|
||||||
pl().imshow_interact(ax, test_func, extent=(-1,1,-1,1), resolution=3)
|
pl().imshow_interact(ax, test_func, extent=(-1,1,-1,1), resolution=3)
|
||||||
|
|
@ -228,7 +228,7 @@ def test_figure():
|
||||||
|
|
||||||
pl().fill_gradient(ax, x, y, facecolors=['r', 'g'], array=array, cmap=cmap)
|
pl().fill_gradient(ax, x, y, facecolors=['r', 'g'], array=array, cmap=cmap)
|
||||||
|
|
||||||
ax, _ = pl().new_canvas(num=4, figsize=(4,3), projection='3d', xlabel='x', ylabel='y', zlabel='z', title='awsome title', xlim=(-1,1), ylim=(-1,1), zlim=(-3,3))
|
ax, _ = pl().new_canvas(num="3d_plot", figsize=(4,3), projection='3d', xlabel='x', ylabel='y', zlabel='z', title='awsome title', xlim=(-1,1), ylim=(-1,1), zlim=(-3,3))
|
||||||
z = 2-np.abs(np.linspace(-2,2,(100)))+1
|
z = 2-np.abs(np.linspace(-2,2,(100)))+1
|
||||||
x, y = z*np.sin(np.linspace(-2*np.pi,2*np.pi,(100))), z*np.cos(np.linspace(-np.pi,np.pi,(100)))
|
x, y = z*np.sin(np.linspace(-2*np.pi,2*np.pi,(100))), z*np.cos(np.linspace(-np.pi,np.pi,(100)))
|
||||||
|
|
||||||
|
|
|
||||||
63
GPy/testing/variational_tests.py
Normal file
63
GPy/testing/variational_tests.py
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
'''
|
||||||
|
Copyright (c) 2015, Max Zwiessele
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of paramax nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
'''
|
||||||
|
import unittest
|
||||||
|
import GPy, numpy as np
|
||||||
|
|
||||||
|
class KLGrad(GPy.core.Model):
|
||||||
|
def __init__(self, Xvar, kl):
|
||||||
|
super(KLGrad, self).__init__(name="klgrad")
|
||||||
|
self.kl = kl
|
||||||
|
self.link_parameter(Xvar)
|
||||||
|
self.Xvar = Xvar
|
||||||
|
self._obj = 0
|
||||||
|
def parameters_changed(self):
|
||||||
|
self.Xvar.gradient[:] = 0
|
||||||
|
self.kl.update_gradients_KL(self.Xvar)
|
||||||
|
self._obj = self.kl.KL_divergence(self.Xvar)
|
||||||
|
def objective_function(self):
|
||||||
|
return self._obj
|
||||||
|
|
||||||
|
class Test(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
np.random.seed(12345)
|
||||||
|
self.Xvar = GPy.core.parameterization.variational.NormalPosterior(
|
||||||
|
np.random.uniform(0,1,(10,3)),
|
||||||
|
np.random.uniform(1e-5,.01, (10,3))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def testNormal(self):
|
||||||
|
klgrad = KLGrad(self.Xvar, GPy.core.parameterization.variational.NormalPrior())
|
||||||
|
np.testing.assert_(klgrad.checkgrad())
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
#import sys;sys.argv = ['', 'Test.testNormal']
|
||||||
|
unittest.main()
|
||||||
|
|
@ -13,7 +13,6 @@ except ImportError:
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
from configparser import NoOptionError
|
from configparser import NoOptionError
|
||||||
|
|
||||||
|
|
||||||
# This is the default configuration file that always needs to be present.
|
# This is the default configuration file that always needs to be present.
|
||||||
default_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'defaults.cfg'))
|
default_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'defaults.cfg'))
|
||||||
|
|
||||||
|
|
@ -22,7 +21,7 @@ default_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', '
|
||||||
local_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'installation.cfg'))
|
local_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'installation.cfg'))
|
||||||
|
|
||||||
# This specifies configurations specific to the user (it is found in the user home directory)
|
# This specifies configurations specific to the user (it is found in the user home directory)
|
||||||
home = os.getenv('HOME') or os.getenv('USERPROFILE')
|
home = os.getenv('HOME') or os.getenv('USERPROFILE') or ''
|
||||||
user_file = os.path.join(home,'.config','GPy', 'user.cfg')
|
user_file = os.path.join(home,'.config','GPy', 'user.cfg')
|
||||||
|
|
||||||
# Read in the given files.
|
# Read in the given files.
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ environment:
|
||||||
secure: 8/ZjXFwtd1S7ixd7PJOpptupKKEDhm2da/q3unabJ00=
|
secure: 8/ZjXFwtd1S7ixd7PJOpptupKKEDhm2da/q3unabJ00=
|
||||||
COVERALLS_REPO_TOKEN:
|
COVERALLS_REPO_TOKEN:
|
||||||
secure: d3Luic/ESkGaWnZrvWZTKrzO+xaVwJWaRCEP0F+K/9DQGPSRZsJ/Du5g3s4XF+tS
|
secure: d3Luic/ESkGaWnZrvWZTKrzO+xaVwJWaRCEP0F+K/9DQGPSRZsJ/Du5g3s4XF+tS
|
||||||
gpy_version: 1.5.6
|
gpy_version: 1.6.1
|
||||||
matrix:
|
matrix:
|
||||||
- PYTHON_VERSION: 2.7
|
- PYTHON_VERSION: 2.7
|
||||||
MINICONDA: C:\Miniconda-x64
|
MINICONDA: C:\Miniconda-x64
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 1.5.6
|
current_version = 1.6.1
|
||||||
tag = True
|
tag = True
|
||||||
commit = True
|
commit = True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue