You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import numpy as np
from pygam import GAM, LinearGAM
def compute_scale_two_ways():
# Parameters for the linear function
A = 0.0
B = 2.0
N = 10_000
sigma = 3.0
# Generate random x values
X = np.random.rand(N) * 100
# Generate y values with random noise
noise = np.random.normal(loc=0, scale=sigma, size=N)
y = A * X + B + noise
gam = LinearGAM()
gam.fit(X, y)
Y_out = gam.predict(X)
r = y - Y_out
scale = np.sqrt(np.mean(r**2))
return scale, gam.distribution.scale
scales_manual, scales_gam = [], []
for _ in range(100):
scale, gam_scale = compute_scale_two_ways()
scales_manual.append(scale)
scales_gam.append(gam_scale)
print(f"Manual Estimate of Scale: {np.mean(scales_manual):.3f} +/- {np.std(scales_manual):.3f}")
print(f"GAM Estimate of Scale: {np.mean(scales_gam):.3f} +/- {np.std(scales_gam):.3f}")
which on my machine returns
Manual Estimate of Scale: 2.996 +/- 0.019
GAM Estimate of Scale: 8.990 +/- 0.112
Which shows the issue, given the standard deviation of the noise term is 3. Having an incorrect scale then means that the log-likelihood is computed incorrectly and possibly other quantities too.
The scale parameter, if not provided is set as
phi
here https://github.com/dswah/pyGAM/blob/v0.9.1/pygam/pygam.py#L1038-L1041. The issue here is thatphi
should represent the variance andscale
the standard deviation, broadly speaking.Here is some code that replicates the issue
which on my machine returns
Which shows the issue, given the standard deviation of the noise term is 3. Having an incorrect scale then means that the log-likelihood is computed incorrectly and possibly other quantities too.
I believe this may be the root issue of #163
The text was updated successfully, but these errors were encountered: