Ask Your Question
1

Seed - probability distribution functions

asked 2013-06-05 11:38:47 -0600

mresimulator gravatar image

updated 2013-06-05 11:50:07 -0600

tmonteil gravatar image

Hello experts!

In a new user of sage.

This is a triple-question for you:

1) Reading the 'Craig Finch Sage Beginners Guide' page 236 I find the next script (about accessing probability distribution functions):

variance = 0.75
gaussian = RealDistribution('gaussian', variance)
gaussian.set_seed(0.0)
random_values = [gaussian.get_random_element() for i in range(1000)]
gaussian_plot = gaussian.plot((-5, 5))

The 1st question is ¿Whats for gaussian.set_seed(0.0)? ¿What does (0.0) seed value minds?

2) ¿What must i write in a script for obtain a normal (gaussian) distribution center in 'C' with variance 'V'?

3) Again, in 'Craig Finch Sage Beginners Guide' page 305 i find:

rng = RealDistribution('uniform', [0,dimension], seed=1)

¿Whats for seed=1 value? ¿What does 1 seed value minds?

Waiting for your answers.

Thaks a lot!!

edit retag flag offensive close merge delete

4 answers

Sort by » oldest newest most voted
2

answered 2013-06-05 12:36:01 -0600

tmonteil gravatar image

updated 2013-06-05 12:42:59 -0600

Looking to the documentation:

sage: RealDistribution?

there seems not to be a parameter to fix the center of a Gaussian distribution. But you can do the translation by yourself:

sage: center = 2
sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: centered_random_values = [gaussian.get_random_element() + center for i in range(1000)]
sage: centered_distribution_function = lambda x : gaussian.distribution_function(x-center)
sage: plot(centered_distribution_function,(-5,5))
edit flag offensive delete link more

Comments

Yes, this is unfortunate. I feel like we have a ticket for this (it's certainly known) but I couldn't find it right away - it may be part of one of the other tickets about the `RealDistribution` stuff.

kcrisman gravatar imagekcrisman ( 2013-06-05 14:50:35 -0600 )edit
1

answered 2013-06-05 12:03:21 -0600

tmonteil gravatar image

updated 2013-06-05 12:24:05 -0600

A computer can not create randomness out of nothing. To build pseudo-random numbers, it needs to start from a "seed", which is assumed to be random. If you do not provide a seed, the computer will try to forge a seed that looks random, for example it will look at the keys you hit on the keyboard, the webpages that your web browser visited, the date, etc, and build a seed from that. Now, given a seed, it will use some algorithm to provide a lot of pseudo-random numbers, the randomness of this sequence of numbers will depend on the seed (a determiistic algorithm can not create randomness out of nothing).

Fixing a seed allows you to start from something you control completely, and then be able to reproduce your tests (the seed is fixed and the algorithm is deterministic). If you fix twice the same seed, you will get twice the same sequence of pseudo-random numbers:

sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: gaussian.set_seed(0.0)                   
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469
sage: gaussian.set_seed(0.0)
sage: gaussian.get_random_element()
0.100438956089
sage: gaussian.get_random_element()
-0.0660757438736
sage: gaussian.get_random_element()
1.25580630469

Now, if you do not fix a seed, and do the following from two different sage sessions, you should get different values:

sage: variance = 0.75
sage: gaussian = RealDistribution('gaussian', variance)
sage: gaussian.get_random_element()
# random number that depends on the seed that is built 
# according to the state of your computer.

If you want to write tests that need to output the same result along the time, use a fixed seed. If you want to make independent tests, don't !

edit flag offensive delete link more
0

answered 2013-06-05 14:15:22 -0600

mresimulator gravatar image

Thanks!!! Very clear.

Best regards.

edit flag offensive delete link more
0

answered 2013-06-05 12:21:18 -0600

mresimulator gravatar image

Thanks a lot!!

Only one more question: ¿What must i write in a script for obtain a normal (gaussian) distribution center in 'C' with variance 'V'?

Waiting for your answers.

Best regards!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-06-05 11:38:47 -0600

Seen: 931 times

Last updated: Jun 05 '13