Beispiel #1
0
    def eq_sympy(input_dim, output_dim, ARD=False):
        """
        Latent force model covariance, exponentiated quadratic with multiple outputs. Derived from a diffusion equation with the initial spatial condition layed down by a Gaussian process with lengthscale given by shared_lengthscale.

        See IEEE Trans Pattern Anal Mach Intell. 2013 Nov;35(11):2693-705. doi: 10.1109/TPAMI.2013.86. Linear latent force models using Gaussian processes. Alvarez MA, Luengo D, Lawrence ND.

        :param input_dim: Dimensionality of the kernel
        :type input_dim: int
        :param output_dim: number of outputs in the covariance function.
        :type output_dim: int
        :param ARD: whether or not to user ARD (default False).
        :type ARD: bool

        """
        real_input_dim = input_dim
        if output_dim>1:
            real_input_dim -= 1
        X = sp.symbols('x_:' + str(real_input_dim))
        Z = sp.symbols('z_:' + str(real_input_dim))
        scale = sp.var('scale_i scale_j',positive=True)
        if ARD:
            lengthscales = [sp.var('lengthscale%i_i lengthscale%i_j' % i, positive=True) for i in range(real_input_dim)]
            shared_lengthscales = [sp.var('shared_lengthscale%i' % i, positive=True) for i in range(real_input_dim)]
            dist_string = ' + '.join(['(x_%i-z_%i)**2/(shared_lengthscale%i**2 + lengthscale%i_i**2 + lengthscale%i_j**2)' % (i, i, i) for i in range(real_input_dim)])
            dist = parse_expr(dist_string)
            f =  variance*sp.exp(-dist/2.)
        else:
            lengthscales = sp.var('lengthscale_i lengthscale_j',positive=True)
            shared_lengthscale = sp.var('shared_lengthscale',positive=True)
            dist_string = ' + '.join(['(x_%i-z_%i)**2' % (i, i) for i in range(real_input_dim)])
            dist = parse_expr(dist_string)
            f =  scale_i*scale_j*sp.exp(-dist/(2*(lengthscale_i**2 + lengthscale_j**2 + shared_lengthscale**2)))
        return kern(input_dim, [spkern(input_dim, f, output_dim=output_dim, name='eq_sympy')])
Beispiel #2
0
    def sympykern(input_dim, k=None, output_dim=1, name=None, param=None):
        """
        A base kernel object, where all the hard work in done by sympy.

        :param k: the covariance function
        :type k: a positive definite sympy function of x1, z1, x2, z2...

        To construct a new sympy kernel, you'll need to define:
         - a kernel function using a sympy object. Ensure that the kernel is of the form k(x,z).
         - that's it! we'll extract the variables from the function k.

        Note:
         - to handle multiple inputs, call them x1, z1, etc
         - to handle multpile correlated outputs, you'll need to define each covariance function and 'cross' variance function. TODO
        """
        return kern(input_dim, [spkern(input_dim, k=k, output_dim=output_dim, name=name, param=param)])
Beispiel #3
0
    def eq_sympy(input_dim, output_dim, ARD=False):
        """
        Latent force model covariance, exponentiated quadratic with multiple outputs. Derived from a diffusion equation with the initial spatial condition layed down by a Gaussian process with lengthscale given by shared_lengthscale.

        See IEEE Trans Pattern Anal Mach Intell. 2013 Nov;35(11):2693-705. doi: 10.1109/TPAMI.2013.86. Linear latent force models using Gaussian processes. Alvarez MA, Luengo D, Lawrence ND.

        :param input_dim: Dimensionality of the kernel
        :type input_dim: int
        :param output_dim: number of outputs in the covariance function.
        :type output_dim: int
        :param ARD: whether or not to user ARD (default False).
        :type ARD: bool

        """
        real_input_dim = input_dim
        if output_dim > 1:
            real_input_dim -= 1
        X = sp.symbols('x_:' + str(real_input_dim))
        Z = sp.symbols('z_:' + str(real_input_dim))
        scale = sp.var('scale_i scale_j', positive=True)
        if ARD:
            lengthscales = [
                sp.var('lengthscale%i_i lengthscale%i_j' % i, positive=True)
                for i in range(real_input_dim)
            ]
            shared_lengthscales = [
                sp.var('shared_lengthscale%i' % i, positive=True)
                for i in range(real_input_dim)
            ]
            dist_string = ' + '.join([
                '(x_%i-z_%i)**2/(shared_lengthscale%i**2 + lengthscale%i_i**2 + lengthscale%i_j**2)'
                % (i, i, i) for i in range(real_input_dim)
            ])
            dist = parse_expr(dist_string)
            f = variance * sp.exp(-dist / 2.)
        else:
            lengthscales = sp.var('lengthscale_i lengthscale_j', positive=True)
            shared_lengthscale = sp.var('shared_lengthscale', positive=True)
            dist_string = ' + '.join(
                ['(x_%i-z_%i)**2' % (i, i) for i in range(real_input_dim)])
            dist = parse_expr(dist_string)
            f = scale_i * scale_j * sp.exp(-dist / (
                2 *
                (lengthscale_i**2 + lengthscale_j**2 + shared_lengthscale**2)))
        return kern(
            input_dim,
            [spkern(input_dim, f, output_dim=output_dim, name='eq_sympy')])
Beispiel #4
0
 def rbf_sympy(input_dim, ARD=False, variance=1., lengthscale=1.):
     """
     Radial Basis Function covariance.
     """
     X = sp.symbols('x_:' + str(input_dim))
     Z = sp.symbols('z_:' + str(input_dim))
     variance = sp.var('variance',positive=True)
     if ARD:
         lengthscales = sp.symbols('lengthscale_:' + str(input_dim))
         dist_string = ' + '.join(['(x_%i-z_%i)**2/lengthscale%i**2' % (i, i, i) for i in range(input_dim)])
         dist = parse_expr(dist_string)
         f =  variance*sp.exp(-dist/2.)
     else:
         lengthscale = sp.var('lengthscale',positive=True)
         dist_string = ' + '.join(['(x_%i-z_%i)**2' % (i, i) for i in range(input_dim)])
         dist = parse_expr(dist_string)
         f =  variance*sp.exp(-dist/(2*lengthscale**2))
     return kern(input_dim, [spkern(input_dim, f, name='rbf_sympy')])
Beispiel #5
0
    def ode1_eq(output_dim=1):
        """
        Latent force model covariance, first order differential
        equation driven by exponentiated quadratic.

        See N. D. Lawrence, G. Sanguinetti and M. Rattray. (2007)
        'Modelling transcriptional regulation using Gaussian
        processes' in B. Schoelkopf, J. C. Platt and T. Hofmann (eds)
        Advances in Neural Information Processing Systems, MIT Press,
        Cambridge, MA, pp 785--792.

        :param output_dim: number of outputs in the covariance function.
        :type output_dim: int
        """
        input_dim = 2
        x_0, z_0, decay_i, decay_j, scale_i, scale_j, lengthscale = sp.symbols('x_0, z_0, decay_i, decay_j, scale_i, scale_j, lengthscale')
        f = scale_i*scale_j*(symbolic.h(x_0, z_0, decay_i, decay_j, lengthscale) 
     + symbolic.h(z_0, x_0, decay_j, decay_i, lengthscale))
        return kern(input_dim, [spkern(input_dim, f, output_dim=output_dim, name='ode1_eq')])
Beispiel #6
0
    def sympykern(input_dim, k=None, output_dim=1, name=None, param=None):
        """
        A base kernel object, where all the hard work in done by sympy.

        :param k: the covariance function
        :type k: a positive definite sympy function of x1, z1, x2, z2...

        To construct a new sympy kernel, you'll need to define:
         - a kernel function using a sympy object. Ensure that the kernel is of the form k(x,z).
         - that's it! we'll extract the variables from the function k.

        Note:
         - to handle multiple inputs, call them x1, z1, etc
         - to handle multpile correlated outputs, you'll need to define each covariance function and 'cross' variance function. TODO
        """
        return kern(input_dim, [
            spkern(
                input_dim, k=k, output_dim=output_dim, name=name, param=param)
        ])
Beispiel #7
0
 def rbf_sympy(input_dim, ARD=False, variance=1., lengthscale=1.):
     """
     Radial Basis Function covariance.
     """
     X = sp.symbols('x_:' + str(input_dim))
     Z = sp.symbols('z_:' + str(input_dim))
     variance = sp.var('variance', positive=True)
     if ARD:
         lengthscales = sp.symbols('lengthscale_:' + str(input_dim))
         dist_string = ' + '.join([
             '(x_%i-z_%i)**2/lengthscale%i**2' % (i, i, i)
             for i in range(input_dim)
         ])
         dist = parse_expr(dist_string)
         f = variance * sp.exp(-dist / 2.)
     else:
         lengthscale = sp.var('lengthscale', positive=True)
         dist_string = ' + '.join(
             ['(x_%i-z_%i)**2' % (i, i) for i in range(input_dim)])
         dist = parse_expr(dist_string)
         f = variance * sp.exp(-dist / (2 * lengthscale**2))
     return kern(input_dim, [spkern(input_dim, f, name='rbf_sympy')])
Beispiel #8
0
    def ode1_eq(output_dim=1):
        """
        Latent force model covariance, first order differential
        equation driven by exponentiated quadratic.

        See N. D. Lawrence, G. Sanguinetti and M. Rattray. (2007)
        'Modelling transcriptional regulation using Gaussian
        processes' in B. Schoelkopf, J. C. Platt and T. Hofmann (eds)
        Advances in Neural Information Processing Systems, MIT Press,
        Cambridge, MA, pp 785--792.

        :param output_dim: number of outputs in the covariance function.
        :type output_dim: int
        """
        input_dim = 2
        x_0, z_0, decay_i, decay_j, scale_i, scale_j, lengthscale = sp.symbols(
            'x_0, z_0, decay_i, decay_j, scale_i, scale_j, lengthscale')
        f = scale_i * scale_j * (
            symbolic.h(x_0, z_0, decay_i, decay_j, lengthscale) +
            symbolic.h(z_0, x_0, decay_j, decay_i, lengthscale))
        return kern(
            input_dim,
            [spkern(input_dim, f, output_dim=output_dim, name='ode1_eq')])