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

to_dict() and from_dict() methods for Periodic Kernel #976

Open
wants to merge 36 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ba050da
new: added to_dict() method to Coregionalize kernel class
gehbiszumeis Oct 27, 2021
fcb43ce
new: added to_dict() method to MixedNoise likelihood class
gehbiszumeis Oct 27, 2021
4de3fdd
fix: made Y_metadata dict content serializable
gehbiszumeis Oct 27, 2021
f79144b
fix: typo
gehbiszumeis Oct 27, 2021
4c3c2ac
added additional needed parameters to to_dict() method for Coregional…
gehbiszumeis Oct 29, 2021
49e272c
new: added possibility to build MixedNoise likelihood from input_dict
gehbiszumeis Oct 29, 2021
a133947
Y_metadata conversion from serializable to np.array when loading from…
gehbiszumeis Oct 29, 2021
1b8b649
fix: rework Y_metadata part for compatibility with unittests !minor
gehbiszumeis Oct 29, 2021
f4409e0
conda cleanup in appveyors pipeline
gehbiszumeis Nov 24, 2021
67a4813
conda clean up after conda update
gehbiszumeis Nov 24, 2021
73960b4
conda clean before conda update
gehbiszumeis Nov 24, 2021
7f4ce5f
try pinning packages for conda
gehbiszumeis Nov 25, 2021
4567ddf
revert all conda changes
gehbiszumeis Nov 25, 2021
5f02717
conda clean all (not only packages)
gehbiszumeis Nov 25, 2021
cd783a1
use conda update anaconda
gehbiszumeis Nov 25, 2021
9c9dfb2
pin conda package
gehbiszumeis Nov 25, 2021
289a15c
pin conda package
gehbiszumeis Nov 25, 2021
4d9f9e8
try installing charset-normalizer beforehand
gehbiszumeis Nov 25, 2021
517108a
try to get from conda-forge
gehbiszumeis Nov 25, 2021
0dc988b
revert all conda changes
gehbiszumeis Nov 25, 2021
cd6e9b5
Try to fix the conda update challange.
ppk42 Nov 25, 2021
9c0c167
Still fixing build error on appveyor
ppk42 Nov 25, 2021
62f88ff
Update appveyor.yml
ppk42 Nov 25, 2021
77f9f46
Merge pull request #1 from ppk42/devel
gehbiszumeis Nov 26, 2021
77ea10b
revert miniconda versioning changes
gehbiszumeis Nov 26, 2021
c84d968
adjust GPy version in appveyor.yml
gehbiszumeis Nov 26, 2021
a633064
1st attempt bring the appveyor build to life again
Nov 27, 2021
299b3b0
#955 fixing ci build on appveyor
Nov 28, 2021
a93c4ac
#955 Fix CI build
Nov 28, 2021
23aae96
add: built_from_dict method for White Kernel
gehbiszumeis Dec 1, 2021
4286501
Merge pull request #2 from ppk42/devel
gehbiszumeis Dec 1, 2021
5c587e9
docstring typo fix
gehbiszumeis Dec 14, 2021
ebad34a
to and & from_dict method for periodic kernel
gehbiszumeis Dec 23, 2021
aa9a2ee
typo fix
gehbiszumeis Jan 19, 2022
f161325
saving W_rank variable in from_dict method for Coregionalization kern…
gehbiszumeis Feb 23, 2022
ce2b154
Merge remote-tracking branch 'upstream/devel' into devel
gehbiszumeis Mar 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion GPy/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def randomize(self, rand_gen=None, *args, **kwargs):
Make this draw from the prior if one exists, else draw from given random generator

:param rand_gen: np random number generator which takes args and kwargs
:param flaot loc: loc parameter for random number generator
:param float loc: loc parameter for random number generator
:param float scale: scale parameter for random number generator
:param args, kwargs: will be passed through to random number generator
"""
Expand Down
1 change: 1 addition & 0 deletions GPy/kern/src/coregionalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def to_dict(self):
input_dict["W"] = self.W.values.tolist()
input_dict["kappa"] = self.kappa.values.tolist()
input_dict["output_dim"] = self.output_dim
input_dict["rank"] = self.rank
return input_dict

@staticmethod
Expand Down
25 changes: 25 additions & 0 deletions GPy/kern/src/periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def f(x):
return alpha*np.cos(omega*x + phase)
return f

def _save_to_input_dict(self):
input_dict = super(Periodic, self)._save_to_input_dict()
input_dict["variance"] = self.variance.values.tolist()
input_dict["lengthscale"] = self.lengthscale.values.tolist()
input_dict["period"] = self.period.values.tolist()
return input_dict

@silence_errors
def _cos_factorization(self, alpha, omega, phase):
r1 = np.sum(alpha*np.cos(phase),axis=1)[:,None]
Expand Down Expand Up @@ -200,6 +207,24 @@ def parameters_changed(self):
self.G = self.Gram_matrix()
self.Gi = np.linalg.inv(self.G)

def to_dict(self):
"""
Convert the object into a json serializable dictionary.

Note: It uses the private method _save_to_input_dict of the parent.

:return dict: json serializable dictionary containing the needed information to instantiate the object
"""

input_dict = super(PeriodicMatern32, self)._save_to_input_dict()
input_dict["class"] = "GPy.kern.PeriodicMatern32"
return input_dict

@staticmethod
def _build_from_input_dict(kernel_class, input_dict):
useGPU = input_dict.pop('useGPU', None)
return kernel_class(**input_dict)

def Gram_matrix(self):
La = np.column_stack((self.a[0]*np.ones((self.n_basis,1)),self.a[1]*self.basis_omega,self.a[2]*self.basis_omega**2))
Lo = np.column_stack((self.basis_omega,self.basis_omega,self.basis_omega))
Expand Down
2 changes: 1 addition & 1 deletion GPy/models/gp_coregionalized_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GPCoregionalizedRegression(GP):
:type likelihoods_list: None | a list GPy.likelihoods
:param name: model name
:type name: string
:param W_rank: number tuples of the corregionalization parameters 'W' (see coregionalize kernel documentation)
:param W_rank: number tuples of the coregionalization parameters 'W' (see coregionalize kernel documentation)
:type W_rank: integer
:param kernel_name: name of the kernel
:type kernel_name: string
Expand Down
2 changes: 1 addition & 1 deletion GPy/models/sparse_gp_coregionalized_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SparseGPCoregionalizedRegression(SparseGP):

:param name: model name
:type name: string
:param W_rank: number tuples of the corregionalization parameters 'W' (see coregionalize kernel documentation)
:param W_rank: number tuples of the coregionalization parameters 'W' (see coregionalize kernel documentation)
:type W_rank: integer
:param kernel_name: name of the kernel
:type kernel_name: string
Expand Down
2 changes: 1 addition & 1 deletion GPy/util/multioutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def ICM(input_dim, num_outputs, kernel, W_rank=1,W=None,kappa=None,name='ICM'):
:num_outputs: Number of outputs
:param kernel: kernel that will be multiplied by the coregionalize kernel (matrix B).
:type kernel: a GPy kernel
:param W_rank: number tuples of the corregionalization parameters 'W'
:param W_rank: number tuples of the coregionalization parameters 'W'
:type W_rank: integer
"""
if kernel.input_dim != input_dim:
Expand Down