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

monte_carlo_integral looks deterministic #32456

Open
sagetrac-tmonteil mannequin opened this issue Sep 2, 2021 · 2 comments
Open

monte_carlo_integral looks deterministic #32456

sagetrac-tmonteil mannequin opened this issue Sep 2, 2021 · 2 comments

Comments

@sagetrac-tmonteil
Copy link
Mannequin

sagetrac-tmonteil mannequin commented Sep 2, 2021

Tested on various computers, with various random seeds, the following invariably provides the same result:

var('x,y,z')
f = x*y*z
monte_carlo_integral(f, [0,0,0],[1,1,1], calls=1000)
(0.12001500488162796, 0.004393500801071119)

The result should depend on the current ranstate.

CC: @videlec

Component: algebra

Issue created by migration from https://trac.sagemath.org/ticket/32456

@sagetrac-tmonteil sagetrac-tmonteil mannequin added this to the sage-9.5 milestone Sep 2, 2021
@nbruin
Copy link
Contributor

nbruin commented Sep 2, 2021

comment:1

Well, it's certainly explicable: according to https://www.gnu.org/software/gsl/doc/html/rng.html the rng initialization sets up a default seed of 0 and no other seed is initialized in our code.

I don't know if the strict definition of monte carlo integration requires the use of true random numbers and/or the use of a pseudo-random generator with a non-deterministically initialized seed. The theory definitely needs it, because otherwise the probabilistic statements about accuracy could be engineered to fail for a particular integral, making use of the known sample sequence.

Fixing this is pretty simple: put a gsl_rng_set call in somewhere. The tricky bit is finding where to get the appropriate seed value from (since we still need to be able to get reproducible results)

@mkoeppe
Copy link
Member

mkoeppe commented Sep 3, 2021

comment:2

sage.misc.randstate likely needs updating.

@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 18, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 May 3, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Sep 19, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants