setting seed for Monte Carlo
Does sage seriously not have the ability to change the seed for a Monte Carlo execution? I assumed there is at some way to pass the time, or some other seed generator, to the algorithm.
f(x)=ln(x)
for i in range(10):
I=monte_carlo_integral(f,[0],[1],100000, algorithm='plain')
print(I[0])
-1.0002232192476281
-1.0002232192476281
-1.0002232192476281
-1.0002232192476281
-1.0002232192476281
-1.0002232192476281
-1.0002232192476281
-1.0002232192476281
-1.0002232192476281
-1.0002232192476281
EDIT: Based on a helpful comment: randstate is apparently not impacting the Monte Carlo routines.
I=monte_carlo_integral(f,[0],[1],100000, algorithm='plain')
print(I[0])
from sage.misc.randstate import randstate
r = randstate(54321)
print(r.seed())
I=monte_carlo_integral(f,[0],[1],100000, algorithm='plain')
print(I[0])
r = randstate()
print(r.seed())
I=monte_carlo_integral(f,[0],[1],100000, algorithm='plain')
print(I[0])
-1.0002232192476281
54321
-1.0002232192476281
305159320933427511743223216889072415483
-1.0002232192476281
Any other thoughts?
The random component is initialized inside the code of the function, the relevant lines are:
So in order to have access to the randomizer, we need to go deep into the cython tunnel.
Why is it important to have a random component?
It's one of the basic methods to determine the statistical errors around a MC calculation. Run N times (with N different seeds) to find an average and standard deviation. You can check for Guassianity also, for example. I can't argue for how complicated implementation would be, but assuming Gaussian statistics limits the relevance of the implementation. Mathematica allows seed changes right at the cli, if that matters. Shall I file a feature request?