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

Metric attributes not set correctly when passed a Metric instance #127

Open
StijnDebackere opened this issue May 25, 2020 · 0 comments
Open

Comments

@StijnDebackere
Copy link

The following example fails in both the python2 and python3 versions of george

from george import kernels
from george import metrics

matern =  kernels.Matern32Kernel(4, ndim=2)
m = metrics.Metric(matern.metric)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-e15f1390792f> in <module>
      3 
      4 matern =  kernels.Matern32Kernel(4, ndim=2)
----> 5 m = metrics.Metric(matern.metric)

/usr/local/lib/python3.7/site-packages/george/metrics.py in __init__(self, metric, bounds, ndim, axes, lower)
     37             self.set_parameter_vector(
     38                 metric.get_parameter_vector(include_frozen=True),
---> 39                 include_frozen=True)
     40             self.parameter_bounds = metric.parameter_bounds
     41             self.ndim = metric.ndim

/usr/local/lib/python3.7/site-packages/george/modeling.py in set_parameter_vector(self, vector, include_frozen)
    244 
    245         """
--> 246         v = self.parameter_vector
    247         if include_frozen:
    248             v[:] = vector

/usr/local/lib/python3.7/site-packages/george/modeling.py in parameter_vector(self)
    164     def parameter_vector(self):
    165         """An array of all parameters (including frozen parameters)"""
--> 166         return np.array([getattr(self, k) for k in self.parameter_names])
    167 
    168     @parameter_vector.setter

/usr/local/lib/python3.7/site-packages/george/modeling.py in <listcomp>(.0)
    164     def parameter_vector(self):
    165         """An array of all parameters (including frozen parameters)"""
--> 166         return np.array([getattr(self, k) for k in self.parameter_names])
    167 
    168     @parameter_vector.setter

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

The Model.parameter_vector, which is called in Model.set_parameter_vector(), needs all parameter names to be loaded as attributes, which does not happen when calling Model.set_parameter_vector(). Changing

self.set_parameter_vector(
    metric.get_parameter_vector(include_frozen=True),
    include_frozen=True)

to

self.parameter_vector = metric.get_parameter_vector(include_frozen=True)

in metrics.Metric when metric is a metrics.Metric instance fixes this problem.

StijnDebackere added a commit to StijnDebackere/george that referenced this issue Jul 22, 2020
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

1 participant