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

Passing data to function #79

Closed
fintzij opened this issue Feb 3, 2022 · 4 comments
Closed

Passing data to function #79

fintzij opened this issue Feb 3, 2022 · 4 comments

Comments

@fintzij
Copy link

fintzij commented Feb 3, 2022

Hello,

I have a function that I would like to integrate repeatedly but which depends on data whose values might change. Is there a way to specify a function in Quadrature.jl such that I don't need to create a new QuadratureProblem each time the values of the data change?

For example, is there a way to pass f(x, p, d) = sum(sin.(x * p + d)) so that I could change the value of d in an outer loop and just call solve() instead of creating a new QuadratureProblem each time?

Apologies in advance if this is obvious and there is something trivial I am overlooking.

Thanks,
Jon

@ChrisRackauckas
Copy link
Member

So d is the parameter? Why not make the parameters p?

@fintzij
Copy link
Author

fintzij commented Feb 4, 2022

So, for a bit more context, this is part of a statistical package. d are data in the sense that the values are known, not estimated, like covariates. p are parameters that are being estimated, so, e.g., we would want autodiff to be taking gradients with respect to p but not d. Zooming out a bit, d might be a row in a dataset that we want to pass as an argument to f()

@fintzij
Copy link
Author

fintzij commented Feb 4, 2022

One more point is that we'd like to handle the data with some abstraction so that we have a general modeling framework. Obviously, it is trivial to hard code the values when they're known ahead of time.

@ChrisRackauckas
Copy link
Member

You can use a closure then. f(x, p) = sum(sin.(x * p + d)) just enclose

@fintzij fintzij closed this as completed Feb 4, 2022
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