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

Glm calculates wrong solution #37

Open
lueckem opened this issue Feb 10, 2023 · 1 comment
Open

Glm calculates wrong solution #37

lueckem opened this issue Feb 10, 2023 · 1 comment

Comments

@lueckem
Copy link

lueckem commented Feb 10, 2023

I found that the solution calculated by Glm is not correct. (Or am I using it wrong?) Here is an example of a simple least-squares problem:

import numpy as np
from numpy.random import default_rng
from yaglm.Glm import Glm

rng = default_rng(seed=1)

num_features = 500
num_data = 2000

# y = X @ alpha + noise
X = rng.random((num_data, num_features))
alpha = rng.random(num_features)
y = X @ alpha + rng.standard_normal(num_data) / 100

model = Glm(fit_intercept=False)
model.fit(X, y)
alpha_yaglm = model.coef_

alpha_np = np.linalg.lstsq(X, y, rcond=None)[0]

loss_np = np.linalg.norm(y - X @ alpha_np)  # = 0.39
loss_yaglm = np.linalg.norm(y - X @ alpha_yaglm)  # = 0.70

As you can see the loss of the numpy least-squares solution is much smaller. The two solutions alpha_yaglm and alpha_np are approximately identical up to the first two decimals though. Maybe the yaglm solver terminates too early?

@lueckem
Copy link
Author

lueckem commented Feb 10, 2023

I found the problem: The FISTA solver indeed stopped to early. Manually setting the maximum iterations to 10 000 instead of the default 1000 and the tolerance to 1e-10 instead of the default 1e-5 produces the correct solution.

Maybe the default parameters could be changed such that simple problems like this are solved correctly by default.

Anyway, you can close this issue if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant