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

Multiple Integrands Simultaneously #27

Closed
dsmic opened this issue Nov 23, 2022 · 4 comments
Closed

Multiple Integrands Simultaneously #27

dsmic opened this issue Nov 23, 2022 · 4 comments

Comments

@dsmic
Copy link

dsmic commented Nov 23, 2022

I get into problems, if I integrate functions simultaneously, which have very different function values:

import vegas

integrator = vegas.Integrator([[0, 1], [0, 1]])

def f(x):
    return [1,1e60]

result = integrator(f, nitn=10, neval=1000)

print(result.summary())

print(result)

gives the following output:

itn   integral         wgt average     chi2/dof        Q
--------------------------------------------------------
  1   1.0000000000(15) 0(0)                0.00     1.00
  2   1.0000000000(18) 0(0)                 nan      nan
  3   1.0000000000(22) 0(0)                 nan      nan
  4   1.0000000000(22) 0(0)                 nan      nan
  5   1.0000000000(21) 0(0)                 nan      nan
  6   1.0000000000(21) 0(0)                 nan      nan
  7   1.0000000000(20) 0(0)                 nan      nan
  8   1.0000000000(20) 0(0)                 nan      nan
  9   1.0000000000(22) 0(0)                 nan      nan
 10   1.0000000000(22) 0(0)                 nan      nan

[0(0) 1.00000000000(63)e+60]

Any idea, what is happening here?

@gplepage
Copy link
Owner

This is due to roundoff error in the weighted average of results. I can fix this but it will be several days before I can get to it.

If you need it to work right now, one possibility is to install the lsqfit module and use lsqfit.wavg(result.itn_results) for the weighted average:

import vegas
import lsqfit 

integrator = vegas.Integrator([[0, 1], [0, 1]])
def f(x):
   return [1, 1e60]

result = integrator(f, nitn=10, neval=1000)

print(result.summary())

print(result)

answer = lsqfit.wavg(result.itn_results)
print(answer, 'chi2/dof =', answer.chi2/answer.dof)

This prints out the following, with the correct answer in the final line:

itn   integral         wgt average     chi2/dof        Q
--------------------------------------------------------
  1   1.0000000000(15) 0(0)                0.00     1.00
  2   1.0000000000(19) 0(0)                 nan      nan
  3   1.0000000000(21) 0(0)                 nan      nan
  4   1.0000000000(21) 0(0)                 nan      nan
  5   1.0000000000(22) 0(0)                 nan      nan
  6   1.0000000000(21) 0(0)                 nan      nan
  7   1.0000000000(22) 0(0)                 nan      nan
  8   1.0000000000(20) 0(0)                 nan      nan
  9   1.0000000000(21) 0(0)                 nan      nan
 10   1.0000000000(22) 0(0)                 nan      nan

[0(0) 1.00000000000(64)e+60]
[1.00000000000(64) 1.00000000000(64)e+60] chi2/dof = 2.768095398562126e-12

Thanks for pointing out the problem.

@dsmic
Copy link
Author

dsmic commented Nov 24, 2022

Thanks a lot for the very quick reply! I do not really understand, how the implemented averaging works to produce such kind of roundoff error, but ...

Not a problem at the moment, but in my real live problem I get

mean field itn   integral        wgt average     chi2/dof        Q
-------------------------------------------------------
  1   4.752(35)e+11   0(0)                0.00     1.00
  2   4.732(32)e+11   0(0)                1.32     0.26
  3   4.768(31)e+11   0(0)                0.71     0.69
  4   4.767(30)e+11   0(0)                0.48     0.93
  5   4.774(30)e+11   0(0)                0.37     0.99
  6   4.783(29)e+11   0(0)                0.33     1.00
  7   4.761(27)e+11   0(0)                0.28     1.00
  8   4.775(27)e+11   0(0)                0.25     1.00
  9   4.728(28)e+11   0(0)                0.22     1.00
 10   4.805(27)e+11   0(0)                0.20     1.00

Test: 11:07:38 mean field [0(0) 0(0) 0(0) 6.055(79)e+63]
lsqfit [4.7646(91)e+11 3.8674(72)e+13 3.91281225(13)e+13
 6.107230208142814475991144718136638402938842773437500000000000000000000000000000000000000000000000000000000(23)e+63]

There is no way I believe the error estimate of the 4. integrand :)

May I ask: is there an easy way to install vegas to use the pyx file (instead of the c file) for debugging (understanding) proposes?

@gplepage
Copy link
Owner

gplepage commented Jan 6, 2023

This is fixed in v5.4 of vegas (which I just uploaded). Thanks for pointing out the problem.

@gplepage
Copy link
Owner

I am closing this issue because v5.4 of vegas addresses it. Running the code you posted above now gives the following greatly improved result:

itn   integral         wgt average       chi2/dof        Q
----------------------------------------------------------
  1   1.0000000000(15) 1.0000000000(15)      0.00     1.00
  2   1.0000000000(18) 1.0000000000(12)      0.00     1.00
  3   1.0000000000(21) 1.0000000000(10)      0.00     1.00
  4   1.0000000000(20) 1.00000000000(90)     0.00     1.00
  5   1.0000000000(21) 1.00000000000(83)     0.00     1.00
  6   1.0000000000(21) 1.00000000000(77)     0.00     1.00
  7   1.0000000000(21) 1.00000000000(72)     0.00     1.00
  8   1.0000000000(21) 1.00000000000(68)     0.00     1.00
  9   1.0000000000(22) 1.00000000000(65)     0.00     1.00
 10   1.0000000000(22) 1.00000000000(63)     0.00     1.00

[1.00000000000(63) 1.00000000000(63)e+60]

Thanks again for pointing out the problem.

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