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

Performance question #162

Closed
itsdfish opened this issue Feb 28, 2023 · 2 comments
Closed

Performance question #162

itsdfish opened this issue Feb 28, 2023 · 2 comments

Comments

@itsdfish
Copy link

Hi,

A few months ago, I opened an issue in DiffEqFlux about using normalizing flows to learn likelihood functions from simulated data. I noticed you have been working on this package which seems to serve a similar purpose. Out of curiosity, I tried to run the example in the README file (commit 82149d2), but stopped the program after it had been running for more than an hour. Would you expect this algorithm to require so much time for a simple problem?

@prbzrg
Copy link
Member

prbzrg commented Feb 28, 2023

Hi,

There are some performance issues, For now, we can use compute_mode=ZygoteMatrixMode and adtype=Optimization.AutoForwardDiff():

using ICNF
using Distributions, Lux
using DifferentialEquations, SciMLSensitivity
using Optimization, ForwardDiff

# Parameters
nvars = 1
n = 1024

# Data
data_dist = Beta(2.0f0, 4.0f0)
r = rand(data_dist, nvars, n)

# Model
nn = Chain(Dense(nvars => 4 * nvars, tanh), Dense(4 * nvars => nvars, tanh))
icnf = construct(RNODE, nn, nvars; tspan = (0.0f0, 4.0f0), compute_mode=ZygoteMatrixMode)

# Training
using DataFrames, MLJBase
df = DataFrame(transpose(r), :auto)
model = ICNFModel(icnf; adtype=Optimization.AutoForwardDiff())
mach = machine(model, df)
fit!(mach)
ps, st = fitted_params(mach)

# Use It
d = ICNFDist(icnf, ps, st)
actual_pdf = pdf.(data_dist, vec(r))
estimated_pdf = pdf(d, r)
new_data = rand(d, n)

# Evaluation
using Distances
mad_ = meanad(estimated_pdf, actual_pdf)
msd_ = msd(estimated_pdf, actual_pdf)
tv_dis = totalvariation(estimated_pdf, actual_pdf) / n

@itsdfish
Copy link
Author

itsdfish commented Mar 1, 2023

Thank you for your reply. I will try that.

@prbzrg prbzrg closed this as completed Mar 6, 2023
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