'GPR' object has no attribute 'X'

Viewed 39

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 Answers

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.

Related