1

I am trying to run the code from https://github.com/befelix/safe_learning/blob/master/examples/1d_example.ipynb . This code is written for gpflow version 0.4.0. I want to update this code for gpflow version 2.5.2. I changed the following line

gp = gpflow.gpr.GPR(np.empty((0, 2), dtype=safe_learning.config.np_dtype),
                    np.empty((0, 1), dtype=safe_learning.config.np_dtype),
                    kernel,
                    mean_function=mean_function)

to

gp = gpflow.models.GPR(data=(np.empty((0, 2), dtype=safe_learning.config.np_dtype),
                    np.empty((0, 1), dtype=safe_learning.config.np_dtype)),
                    kernel=kernel,
                    mean_function=mean_function)

then it creates a class object, dynamics = safe_learning.GaussianProcess(gp, name='gp_dynamics') which is defined as follows:

    """A GaussianProcess model based on gpflow.

    Parameters
    ----------
    gaussian_process : instance of gpflow.models.GPModel
        The Gaussian process model.
    beta : float
        The scaling factor for the standard deviation to create
        confidence intervals.

    
    """

    def __init__(self, gaussian_process, beta=2., name='gaussian_process'):
        """Initialization."""
        super(GaussianProcess, self).__init__(name=name)

        with tf.variable_scope(self.scope_name):
            self.n_dim = gaussian_process.X.shape[-1]
            self.gaussian_process = gaussian_process
            self.beta = float(beta)

            self.input_dim = gaussian_process.X.shape[1]
            self.output_dim = gaussian_process.Y.shape[1]

            self.hyperparameters = [tf.placeholder(config.dtype, [None])]
            self.gaussian_process.make_tf_array(self.hyperparameters[0])

            self.update_feed_dict()
...

when I run this class, I get the following error

dynamics = safe_learning.GaussianProcess(gp, name='gp_dynamics')
Traceback (most recent call last):

  Input In [39] in <cell line: 1>
    dynamics = safe_learning.GaussianProcess(gp, name='gp_dynamics')

  File D:\python\safe_learning-master\safe_learning-master\safe_learning\functions.py:490 in __init__
    self.n_dim = gaussian_process.X.shape[-1]

AttributeError: 'GPR' object has no attribute 'X'

Please kindly help me how this attribute has changed in new version (2.5.2) of gpflow. I am using the following link to upgrade https://gpflow.github.io/GPflow/develop/notebooks/gpflow2_upgrade_guide.html#Model-Class

Thanks in advance.

1 Answer 1

0

There's a big difference between 0.4.0 and 2.5.2. I don't think you should expect this to be an easy process.

model.X and model.Y has been replaced with model.data[0] and model.data[1] respectively. In fact model.data corresponds to the data parameter you passed to the GPR initialiser.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot. Changing to data[0], data[1] is working. I am getting couple of issues similar to above. For example, "'GPR' object has no attribute 'make_tf_array'". Can you suggest any link that list out the changes? Though it is not an easy process, it is a requirement for me to make it run. Thank you.
I'm afraid you're asking for change over too long time. You're asking for the difference between now and 5 years ago, and that covers two major versions. We had an upgrade guide from version 1.x.x to 2.x.x, but even that is deprecated. We also have a change log, but that only goes back to version 2.1.5. I'm sorry. I think you're going to have to dive into the source code and really understand GPflow, if you want to make this kind of update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.