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

Integrate function with parameters #187

Closed
omashkova opened this issue Oct 2, 2023 · 3 comments
Closed

Integrate function with parameters #187

omashkova opened this issue Oct 2, 2023 · 3 comments

Comments

@omashkova
Copy link

Hi, I would like to know whether there is functionality for integrating functions with parameters. For example, if one has a function

def func(alpha, x):
    return x**2 * alpha

how can one apply Trapezoid rule to integrate over x, for example? In the docs there is information about additional arguments of functions in BaseIntegrator class, but it seems like it is always set to None when applied to concrete methods.

If there is no such option, one may add something like args=(alpha,) to Trapezoid.integrate() or any other method.

Thanks in advance!

@gomezzz
Copy link
Collaborator

gomezzz commented Oct 2, 2023

Hi @omashkova , thanks for the question!

So, this should already be implemented.

Either you can use this feature or maybe define your integrand can just be defined with a lambda function ?

More concretly, the latter can be done via:

import torchquad as tq

def func(alpha, x):
    return x**2 * alpha

tp = tq.Trapezoid()

tp.integrate(lambda x: func(alpha=3,x), dim=1, N=100)

this however, does not parallelize over different alpha. For that, you need the above linked feature.

Does this help? :)

@omashkova
Copy link
Author

Hi @gomezzz, yes, this is very helpful, thank you!

@gomezzz
Copy link
Collaborator

gomezzz commented Oct 3, 2023

Perfect 💪 I will close this for now then. :)

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