mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-08 11:32:39 +02:00
Fixed an import
This commit is contained in:
commit
70189a387b
33 changed files with 100 additions and 77 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -9,7 +9,6 @@
|
||||||
dist
|
dist
|
||||||
build
|
build
|
||||||
eggs
|
eggs
|
||||||
parts
|
|
||||||
bin
|
bin
|
||||||
var
|
var
|
||||||
sdist
|
sdist
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
# 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 constructors import *
|
||||||
from constructors import rbf, Matern32, Matern52, exponential, linear, white, bias, finite_dimensional, spline, Brownian, periodic_exponential, periodic_Matern32, periodic_Matern52, prod, symmetric, Coregionalise, rational_quadratic, Fixed, rbfcos, IndependentOutputs
|
|
||||||
try:
|
try:
|
||||||
from constructors import rbf_sympy, sympykern # these depend on sympy
|
from constructors import rbf_sympy, sympykern # these depend on sympy
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,9 @@
|
||||||
# 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)
|
||||||
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from kern import kern
|
from kern import kern
|
||||||
|
import parts
|
||||||
from rbf import rbf as rbfpart
|
|
||||||
from white import white as whitepart
|
|
||||||
from linear import linear as linearpart
|
|
||||||
from exponential import exponential as exponentialpart
|
|
||||||
from Matern32 import Matern32 as Matern32part
|
|
||||||
from Matern52 import Matern52 as Matern52part
|
|
||||||
from bias import bias as biaspart
|
|
||||||
from fixed import Fixed as fixedpart
|
|
||||||
from finite_dimensional import finite_dimensional as finite_dimensionalpart
|
|
||||||
from spline import spline as splinepart
|
|
||||||
from Brownian import Brownian as Brownianpart
|
|
||||||
from periodic_exponential import periodic_exponential as periodic_exponentialpart
|
|
||||||
from periodic_Matern32 import periodic_Matern32 as periodic_Matern32part
|
|
||||||
from periodic_Matern52 import periodic_Matern52 as periodic_Matern52part
|
|
||||||
from prod import prod as prodpart
|
|
||||||
from symmetric import symmetric as symmetric_part
|
|
||||||
from coregionalise import Coregionalise as coregionalise_part
|
|
||||||
from rational_quadratic import rational_quadratic as rational_quadraticpart
|
|
||||||
from rbfcos import rbfcos as rbfcospart
|
|
||||||
from independent_outputs import IndependentOutputs as independent_output_part
|
|
||||||
#TODO these s=constructors are not as clean as we'd like. Tidy the code up
|
|
||||||
#using meta-classes to make the objects construct properly wthout them.
|
|
||||||
|
|
||||||
|
|
||||||
def rbf(input_dim,variance=1., lengthscale=None,ARD=False):
|
def rbf(input_dim,variance=1., lengthscale=None,ARD=False):
|
||||||
"""
|
"""
|
||||||
|
|
@ -42,7 +18,7 @@ def rbf(input_dim,variance=1., lengthscale=None,ARD=False):
|
||||||
:param ARD: Auto Relevance Determination (one lengthscale per dimension)
|
:param ARD: Auto Relevance Determination (one lengthscale per dimension)
|
||||||
:type ARD: Boolean
|
:type ARD: Boolean
|
||||||
"""
|
"""
|
||||||
part = rbfpart(input_dim,variance,lengthscale,ARD)
|
part = parts.rbf.RBF(input_dim,variance,lengthscale,ARD)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def linear(input_dim,variances=None,ARD=False):
|
def linear(input_dim,variances=None,ARD=False):
|
||||||
|
|
@ -55,7 +31,7 @@ def linear(input_dim,variances=None,ARD=False):
|
||||||
variances (np.ndarray)
|
variances (np.ndarray)
|
||||||
ARD (boolean)
|
ARD (boolean)
|
||||||
"""
|
"""
|
||||||
part = linearpart(input_dim,variances,ARD)
|
part = parts.linear.Linear(input_dim,variances,ARD)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def white(input_dim,variance=1.):
|
def white(input_dim,variance=1.):
|
||||||
|
|
@ -67,7 +43,7 @@ def white(input_dim,variance=1.):
|
||||||
input_dimD (int), obligatory
|
input_dimD (int), obligatory
|
||||||
variance (float)
|
variance (float)
|
||||||
"""
|
"""
|
||||||
part = whitepart(input_dim,variance)
|
part = parts.white.White(input_dim,variance)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def exponential(input_dim,variance=1., lengthscale=None, ARD=False):
|
def exponential(input_dim,variance=1., lengthscale=None, ARD=False):
|
||||||
|
|
@ -83,7 +59,7 @@ def exponential(input_dim,variance=1., lengthscale=None, ARD=False):
|
||||||
:param ARD: Auto Relevance Determination (one lengthscale per dimension)
|
:param ARD: Auto Relevance Determination (one lengthscale per dimension)
|
||||||
:type ARD: Boolean
|
:type ARD: Boolean
|
||||||
"""
|
"""
|
||||||
part = exponentialpart(input_dim,variance, lengthscale, ARD)
|
part = parts.exponential.Exponential(input_dim,variance, lengthscale, ARD)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def Matern32(input_dim,variance=1., lengthscale=None, ARD=False):
|
def Matern32(input_dim,variance=1., lengthscale=None, ARD=False):
|
||||||
|
|
@ -99,7 +75,7 @@ def Matern32(input_dim,variance=1., lengthscale=None, ARD=False):
|
||||||
:param ARD: Auto Relevance Determination (one lengthscale per dimension)
|
:param ARD: Auto Relevance Determination (one lengthscale per dimension)
|
||||||
:type ARD: Boolean
|
:type ARD: Boolean
|
||||||
"""
|
"""
|
||||||
part = Matern32part(input_dim,variance, lengthscale, ARD)
|
part = parts.Matern32.Matern32(input_dim,variance, lengthscale, ARD)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def Matern52(input_dim, variance=1., lengthscale=None, ARD=False):
|
def Matern52(input_dim, variance=1., lengthscale=None, ARD=False):
|
||||||
|
|
@ -115,7 +91,7 @@ def Matern52(input_dim, variance=1., lengthscale=None, ARD=False):
|
||||||
:param ARD: Auto Relevance Determination (one lengthscale per dimension)
|
:param ARD: Auto Relevance Determination (one lengthscale per dimension)
|
||||||
:type ARD: Boolean
|
:type ARD: Boolean
|
||||||
"""
|
"""
|
||||||
part = Matern52part(input_dim, variance, lengthscale, ARD)
|
part = parts.Matern52.Matern52(input_dim, variance, lengthscale, ARD)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def bias(input_dim, variance=1.):
|
def bias(input_dim, variance=1.):
|
||||||
|
|
@ -127,7 +103,7 @@ def bias(input_dim, variance=1.):
|
||||||
input_dim (int), obligatory
|
input_dim (int), obligatory
|
||||||
variance (float)
|
variance (float)
|
||||||
"""
|
"""
|
||||||
part = biaspart(input_dim, variance)
|
part = parts.bias.Bias(input_dim, variance)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def finite_dimensional(input_dim, F, G, variances=1., weights=None):
|
def finite_dimensional(input_dim, F, G, variances=1., weights=None):
|
||||||
|
|
@ -138,7 +114,7 @@ def finite_dimensional(input_dim, F, G, variances=1., weights=None):
|
||||||
G: np.array with shape (n,n) - the Gram matrix associated to F
|
G: np.array with shape (n,n) - the Gram matrix associated to F
|
||||||
variances : np.ndarray with shape (n,)
|
variances : np.ndarray with shape (n,)
|
||||||
"""
|
"""
|
||||||
part = finite_dimensionalpart(input_dim, F, G, variances, weights)
|
part = parts.finite_dimensional.FiniteDimensional(input_dim, F, G, variances, weights)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def spline(input_dim, variance=1.):
|
def spline(input_dim, variance=1.):
|
||||||
|
|
@ -150,7 +126,7 @@ def spline(input_dim, variance=1.):
|
||||||
:param variance: the variance of the kernel
|
:param variance: the variance of the kernel
|
||||||
:type variance: float
|
:type variance: float
|
||||||
"""
|
"""
|
||||||
part = splinepart(input_dim, variance)
|
part = parts.spline.Spline(input_dim, variance)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def Brownian(input_dim, variance=1.):
|
def Brownian(input_dim, variance=1.):
|
||||||
|
|
@ -162,7 +138,7 @@ def Brownian(input_dim, variance=1.):
|
||||||
:param variance: the variance of the kernel
|
:param variance: the variance of the kernel
|
||||||
:type variance: float
|
:type variance: float
|
||||||
"""
|
"""
|
||||||
part = Brownianpart(input_dim, variance)
|
part = parts.Brownian.Brownian(input_dim, variance)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -215,7 +191,7 @@ def periodic_exponential(input_dim=1, variance=1., lengthscale=None, period=2 *
|
||||||
:param n_freq: the number of frequencies considered for the periodic subspace
|
:param n_freq: the number of frequencies considered for the periodic subspace
|
||||||
:type n_freq: int
|
:type n_freq: int
|
||||||
"""
|
"""
|
||||||
part = periodic_exponentialpart(input_dim, variance, lengthscale, period, n_freq, lower, upper)
|
part = parts.periodic_exponential.PeriodicExponential(input_dim, variance, lengthscale, period, n_freq, lower, upper)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def periodic_Matern32(input_dim, variance=1., lengthscale=None, period=2 * np.pi, n_freq=10, lower=0., upper=4 * np.pi):
|
def periodic_Matern32(input_dim, variance=1., lengthscale=None, period=2 * np.pi, n_freq=10, lower=0., upper=4 * np.pi):
|
||||||
|
|
@ -233,7 +209,7 @@ def periodic_Matern32(input_dim, variance=1., lengthscale=None, period=2 * np.pi
|
||||||
:param n_freq: the number of frequencies considered for the periodic subspace
|
:param n_freq: the number of frequencies considered for the periodic subspace
|
||||||
:type n_freq: int
|
:type n_freq: int
|
||||||
"""
|
"""
|
||||||
part = periodic_Matern32part(input_dim, variance, lengthscale, period, n_freq, lower, upper)
|
part = parts.periodic_Matern32.PeriodicMatern32(input_dim, variance, lengthscale, period, n_freq, lower, upper)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def periodic_Matern52(input_dim, variance=1., lengthscale=None, period=2 * np.pi, n_freq=10, lower=0., upper=4 * np.pi):
|
def periodic_Matern52(input_dim, variance=1., lengthscale=None, period=2 * np.pi, n_freq=10, lower=0., upper=4 * np.pi):
|
||||||
|
|
@ -251,7 +227,7 @@ def periodic_Matern52(input_dim, variance=1., lengthscale=None, period=2 * np.pi
|
||||||
:param n_freq: the number of frequencies considered for the periodic subspace
|
:param n_freq: the number of frequencies considered for the periodic subspace
|
||||||
:type n_freq: int
|
:type n_freq: int
|
||||||
"""
|
"""
|
||||||
part = periodic_Matern52part(input_dim, variance, lengthscale, period, n_freq, lower, upper)
|
part = parts.periodic_Matern52part(input_dim, variance, lengthscale, period, n_freq, lower, upper)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def prod(k1,k2,tensor=False):
|
def prod(k1,k2,tensor=False):
|
||||||
|
|
@ -262,7 +238,7 @@ def prod(k1,k2,tensor=False):
|
||||||
:type k1, k2: kernpart
|
:type k1, k2: kernpart
|
||||||
:rtype: kernel object
|
:rtype: kernel object
|
||||||
"""
|
"""
|
||||||
part = prodpart(k1,k2,tensor)
|
part = parts.prodpart(k1,k2,tensor)
|
||||||
return kern(part.input_dim, [part])
|
return kern(part.input_dim, [part])
|
||||||
|
|
||||||
def symmetric(k):
|
def symmetric(k):
|
||||||
|
|
@ -270,11 +246,11 @@ def symmetric(k):
|
||||||
Construct a symmetrical kernel from an existing kernel
|
Construct a symmetrical kernel from an existing kernel
|
||||||
"""
|
"""
|
||||||
k_ = k.copy()
|
k_ = k.copy()
|
||||||
k_.parts = [symmetric_part(p) for p in k.parts]
|
k_.parts = [symmetric.Symmetric(p) for p in k.parts]
|
||||||
return k_
|
return k_
|
||||||
|
|
||||||
def Coregionalise(Nout,R=1, W=None, kappa=None):
|
def coregionalise(Nout,R=1, W=None, kappa=None):
|
||||||
p = coregionalise_part(Nout,R,W,kappa)
|
p = parts.coregionalise.Coregionalise(Nout,R,W,kappa)
|
||||||
return kern(1,[p])
|
return kern(1,[p])
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -291,10 +267,10 @@ def rational_quadratic(input_dim, variance=1., lengthscale=1., power=1.):
|
||||||
:rtype: kern object
|
:rtype: kern object
|
||||||
|
|
||||||
"""
|
"""
|
||||||
part = rational_quadraticpart(input_dim, variance, lengthscale, power)
|
part = parts.rational_quadratic.RationalQuadratic(input_dim, variance, lengthscale, power)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def Fixed(input_dim, K, variance=1.):
|
def fixed(input_dim, K, variance=1.):
|
||||||
"""
|
"""
|
||||||
Construct a Fixed effect kernel.
|
Construct a Fixed effect kernel.
|
||||||
|
|
||||||
|
|
@ -304,23 +280,21 @@ def Fixed(input_dim, K, variance=1.):
|
||||||
K (np.array), obligatory
|
K (np.array), obligatory
|
||||||
variance (float)
|
variance (float)
|
||||||
"""
|
"""
|
||||||
part = fixedpart(input_dim, K, variance)
|
part = parts.fixed.Fixed(input_dim, K, variance)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def rbfcos(input_dim, variance=1., frequencies=None, bandwidths=None, ARD=False):
|
def rbfcos(input_dim, variance=1., frequencies=None, bandwidths=None, ARD=False):
|
||||||
"""
|
"""
|
||||||
construct a rbfcos kernel
|
construct a rbfcos kernel
|
||||||
"""
|
"""
|
||||||
part = rbfcospart(input_dim, variance, frequencies, bandwidths, ARD)
|
part = parts.rbfcos.RBFCos(input_dim, variance, frequencies, bandwidths, ARD)
|
||||||
return kern(input_dim, [part])
|
return kern(input_dim, [part])
|
||||||
|
|
||||||
def IndependentOutputs(k):
|
def independent_outputs(k):
|
||||||
"""
|
"""
|
||||||
Construct a kernel with independent outputs from an existing kernel
|
Construct a kernel with independent outputs from an existing kernel
|
||||||
"""
|
"""
|
||||||
for sl in k.input_slices:
|
for sl in k.input_slices:
|
||||||
assert (sl.start is None) and (sl.stop is None), "cannot adjust input slices! (TODO)"
|
assert (sl.start is None) and (sl.stop is None), "cannot adjust input slices! (TODO)"
|
||||||
parts = [independent_output_part(p) for p in k.parts]
|
parts = [independent_outputs.IndependentOutputs(p) for p in k.parts]
|
||||||
return kern(k.input_dim+1,parts)
|
return kern(k.input_dim+1,parts)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
# 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)
|
||||||
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pylab as pb
|
import pylab as pb
|
||||||
from ..core.parameterised import Parameterised
|
from ..core.parameterised import Parameterised
|
||||||
from kernpart import Kernpart
|
from parts.kernpart import Kernpart
|
||||||
import itertools
|
import itertools
|
||||||
from prod import prod
|
from parts.prod import Prod as prod
|
||||||
|
|
||||||
class kern(Parameterised):
|
class kern(Parameterised):
|
||||||
def __init__(self, input_dim, parts=[], input_slices=None):
|
def __init__(self, input_dim, parts=[], input_slices=None):
|
||||||
|
|
|
||||||
21
GPy/kern/parts/__init__.py
Normal file
21
GPy/kern/parts/__init__.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import bias
|
||||||
|
import Brownian
|
||||||
|
import coregionalise
|
||||||
|
import exponential
|
||||||
|
import finite_dimensional
|
||||||
|
import fixed
|
||||||
|
import independent_outputs
|
||||||
|
import linear
|
||||||
|
import Matern32
|
||||||
|
import Matern52
|
||||||
|
import periodic_exponential
|
||||||
|
import periodic_Matern32
|
||||||
|
import periodic_Matern52
|
||||||
|
import prod_orthogonal
|
||||||
|
import prod
|
||||||
|
import rational_quadratic
|
||||||
|
import rbfcos
|
||||||
|
import rbf
|
||||||
|
import spline
|
||||||
|
import symmetric
|
||||||
|
import white
|
||||||
|
|
@ -6,7 +6,7 @@ from kernpart import Kernpart
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
class bias(Kernpart):
|
class Bias(Kernpart):
|
||||||
def __init__(self,input_dim,variance=1.):
|
def __init__(self,input_dim,variance=1.):
|
||||||
"""
|
"""
|
||||||
:param input_dim: the number of input dimensions
|
:param input_dim: the number of input dimensions
|
||||||
|
|
@ -6,7 +6,7 @@ from kernpart import Kernpart
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy import integrate
|
from scipy import integrate
|
||||||
|
|
||||||
class exponential(Kernpart):
|
class Exponential(Kernpart):
|
||||||
"""
|
"""
|
||||||
Exponential kernel (aka Ornstein-Uhlenbeck or Matern 1/2)
|
Exponential kernel (aka Ornstein-Uhlenbeck or Matern 1/2)
|
||||||
|
|
||||||
|
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
from kernpart import Kernpart
|
from kernpart import Kernpart
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from ..util.linalg import pdinv,mdot
|
from ...util.linalg import pdinv,mdot
|
||||||
|
|
||||||
class finite_dimensional(Kernpart):
|
class FiniteDimensional(Kernpart):
|
||||||
def __init__(self, input_dim, F, G, variance=1., weights=None):
|
def __init__(self, input_dim, F, G, variance=1., weights=None):
|
||||||
"""
|
"""
|
||||||
Argumnents
|
Argumnents
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
from kernpart import Kernpart
|
from kernpart import Kernpart
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from ..util.linalg import tdot
|
from ...util.linalg import tdot
|
||||||
from scipy import weave
|
from scipy import weave
|
||||||
|
|
||||||
class linear(Kernpart):
|
class Linear(Kernpart):
|
||||||
"""
|
"""
|
||||||
Linear kernel
|
Linear kernel
|
||||||
|
|
||||||
|
|
@ -7,7 +7,7 @@ import numpy as np
|
||||||
from GPy.util.linalg import mdot
|
from GPy.util.linalg import mdot
|
||||||
from GPy.util.decorators import silence_errors
|
from GPy.util.decorators import silence_errors
|
||||||
|
|
||||||
class periodic_Matern32(Kernpart):
|
class PeriodicMatern32(Kernpart):
|
||||||
"""
|
"""
|
||||||
Kernel of the periodic subspace (up to a given frequency) of a Matern 3/2 RKHS. Only defined for input_dim=1.
|
Kernel of the periodic subspace (up to a given frequency) of a Matern 3/2 RKHS. Only defined for input_dim=1.
|
||||||
|
|
||||||
|
|
@ -7,7 +7,7 @@ import numpy as np
|
||||||
from GPy.util.linalg import mdot
|
from GPy.util.linalg import mdot
|
||||||
from GPy.util.decorators import silence_errors
|
from GPy.util.decorators import silence_errors
|
||||||
|
|
||||||
class periodic_Matern52(Kernpart):
|
class PeriodicMatern52(Kernpart):
|
||||||
"""
|
"""
|
||||||
Kernel of the periodic subspace (up to a given frequency) of a Matern 5/2 RKHS. Only defined for input_dim=1.
|
Kernel of the periodic subspace (up to a given frequency) of a Matern 5/2 RKHS. Only defined for input_dim=1.
|
||||||
|
|
||||||
|
|
@ -7,7 +7,7 @@ import numpy as np
|
||||||
from GPy.util.linalg import mdot
|
from GPy.util.linalg import mdot
|
||||||
from GPy.util.decorators import silence_errors
|
from GPy.util.decorators import silence_errors
|
||||||
|
|
||||||
class periodic_exponential(Kernpart):
|
class PeriodicExponential(Kernpart):
|
||||||
"""
|
"""
|
||||||
Kernel of the periodic subspace (up to a given frequency) of a exponential (Matern 1/2) RKHS. Only defined for input_dim=1.
|
Kernel of the periodic subspace (up to a given frequency) of a exponential (Matern 1/2) RKHS. Only defined for input_dim=1.
|
||||||
|
|
||||||
|
|
@ -5,7 +5,7 @@ from kernpart import Kernpart
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
class prod(Kernpart):
|
class Prod(Kernpart):
|
||||||
"""
|
"""
|
||||||
Computes the product of 2 kernels
|
Computes the product of 2 kernels
|
||||||
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
from kernpart import Kernpart
|
from kernpart import Kernpart
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
class rational_quadratic(Kernpart):
|
class RationalQuadratic(Kernpart):
|
||||||
"""
|
"""
|
||||||
rational quadratic kernel
|
rational quadratic kernel
|
||||||
|
|
||||||
|
|
@ -6,9 +6,9 @@ from kernpart import Kernpart
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import hashlib
|
import hashlib
|
||||||
from scipy import weave
|
from scipy import weave
|
||||||
from ..util.linalg import tdot
|
from ...util.linalg import tdot
|
||||||
|
|
||||||
class rbf(Kernpart):
|
class RBF(Kernpart):
|
||||||
"""
|
"""
|
||||||
Radial Basis Function kernel, aka squared-exponential, exponentiated quadratic or Gaussian kernel:
|
Radial Basis Function kernel, aka squared-exponential, exponentiated quadratic or Gaussian kernel:
|
||||||
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
from kernpart import Kernpart
|
from kernpart import Kernpart
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
class rbfcos(Kernpart):
|
class RBFCos(Kernpart):
|
||||||
def __init__(self,input_dim,variance=1.,frequencies=None,bandwidths=None,ARD=False):
|
def __init__(self,input_dim,variance=1.,frequencies=None,bandwidths=None,ARD=False):
|
||||||
self.input_dim = input_dim
|
self.input_dim = input_dim
|
||||||
self.name = 'rbfcos'
|
self.name = 'rbfcos'
|
||||||
|
|
@ -9,7 +9,7 @@ def theta(x):
|
||||||
"""Heaviside step function"""
|
"""Heaviside step function"""
|
||||||
return np.where(x>=0.,1.,0.)
|
return np.where(x>=0.,1.,0.)
|
||||||
|
|
||||||
class spline(Kernpart):
|
class Spline(Kernpart):
|
||||||
"""
|
"""
|
||||||
Spline kernel
|
Spline kernel
|
||||||
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
from kernpart import Kernpart
|
from kernpart import Kernpart
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
class symmetric(Kernpart):
|
class Symmetric(Kernpart):
|
||||||
"""
|
"""
|
||||||
Symmetrical kernels
|
Symmetrical kernels
|
||||||
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
# 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 kernpart import Kernpart
|
from kernpart import Kernpart
|
||||||
import numpy as np
|
import numpy as np
|
||||||
class white(Kernpart):
|
|
||||||
|
class White(Kernpart):
|
||||||
"""
|
"""
|
||||||
White noise kernel.
|
White noise kernel.
|
||||||
|
|
||||||
|
|
@ -2,6 +2,7 @@ import numpy as np
|
||||||
from likelihood import likelihood
|
from likelihood import likelihood
|
||||||
from ..util.linalg import jitchol
|
from ..util.linalg import jitchol
|
||||||
|
|
||||||
|
|
||||||
class Gaussian(likelihood):
|
class Gaussian(likelihood):
|
||||||
"""
|
"""
|
||||||
Likelihood class for doing Expectation propagation
|
Likelihood class for doing Expectation propagation
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class KernelTests(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
X = np.random.rand(30, 4)
|
X = np.random.rand(30, 4)
|
||||||
K = np.dot(X, X.T)
|
K = np.dot(X, X.T)
|
||||||
kernel = GPy.kern.Fixed(4, K)
|
kernel = GPy.kern.fixed(4, K)
|
||||||
Y = np.ones((30,1))
|
Y = np.ones((30,1))
|
||||||
m = GPy.models.GPRegression(X,Y,kernel=kernel)
|
m = GPy.models.GPRegression(X,Y,kernel=kernel)
|
||||||
self.assertTrue(m.checkgrad())
|
self.assertTrue(m.checkgrad())
|
||||||
|
|
@ -36,7 +36,7 @@ class KernelTests(unittest.TestCase):
|
||||||
Y = np.vstack((Y1,Y2))
|
Y = np.vstack((Y1,Y2))
|
||||||
|
|
||||||
k1 = GPy.kern.rbf(1) + GPy.kern.bias(1)
|
k1 = GPy.kern.rbf(1) + GPy.kern.bias(1)
|
||||||
k2 = GPy.kern.Coregionalise(2,1)
|
k2 = GPy.kern.coregionalise(2,1)
|
||||||
k = k1.prod(k2,tensor=True)
|
k = k1.prod(k2,tensor=True)
|
||||||
m = GPy.models.GPRegression(X,Y,kernel=k)
|
m = GPy.models.GPRegression(X,Y,kernel=k)
|
||||||
self.assertTrue(m.checkgrad())
|
self.assertTrue(m.checkgrad())
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,36 @@ def align_subplots(N,M,xlim=None, ylim=None):
|
||||||
else:
|
else:
|
||||||
removeUpperTicks()
|
removeUpperTicks()
|
||||||
|
|
||||||
|
def align_subplot_array(axes,xlim=None, ylim=None):
|
||||||
|
"""make all of the axes in the array hae the same limits, turn off unnecessary ticks
|
||||||
|
|
||||||
|
use pb.subplots() to get an array of axes
|
||||||
|
"""
|
||||||
|
#find sensible xlim,ylim
|
||||||
|
if xlim is None:
|
||||||
|
xlim = [np.inf,-np.inf]
|
||||||
|
for ax in axes.flatten():
|
||||||
|
xlim[0] = min(xlim[0],ax.get_xlim()[0])
|
||||||
|
xlim[1] = max(xlim[1],ax.get_xlim()[1])
|
||||||
|
if ylim is None:
|
||||||
|
ylim = [np.inf,-np.inf]
|
||||||
|
for ax in axes.flatten():
|
||||||
|
ylim[0] = min(ylim[0],ax.get_ylim()[0])
|
||||||
|
ylim[1] = max(ylim[1],ax.get_ylim()[1])
|
||||||
|
|
||||||
|
N,M = axes.shape
|
||||||
|
for i,ax in enumerate(axes.flatten()):
|
||||||
|
ax.set_xlim(xlim)
|
||||||
|
ax.set_ylim(ylim)
|
||||||
|
if (i)%M:
|
||||||
|
ax.set_yticks([])
|
||||||
|
else:
|
||||||
|
removeRightTicks(ax)
|
||||||
|
if i<(M*(N-1)):
|
||||||
|
ax.set_xticks([])
|
||||||
|
else:
|
||||||
|
removeUpperTicks(ax)
|
||||||
|
|
||||||
def x_frame1D(X,plot_limits=None,resolution=None):
|
def x_frame1D(X,plot_limits=None,resolution=None):
|
||||||
"""
|
"""
|
||||||
Internal helper function for making plots, returns a set of input values to plot as well as lower and upper limits
|
Internal helper function for making plots, returns a set of input values to plot as well as lower and upper limits
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue