dfm / george

Fast and flexible Gaussian Process regression in Python
http://george.readthedocs.io
MIT License
451 stars 128 forks source link

str of Matern32Kernels #146

Open elloa opened 3 years ago

elloa commented 3 years ago

To string version of Matern32Kernels must be improved in order to allow copy and paste

On code: kernels.Matern32Kernel(metric=18.9, ndim=3) + kernels.Matern32Kernel(metric=1.2, ndim=3)

When printing kernel name:

Matern32Kernel(metric=**Metric**(1.6, ndim=3, axes=array([0, 1, 2]), bounds=[(None, None)]), block=None) + Matern32Kernel(metric=**Metric**(1.2, ndim=3, axes=array([0, 1, 2]), bounds=[(None, None)]), block=None)

Bold emphasis on wrong printing

MWE

from george import kernels
k = kernels.Matern32Kernel(metric=18.9, ndim=3) + kernels.Matern32Kernel(metric=1.2, ndim=3)
print(str(k))

ERROR:

from george import kernels
k1 = kernels.Matern32Kernel(metric=Metric(1.6, ndim=3, axes=array([0, 1, 2]), bounds=[(None, None)]), block=None)

NameError: name 'Metric' is not defined

dfm commented 3 years ago

While it's true that there is an issue here, this report is not it. Yes, you need to import Metric if you want to copy and paste the __repr__, just numpy arrays and everything else!

The real issue is somewhere deep in the modeling protocol:

from george import kernels
k = kernels.Matern32Kernel(metric=18.9, ndim=3)
print(str(k))
# prints: 
#   >>> Matern32Kernel(metric=Metric(18.9, ndim=3, axes=array([0, 1, 2]), bounds=[(None, None)]), block=None)

Then:

from george.kernels import Matern32Kernel
from george.metrics import Metric
from numpy import array
Matern32Kernel(metric=Metric(18.9, ndim=3, axes=array([0, 1, 2]), bounds=[(None, None)]), block=None)

which should work, but fails with the error:

AttributeError: 'Metric' object has no attribute 'log_M_0_0'

It's not high on my priority list to fix this, but I'm happy to keep it open in case someone else wants to take a look!

elloa commented 3 years ago

@dfm Thanks for properly addressing the error report. Newbie here.