cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
MCint.py
Go to the documentation of this file.
1
6
7
import
mcint
8
import
random
9
import
numpy
as
np
10
11
12
def
integrate(f, num_dim: int, num_iter: int, num_warmup: int, num_calls: int, limits: list[tuple[float]]=[]):
13
limits = limits
if
len(limits) > 0
else
num_dim * [(0., 1.)]
14
jacob = np.prod([lim[1] - lim[0]
for
lim
in
limits])
15
def
sampler():
16
while
True
:
17
yield
[random.uniform(lim[0], lim[1])
for
lim
in
limits]
18
return
mcint.integrate(f, sampler(), measure=jacob, n=num_calls)
19
20
21
if
__name__ ==
'__main__'
:
22
import
math
23
print(integrate(
lambda
x: x[0]**2 + x[1]**2, 2, 10, 1000, 1000))
24
print(integrate(
lambda
x: math.sin(x[0]), 1, 10, 1000, 1000, [(0, math.pi)]))
python
IntegrationAlgos
MCint.py
Generated on Mon Jul 29 2024 for CepGen by
1.9.7