C-bowman / inference-tools

Python tools for Bayesian data analysis
MIT License
28 stars 3 forks source link

Can't use composite kernel with 2d data #27

Closed RemDelaporteMathurin closed 1 year ago

RemDelaporteMathurin commented 1 year ago

I try to use a composite kernel as in the GPR example on a 2d space. However it doesm't work:

data = np.genfromtxt("data/step_results.csv", delimiter=",", names=True)

# train the GP model on the observed data
composite_kernel = SquaredExponential() + WhiteNoise()

training_points = [(tau, eta) for tau, eta in zip(data["tau_bzs"], data["eta_TES"])]
GP = GpRegressor(training_points, data["TBR"], kernel=composite_kernel )

this produces:

Traceback (most recent call last):
  File "c:\Fuel Cycle Modelling\fc-results\step_results.py", line 23, in <module>
    mu, sig = GP(gp_coords)
  File "C:\Users\remidm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\inference\gp.py", line 217, in __call__
    K_qx = self.cov(q, self.x, self.cov_hyperpars)
  File "C:\Users\remidm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\inference\covariance.py", line 82, in __call__      
    return sum(
ValueError: operands could not be broadcast together with shapes (1,100) (2,200)

Am I missing anything?

Thanks Chris!

C-bowman commented 1 year ago

Hi Rémi,

I looked into this and it was actually a bug in the WhiteNoise kernel which only affects multi-dimensional data. The automated testing missed it because I only had tests with 1D data (those are now expanded to 2D as well).

I've fixed the bug, and I'll publish a new release today - if it fixes the problem on your end let me know and I'll close the issue.

Thanks for posting the bug!

RemDelaporteMathurin commented 1 year ago

Awesome thank you! Let me know :-)

RemDelaporteMathurin commented 1 year ago

I confirm the last release fixed the issue! Thanks Chris!