ycwu1030 / CIGAR

Implementation of VEGAS/VEGAS+ Algorithm in C++
MIT License
4 stars 0 forks source link

VEGAS_Stratify Counts, JF and JF2 accumulation #1

Open FHof opened 2 years ago

FHof commented 2 years ago

When I compared VEGAS+ implementations, I noticed that the Counts, JF and JF2 are reset to zero after each iteration in the VegasFlow and original gplepage implementations, while in the code in this repository they are accumulated and set to zero only once in the initialisation. I opened this issue because I doubt that this behaviour is intentional. Calculating an approximate variance from values of all previous iterations could work badly because a VEGAS_Map update changes which parts of the integration domain the hybercubes cover.

Additional Information

Relevant code in VegasFlow: https://github.com/N3PDF/vegasflow/blob/21209c928d07c00ae4f789d03b83e518621f174a/src/vegasflow/vflowplus.py#L202 In VegasFlow the variance is directly calculated with vectorized Tensorflow operations

Relevant code in gplepage vegas: https://github.com/gplepage/vegas/blob/11f67af45c8fc5c8c25060f18a61137274a64789/src/vegas/_vegas.pyx#L1645 In gplepage vegas the variance is a covariance matrix because it supports integrands which output a vector for each sample point.

torchquad's VEGAS+ implementation is based on code from this repository. There a code rewrite happened after which only Counts but not JF and JF2 were accumulated: https://github.com/ESA/torchquad/commit/154aa7220377ddcbd28c4c617162a2c64d33cb8a#diff-043ebca7e1b0e1177dca8d0ce7bca0efc00f0a68c90edeea6b272ff39505e0e2L41

I'm not sure if my descriptions about what happens in these four implementations is correct or if I made a mistake. I did not execute all the code to test my assumptions.

ycwu1030 commented 2 years ago

Hey: Thanks for pointing this out. It should be better to reset JF JF2 and counts every iteration. I shall modify the behavior in later version. Thanks!