# Seed - probability distribution functions

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?

Thaks a lot!!

edit retag close merge delete

Sort by » oldest newest most voted

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))

more

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.

( 2013-06-05 14:50:35 -0600 )edit

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 !

more

Thanks!!! Very clear.

Best regards.

more

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'?

Best regards!

more