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

Example from JOSS paper lags forever with reasonable dimensions #25

Closed
gdalle opened this issue Jan 6, 2025 · 11 comments
Closed

Example from JOSS paper lags forever with reasonable dimensions #25

gdalle opened this issue Jan 6, 2025 · 11 comments

Comments

@gdalle
Copy link
Contributor

gdalle commented Jan 6, 2025

The following example from the paper runs in very small dimension, but even for moderately-sized settings it lags forever (> 1 min). I tested it on a very bulky Macbook Pro so I really don't think the problem comes from the hardware. Do you have any clue why it is so slow?

using ExpFamilyPCA, Distributions

indim, outdim, n1 = 10, 5, 100

sample_from_gamma(n, m) = rand(Gamma(), n, m)

G(θ) = -log(-θ)
g(θ) = -1 / θ
gamma_epca = EPCA(indim, outdim, G, g, Val((:G, :g)); options = NegativeDomain())

X = sample_from_gamma(n1, indim)  # matrix of gamma-distributed data

X_compressed = fit!(gamma_epca, X)
@FlyingWorkshop
Copy link
Collaborator

Let me see, I'll do some testing now.

@FlyingWorkshop
Copy link
Collaborator

@gdalle, it appears to be a performance issue caused by a difficult loss landscape. The initial loss falls quickly (as expected), but slows down both in iteration and loss improvement. A solution could be adding early stopping, patience, or trying to get the package to better harness hardware.

using ExpFamilyPCA, Distributions

indim, outdim, n1 = 10, 5, 100

sample_from_gamma(n, m) = rand(Gamma(), n, m)

G(θ) = -log(-θ)
g(θ) = -1 / θ
gamma_epca = EPCA(indim, outdim, G, g, Val((:G, :g)); options = NegativeDomain())
X_compressed = fit!(gamma_epca1, X; verbose=true, steps_per_print=1)
julia> include("arena/epca/gamma_joss.jl")
Iteration: 1/100 | Loss: 96.55726454550793
Iteration: 2/100 | Loss: 96.5354008090762
Iteration: 3/100 | Loss: 96.5351939262657
Iteration: 4/100 | Loss: 96.53519151957907
Iteration: 5/100 | Loss: 96.5351914867849
Iteration: 6/100 | Loss: 93.6300590564199
Iteration: 7/100 | Loss: 81.77055667230692
Iteration: 8/100 | Loss: 76.85946370416866
Iteration: 9/100 | Loss: 74.92081719717324
Iteration: 10/100 | Loss: 74.05334898285854
Iteration: 11/100 | Loss: 73.70765717101862
Iteration: 12/100 | Loss: 73.51276079911916
Iteration: 13/100 | Loss: 73.29055526155825
Iteration: 14/100 | Loss: 73.1023643277939
Iteration: 15/100 | Loss: 72.97495140644317
Iteration: 16/100 | Loss: 72.89544144073695
Iteration: 17/100 | Loss: 72.76572894587677
Iteration: 18/100 | Loss: 72.66082215233749

@gdalle
Copy link
Contributor Author

gdalle commented Jan 6, 2025

My bad, I should have switched on verbose mode. I forgot that we were solving a possibly challenging optimization problem. Perhaps a warning would be appropriate, telling users that the default fit! may be long and that they can play with verbosity or iteration number?

@FlyingWorkshop
Copy link
Collaborator

No worries, very valid concern. I can add a disclaimer to the documentation now.

@gdalle
Copy link
Contributor Author

gdalle commented Jan 6, 2025

Also, if you add a yield() at the end of every iteration (or every couple of iterations), users will be able to interrupt optimization without spamming ctrl+c and eventually crashing their REPL

@gdalle
Copy link
Contributor Author

gdalle commented Jan 6, 2025

Try it, it's life-changing

@FlyingWorkshop
Copy link
Collaborator

Just added a disclaimer :)

@FlyingWorkshop
Copy link
Collaborator

Will look into yield now too

@FlyingWorkshop
Copy link
Collaborator

I added the yields. I'm not familiar w/ this mechanic of Julia, so I'm not sure if this accomplishes the desired result, but it does seem to let me ctrl+c in the middle of fit! w/o crashing the repo, which is the desired behavior.

@FlyingWorkshop
Copy link
Collaborator

What do you think @gdalle?

@gdalle
Copy link
Contributor Author

gdalle commented Jan 6, 2025

Looks good! Let's close this one

@gdalle gdalle closed this as completed Jan 6, 2025
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

2 participants