Skip to content

Commit

Permalink
ConstantKernel bug + minor typos
Browse files Browse the repository at this point in the history
Multiplying by a constant normally adds an extra parameter from the ConstantKernel, which breaks the code; we need to call ConstantKernel directly and specify that this should be an immutable parameter.
  • Loading branch information
peterkentkiernan committed Jul 28, 2023
1 parent d80d7e6 commit f37f012
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions treegp/two_pcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def get_correlation_length_matrix(size, e1, e2):
:param size: Correlation lenght of the kernel.
:param e1, e2: Shear applied to isotropic kernel.
"""
if abs(e1)>1 or abs(e2)>1:
raise ValueError('abs value of e1 and e2 must be lower than one')
e = np.sqrt(e1**2 + e2**2)
if e>1:
raise ValueError('magnitude of e must be lower than one')
q = (1-e) / (1+e)
phi = 0.5 * np.arctan2(e2,e1)
rot = np.array([[np.cos(phi), np.sin(phi)],
Expand Down Expand Up @@ -92,15 +92,15 @@ def _model_skl(self, sigma, corr_length, g1, g2):
from sklearn kernel.
:param sigma: Standard deviation of the gaussian random field.
:param corr_length: Correlation lenght of the kernel.
:param corr_length: Correlation length of the kernel.
:param g1, g2: Shear applied to isotropic kernel.
"""
if abs(g1)>1 or abs(g2)>1:
if (g1**2 + g2**2)>1:
return None
else:
L = get_correlation_length_matrix(corr_length, g1, g2)
invLam = np.linalg.inv(L)
kernel_used = sigma**2 * self.kernel_class(invLam=invLam)
kernel_used = sklearn.gaussian_process.kernels.ConstantKernel(sigma**2,constant_value_bounds = "fixed") * self.kernel_class(invLam=invLam)
pcf = kernel_used.__call__(self.coord,Y=np.zeros_like(self.coord))[:,0]
self.kernel_fit = kernel_used
return pcf
Expand Down Expand Up @@ -194,7 +194,7 @@ def minimize_minuit(self, p0 = [3000., 0.2, 0.2]):

class two_pcf(object):
"""
Fit statistical uncertaintie on two-point correlation function using bootstraping.
Fit statistical uncertainty on two-point correlation function using bootstraping.
:param X: Coordinates of the field. (n_samples, 1 or 2)
:param y: Values of the field. (n_samples)
Expand Down

0 comments on commit f37f012

Please sign in to comment.