GAMES-UChile / mogptk

Multi-Output Gaussian Process Toolkit
MIT License
161 stars 42 forks source link

Some examples not working as per recent updates #35

Closed jimmyrisk closed 2 years ago

jimmyrisk commented 2 years ago

Hi,

Some examples are not working since recent updates. For example, on 06 Custom Kernels and Mean Functions, this happens:

import mogptk
import numpy as np
4
f = lambda x: np.sin(x[:,0]*2.0*np.pi) + 2*x[:,0] - 0.2*x[:,0]**2
data = mogptk.LoadFunction(f, start=0.0, end=10.0, n=100, var=0.5)
data.plot();
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-4-3a0815686640> in <module>
      1 f = lambda x: np.sin(x[:,0]*2.0*np.pi) + 2*x[:,0] - 0.2*x[:,0]**2
----> 2 data = mogptk.LoadFunction(f, start=0.0, end=10.0, n=100, var=0.5)
      3 data.plot();

~\anaconda3\envs\gp-mort\lib\site-packages\mogptk\data.py in LoadFunction(f, start, end, n, var, name, random)
     87                 raise ValueError("start and end must have matching number or datetime data type")
     88 
---> 89     _check_function(f, input_dims, [isinstance(start[i], np.datetime64) for i in range(input_dims)])
     90 
     91     if _is_iterable(n):

~\anaconda3\envs\gp-mort\lib\site-packages\mogptk\data.py in _check_function(f, input_dims, is_datetime64)
   1243 
   1244     x = [np.array([np.datetime64('2000', 'us')]) if is_datetime64[i] else np.ones((1,)) for i in range(input_dims)]
-> 1245     y = f(x)
   1246     if len(y.shape) != 1 or y.shape[0] != 1:
   1247         raise ValueError("function must return Y with shape (n,), note that X is a list where each element is an input dimension of shape (n,)")

<ipython-input-4-3a0815686640> in <lambda>(x)
----> 1 f = lambda x: np.sin(x[:,0]*2.0*np.pi) + 2*x[:,0] - 0.2*x[:,0]**2
      2 data = mogptk.LoadFunction(f, start=0.0, end=10.0, n=100, var=0.5)
      3 data.plot();

TypeError: list indices must be integers or slices, not tuple

I noticed this in a few other examples as well. I tried a hacky solution but it ended up causing a problem in the mean function later.

tdewolff commented 2 years ago

I've fixed some other problems as well. In general, we haven't released a new version yet as we're working on some big new stuff. Usually with new versions we make sure that the examples work, but you're right that they should always be working ;-). Thanks!