dfm / george

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

AttributeError: kernel #101

Closed cmcgrud1 closed 6 years ago

cmcgrud1 commented 6 years ago

Hey dfm, I am trying to implement a new kernel with the developmental version of george on github and I keep running into a AttributeError. In fact when I just copy and past the example MyLocalGaussian.yml file and put it in the kernel directory and reinstall george I get this error when attempting to do the gradient test the tutorial does:

In [1]: import numpy as np

In [2]: from george import kernels

In [3]: x = np.linspace(-10,10,500)

In [4]: kernel = 5 * kernels.MyLocalGaussianKernel(x0=0.0, log_w=np.log(0.2))

In [5]: kernel.test_gradient(np.atleast_2d(x).T)

AttributeError Traceback (most recent call last)

in () ----> 1 kernel.test_gradient(np.atleast_2d(x).T) /Users/chimamcgruder/anaconda/lib/python2.7/site-packages/george-0.3.1-py2.7-macosx-10.5-x86_64.egg/george/kernels.pyc in test_gradient(self, x1, x2, eps, **kwargs) 146 def test_gradient(self, x1, x2=None, eps=1.32e-6, **kwargs): 147 vector = self.get_parameter_vector() --> 148 g0 = self.get_gradient(x1, x2=x2) 149 150 for i, v in enumerate(vector): /Users/chimamcgruder/anaconda/lib/python2.7/site-packages/george-0.3.1-py2.7-macosx-10.5-x86_64.egg/george/kernels.pyc in get_gradient(self, x1, x2, include_frozen) 122 x1 = np.ascontiguousarray(x1, dtype=np.float64) 123 if x2 is None: --> 124 g = self.kernel.gradient_symmetric(which, x1) 125 else: 126 x2 = np.ascontiguousarray(x2, dtype=np.float64) /Users/chimamcgruder/anaconda/lib/python2.7/site-packages/george-0.3.1-py2.7-macosx-10.5-x86_64.egg/george/kernels.pyc in __getattr__(self, name) 64 if None in self.models: 65 return getattr(self.models[None], name) ---> 66 raise AttributeError(name) 67 68 @property AttributeError: kernel In [6]: kernel = 5 * kernels.LocalGaussianKernel(location=0.0, log_width=np.log(0.2)) In [7]: kernel.test_gradient(np.atleast_2d(x).T) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () ----> 1 kernel.test_gradient(np.atleast_2d(x).T) /Users/chimamcgruder/anaconda/lib/python2.7/site-packages/george-0.3.1-py2.7-macosx-10.5-x86_64.egg/george/kernels.pyc in test_gradient(self, x1, x2, eps, **kwargs) 146 def test_gradient(self, x1, x2=None, eps=1.32e-6, **kwargs): 147 vector = self.get_parameter_vector() --> 148 g0 = self.get_gradient(x1, x2=x2) 149 150 for i, v in enumerate(vector): /Users/chimamcgruder/anaconda/lib/python2.7/site-packages/george-0.3.1-py2.7-macosx-10.5-x86_64.egg/george/kernels.pyc in get_gradient(self, x1, x2, include_frozen) 122 x1 = np.ascontiguousarray(x1, dtype=np.float64) 123 if x2 is None: --> 124 g = self.kernel.gradient_symmetric(which, x1) 125 else: 126 x2 = np.ascontiguousarray(x2, dtype=np.float64) /Users/chimamcgruder/anaconda/lib/python2.7/site-packages/george-0.3.1-py2.7-macosx-10.5-x86_64.egg/george/kernels.pyc in __getattr__(self, name) 64 if None in self.models: 65 return getattr(self.models[None], name) ---> 66 raise AttributeError(name) 67 68 @property AttributeError: kernel As you can also see when I attempt the already implemented 'LocalGaussianKernel' I get the same error. However, interesting enough when I try a kernel such as 'Matern32Kernel,' no such error arises. I have no idea what is causing this error, any insight you can give would be super helpful. Thanks
dfm commented 6 years ago

Brutal. I can't reproduce this, but I expect that it has something to do with clashing versions of george. Here's what I would do:

pip uninstall george
pip uninstall george
pip uninstall george  # do this a few times until it says that george is not installed...

rm -rf build
python setup.py develop

And try that again. If that doesn't work, I'll think on it some more...

cmcgrud1 commented 6 years ago

yup yup yup, that fixed the problem. Your wisdom knows no bounds. Thank you very much!