Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7230 Discussions

Obtaining State values in Random Number Generators

dsavio
Beginner
1,131 Views

I find myself frustrated that the only way to save states in the RNG's seems to be to write to a file, or to use the vslCopyStreamState function to another allocated stream.

I want to be able to view the actual "seed" values (ie. the states). Is there ANY way to do this? I find that even if I use the SaveStatesF to save to a file, the data in the file does not look like the state values at all. (For example, for the Mersenne Twister generator, i initialize all 625 states to 1, but when i write it to a file, i do not see anything even close to all 1's).

I would be very interested in a way to view the states especially without writing to a file! Is this possible?

0 Kudos
7 Replies
Andrey_N_Intel
Employee
1,131 Views

We want to avoid users directly accessing VSL internal data structures. Can you please highlight the reasons for which you would like to have an access to the state of the generators? Initialization of VSL RNGs is done according to description in VSL Notes. In particular, initialization of Mersenne Twister RNG is based on description in Sections 8.4.6.3 and 8.4.6.4.

0 Kudos
dsavio
Beginner
1,131 Views
I am writing a function for aninterpreted language that produces random numbers (like matlab's rand function). The user may want to see what the current random seed/seeds are, and this is reasonable. I don't understand why this is so hidden in MKL.
0 Kudos
Andrey_N_Intel
Employee
1,131 Views

We still would like to better understand why user may need access to internal data structures. Could you please shed a light on possible usage scenarios? PRNG state structure varies from generator to generator. Those structures may be quite complicated and impractical from usage perspective.

0 Kudos
dsavio
Beginner
1,131 Views
Just to elaborate: I can understand not wanting users to muck with the underlying data structures. But specificially the seed values: Why not allow access to these? Why are there not get and set-state functions? The fact that I have to allocate a new RNG when I want to re-seed is looney. The fact that I can only save-state to another allocated RNG, and not some array of int's (or whatever seed values the RNG requires) also limits functionality.
0 Kudos
dsavio
Beginner
1,131 Views

Lets look at the Matlab/Octave rand function as an example. If you call rand('state'), it returns the state of the random number generator (ie. a vector of the seed values). With the Intel MKL, there is absolutely no way to know what the current seed values are.

Why would the user want this? Well, a better question is why not? I might want to take these seed values and feed them to another non-MKL RNG. The point is, why restrict it?

0 Kudos
Sergey_M_Intel2
Employee
1,131 Views

It is impossible to feed stream state values to non-MKL RNG without knowing exactly the internal format of the MKL stream state structure. Even if MKL and non-MKL generatorare based onthe same algorithm, the fields of stream state structure may still be different (e.g. be in different order). As we indicated earlier, we don't document details of internal structures as a) those structures may be quite complicated for understanding without giving implementation details; b) the format of the structures is optimized for performance and it is IP we don't really want to disclose.

If the only objectiveis to get RNG stream state as integers, I believe MKL provides you the required features. First, the vslGetBrngProperties allows to extract the information about stream state size (in bytes). Second, MKL manual documents general format of the stream state in section Formats for User-Designed Generators. According to this section the stream state data starts with16 bytes offset. Suppose now you have some stream s and you want get its state as array of integers. The only thing you have to do is to interpret data pointed by s as array of integers.

Please let us know if it addresses your issue.

Thanks,

Sergey

0 Kudos
dsavio
Beginner
1,131 Views

Thanks for the reply. Copying the memory starting at 16 bytes offset from the stream state pointer seems to work for me.

0 Kudos
Reply