From: Jeff on 5 Dec 2009 16:12 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hfecsn$jdq$1(a)fred.mathworks.com>... > I believe the purpose of this line is to make sure the subsequent random generations are differences from run to run. It starts the random *seed* with the current time, so the seeds will never repeated. > > Bruno OK, that sounds right. It sounds like this command was replaced by RandStream. I'll read about that and be done in no time :D. Thanks, -Jeff
From: Peter Perkins on 6 Dec 2009 12:33 Jeff wrote: > Some code that I'm working on has the following line: > > rand('state',sum(100*clock)) > > The editor issues a warning which says "Using character strings to control RAND is deprecated. I need to understand that line, but the help on rand (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream.rand.html) does not give any information on the deprecated parms. Does anyone know where I can find info on the deprecated uses? Thanks, Jeff, first off, the deprecated syntax continues to work, exactly as it always has. So you can still use it with no harm if you want. It's just that the old syntax was not scalable going forward, and had some quirks in it that tended to confuse people without their even knowing it. The User Guide has a whole section on RandStream and random number generation, including a section on backwards compatibility. There is not a list of specific "you used to do this, now do this". However, the help does give examples that describe how to do essentially everything that the old syntax allowed. That line of code, as Bruno says, gives you different values from rand/randn/randi each time you start up MATLAB -- ordinarily, you'd get the same values. The help for rand has this to say, including an example: >> help rand RAND Uniformly distributed pseudorandom numbers. [snip] Compatibility Note: In versions of MATLAB prior to 7.7, you controlled the internal state of the random number stream used by RAND by calling RAND directly with the 'seed', 'state', or 'twister' keywords. That syntax is still supported for backwards compatibility, but is deprecated. Beginning in MATLAB 7.7, use the default stream as described in RANDSTREAM. The sequence of numbers produced by RAND is determined by the internal state of the uniform pseudorandom number generator that underlies RAND, RANDI, and RANDN. Control that default random number stream using its properties and methods. See RANDSTREAM for details about the default stream. Resetting the default stream to the same fixed state allows computations to be repeated. Setting the stream to different states leads to unique computations, however, it does not improve any statistical properties. Since MATLAB uses the same state each time it starts up, RAND, RANDN, and RANDI will generate the same sequence of numbers in each session unless the state is changed. Examples: [snip] Replace the default stream with a stream whose seed is based on CLOCK, so RAND will return different values in different MATLAB sessions. NOTE: It is usually not desirable to do this more than once per MATLAB session. RandStream.setDefaultStream(RandStream('mt19937ar','seed',sum(100*clock))); rand(1,5) and also gives links to the RandStream help page. The syntax you were being nagged about falls under the area of "controlling the random number stream". Hope this helps.
From: Peter Perkins on 6 Dec 2009 12:36 Bruno Luong wrote: > I believe the purpose of this line is to make sure the subsequent random generations are differences from run to run. It starts the random *seed* with the current time, so the seeds will never repeated. Exactly correct. The drawback, and it's not obvious until it's too late, is that unless you save that seed somewhere, you won't ever be able to go back and reproduce the same random values. In many/most cases, that's not a problem but sometimes it is.
From: Jeff on 6 Dec 2009 15:28 Peter Perkins <Peter.Perkins(a)MathRemoveThisWorks.com> wrote in message <hfgpso$rju$1(a)fred.mathworks.com>... > Jeff wrote: > > Some code that I'm working on has the following line: > > > > rand('state',sum(100*clock)) > > > > The editor issues a warning which says "Using character strings to control RAND is deprecated. I need to understand that line, but the help on rand (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream.rand.html) does not give any information on the deprecated parms. Does anyone know where I can find info on the deprecated uses? Thanks, > > Jeff, first off, the deprecated syntax continues to work, exactly as it always has. So you can still use it with no harm if you want. It's just that the old syntax was not scalable going forward, and had some quirks in it that tended to confuse people without their even knowing it. > > The User Guide has a whole section on RandStream and random number generation, including a section on backwards compatibility. There is not a list of specific "you used to do this, now do this". However, the help does give examples that describe how to do essentially everything that the old syntax allowed. > > That line of code, as Bruno says, gives you different values from rand/randn/randi each time you start up MATLAB -- ordinarily, you'd get the same values. The help for rand has this to say, including an example: > > >> help rand > RAND Uniformly distributed pseudorandom numbers. > [snip] > Compatibility Note: In versions of MATLAB prior to 7.7, you controlled > the internal state of the random number stream used by RAND by calling > RAND directly with the 'seed', 'state', or 'twister' keywords. That > syntax is still supported for backwards compatibility, but is deprecated. > Beginning in MATLAB 7.7, use the default stream as described in > RANDSTREAM. > > The sequence of numbers produced by RAND is determined by the internal > state of the uniform pseudorandom number generator that underlies RAND, > RANDI, and RANDN. Control that default random number stream using its > properties and methods. See RANDSTREAM for details about the default > stream. > > Resetting the default stream to the same fixed state allows computations > to be repeated. Setting the stream to different states leads to unique > computations, however, it does not improve any statistical properties. > Since MATLAB uses the same state each time it starts up, RAND, RANDN, and > RANDI will generate the same sequence of numbers in each session unless > the state is changed. > > Examples: > > [snip] > Replace the default stream with a stream whose seed is based on CLOCK, > so RAND will return different values in different MATLAB sessions. > NOTE: It is usually not desirable to do this more than once per MATLAB > session. > RandStream.setDefaultStream(RandStream('mt19937ar','seed',sum(100*clock))); > rand(1,5) > > and also gives links to the RandStream help page. The syntax you were being nagged about falls under the area of "controlling the random number stream". > > Hope this helps. Thanks to both Peter an Bruno. I have enough to answer the question and, if necessary, rewrite the line (actually, I might rewrite it even if it's not necessary, just because I don't like deprecated syntax).
First
|
Prev
|
Pages: 1 2 Prev: classification using neural network Next: Save plot without changing size under terminal mode |