Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different mean functions for the Gaussian process #305

Open
HeltonSM opened this issue May 4, 2019 · 1 comment
Open

Different mean functions for the Gaussian process #305

HeltonSM opened this issue May 4, 2019 · 1 comment

Comments

@HeltonSM
Copy link

HeltonSM commented May 4, 2019

Is it possible to define the mean function for the Gaussian process.

A quadratic one for example?

If so, can you provide the syntax for that?

Thank you.

@uremes
Copy link
Contributor

uremes commented Jan 16, 2023

Hi! This is an old question but I decided to comment in case someone else would also need this.

ELFI uses GPy models which take a mean function as input parameter. The available mean functions are listed here, but it is also possible to create a custom one. For example @jankokk used this in his thesis:

import numpy as np
import GPy

class Polynomial(GPy.core.Mapping):

    def __init__(self, input_dim, output_dim, name='polymap'):

        super(Polynomial, self).__init__(input_dim=input_dim, output_dim=output_dim, name=name)

        self.A = GPy.core.Param('A', np.random.rand(self.input_dim, self.output_dim))
        self.B = GPy.core.Param('B', np.random.rand(self.input_dim, self.output_dim))
        self.C = GPy.core.Param('C', np.random.rand())

        self.link_parameter(self.A)
        self.link_parameter(self.B)
        self.link_parameter(self.C)

        self.A.constrain_positive()

    def f(self, X):

        XX = np.power(X, 2)
        return np.dot(XX, self.A) + np.dot(X, self.B) + self.C

    def update_gradients(self, dL_dF, X):

        XX = np.power(X, 2)
        self.A.gradient = np.dot(XX.T, dL_dF)
        self.B.gradient = np.dot(X.T, dL_dF)
        self.C.gradient = np.sum(dL_dF, axis=0)

And how to use a mean function in BOLFI:

import elfi
from elfi.examples import ma2

seed = 230112

m = ma2.get_model(seed_obs=seed)
bounds = {'t1':(-2, 2), 't2':(-1, 1)}

# Gaussian process model
mean_function = Polynomial(2, 1)
target_model = elfi.GPyRegression(m.parameter_names, bounds=bounds, mean_function=mean_function)

# BOLFI
bolfi = elfi.BOLFI(m['d'], initial_evidence=20, update_interval=10, target_model=target_model, seed=seed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants