cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Toggle main menu visibility
Main Page
Related Pages
Packages
Package List
Package Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
x
y
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
x
y
Variables
Typedefs
Enumerations
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
p
q
r
s
t
u
v
w
x
y
z
Typedefs
Enumerations
Enumerator
b
c
d
e
g
h
i
l
m
n
p
r
t
u
w
x
y
z
Related Symbols
d
g
h
o
u
v
Files
File List
File Members
All
_
a
b
c
d
e
h
o
p
r
s
Functions
Variables
Macros
_
b
c
d
e
p
r
s
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Loading...
Searching...
No Matches
Torchquad.py
Go to the documentation of this file.
1
6
7
import
torch
8
import
numpy
as
np
9
from
torchquad
import
MonteCarlo, set_up_backend
10
11
12
set_up_backend(
'torch'
, data_type=
'float32'
)
13
14
15
def
integrate(f, num_dim: int, num_iter: int, num_warmup: int, num_calls: int, limits: list[tuple[float]]=[]):
16
limits = limits
if
len(limits) > 0
else
num_dim * [(0., 1.)]
17
18
def
func(xarr):
19
return
torch.from_numpy(np.array([f([float(x)
for
x
in
xvals])
for
xvals
in
xarr.numpy()]))
20
21
mc = MonteCarlo()
22
res = mc.integrate(func, dim=num_dim, N=num_calls, integration_domain=limits, backend=
'torch'
)
23
return
(float(res.numpy()), 1.)
24
25
26
if
__name__ ==
'__main__'
:
27
import
math
28
print(integrate(
lambda
x: x[0]**2 + x[1]**2, 2, 10, 1000, 1000))
29
print(integrate(
lambda
x: math.sin(x[0]), 1, 10, 1000, 1000, [(0, math.pi)]))
python
IntegrationAlgos
Torchquad.py
Generated on Mon Jul 29 2024 for CepGen by
1.9.7