Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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?