永发信息网

matlab问题 RandStream.setDefaultStream(RandStream('mt19937ar','seed',sum(clock)));

答案:3  悬赏:0  手机版
解决时间 2021-04-05 12:42
  • 提问者网友:愿为果
  • 2021-04-05 06:02
matlab问题 RandStream.setDefaultStream(RandStream('mt19937ar','seed',sum(clock)));
最佳答案
  • 五星知识达人网友:鸽屿
  • 2021-04-05 07:22
这个函数是自带的哈
是啥子原因没有查到
可以重装试试嘛
全部回答
  • 1楼网友:从此江山别
  • 2021-04-05 08:31
这个函数是matlab自带的
>> help RandStream
RANDSTREAM Random number stream.
(Pseudo)random numbers in MATLAB come from one or more random number
streams.The simplest way to generate arrays of random numbers is to use
RAND, RANDN, or RANDI.These functions all rely on the same stream of
uniform random numbers, known as the default stream.You can create other
streams that act separately from the default stream, and you can use their
RAND, RANDN, or RANDI methods to generate arrays of random numbers.You can
also create a random number stream and make it the default stream.

To create a single random number stream, use either the RandStream
constructor or the RandStream.CREATE factory method.To create multiple
independent random number streams, use RandStream.CREATE.

STREAM = RandStream.getDefaultStream returns the default random number
stream, i.e., the one currently used by the RAND, RANDI, and RANDN
functions.

PREVSTREAM = RandStream.setDefaultStream(STREAM) returns the current default
stream, and designates the random number stream STREAM as the new default to
be used by the RAND, RANDI, and RANDN functions.

A random number stream S has properties that control its behavior.Access or
assign to a property using P = S.Property or S.Property = P.

RandStream properties:
Type- (Read-only) identifies the type of generator algorithm
used by the stream.
Seed- (Read-only) the seed value used to create the stream.
NumStreams- (Read-only) the number of streams created at the same
time as the stream.
StreamIndex - (Read-only) the stream's index among the group of streams
in which it was created.
State - the internal state of the generator.You should not depend
on the format of this property.The value you assign
to S.State must be a value read from S.State previously.
Substream - the index of the substream to which the stream is
currently set.The default is 1.Multiple substreams are
not supported by all generator types.
RandnAlg- the current algorithm used by RANDN(S, ...) to generate
normal pseudorandom values, one of 'Ziggurat' (the
default), 'Polar', or 'Inversion'.
Antithetic- a logical value indicating whether S generates antithetic
uniform pseudorandom values, that is, the usual values
subtracted from 1.The default is false.
FullPrecision - a logical value indicating whether S generates values
using its full precision.Some generators are able to
create pseudorandom values faster, but with fewer random
bits, if FullPrecision is false.The default is true.

The sequence of pseudorandom numbers produced by a random number stream S is
determined by the internal state of its random number generator.Saving and
restoring the generator's internal state via the 'State' property allows you
to reproduce output.

Examples:

Create three independent streams:
[s1,s2,s3] = RandStream.create('mrg32k3a','NumStreams',3);
r1 = rand(s1,100000,1); r2 = rand(s2,100000,1); r3 = rand(s3,100000,1);
corrcoef([r1,r2,r3])

Create only one stream from a set of three independent streams:
s2 = RandStream.create('mrg32k3a','NumStreams',3,'StreamIndices',2);

Reset the generator for the default stream that underlies RAND, RANDI,
and RANDN back to the beginning to reproduce previous results:
reset(RandStream.getDefaultStream);

Save and restore the default stream's state to reproduce the output of
RAND:
defaultStream = RandStream.getDefaultStream;
savedState = defaultStream.State;
u1 = rand(1,5)
defaultStream.State = savedState;
u2 = rand(1,5) % contains exactly the same values as u1

Return RAND, RANDI, and RANDN to their default initial settings:
s = RandStream.create('mt19937ar','seed',5489);
RandStream.setDefaultStream(s);

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.
s = RandStream.create('mt19937ar','seed',sum(100*clock));
RandStream.setDefaultStream(s);

Select the algorithm that RANDN uses:
defaultStream = RandStream.getDefaultStream;
defaultStream.RandnAlg = 'inversion';

RandStream methods:
RandStream/RandStream - Create a random number stream.
create - Create multiple independent random number streams.
list - List available random number generator algorithms.
getDefaultStream - Get the default random number stream.
setDefaultStream - Set the default random number stream.
reset- Reset a stream to its initial internal state.
rand - Pseudorandom numbers from a uniform distribution.
randn- Pseudorandom numbers from a standard normal distribution.
randi- Pseudorandom integers from a uniform discrete distribution.
randperm - Random permutation.

See also randfun/rand, randfun/randn, randfun/randi.
Reference page in Help browser
doc RandStream
追问:我的没有,是因为版本太低的原因吗,还是我忘记装工具箱了
追答:是你的matlab有问题了,你重装吧,最好装个高版本的吧
  • 2楼网友:骨子里都是戏
  • 2021-04-05 07:55
这个函数是matlab自带的
>> help RandStream
RANDSTREAM Random number stream.
(Pseudo)random numbers in MATLAB come from one or more random number
streams.The simplest way to generate arrays of random numbers is to use
RAND, RANDN, or RANDI.These functions all rely on the same stream of
uniform random numbers, known as the default stream.You can create other
streams that act separately from the default stream, and you can use their
RAND, RANDN, or RANDI methods to generate arrays of random numbers.You can
also create a random number stream and make it the default stream.

To create a single random number stream, use either the RandStream
constructor or the RandStream.CREATE factory method.To create multiple
independent random number streams, use RandStream.CREATE.

STREAM = RandStream.getDefaultStream returns the default random number
stream, i.e., the one currently used by the RAND, RANDI, and RANDN
functions.

PREVSTREAM = RandStream.setDefaultStream(STREAM) returns the current default
stream, and designates the random number stream STREAM as the new default to
be used by the RAND, RANDI, and RANDN functions.

A random number stream S has properties that control its behavior.Access or
assign to a property using P = S.Property or S.Property = P.

RandStream properties:
Type- (Read-only) identifies the type of generator algorithm
used by the stream.
Seed- (Read-only) the seed value used to create the stream.
NumStreams- (Read-only) the number of streams created at the same
time as the stream.
StreamIndex - (Read-only) the stream's index among the group of streams
in which it was created.
State - the internal state of the generator.You should not depend
on the format of this property.The value you assign
to S.State must be a value read from S.State previously.
Substream - the index of the substream to which the stream is
currently set.The default is 1.Multiple substreams are
not supported by all generator types.
RandnAlg- the current algorithm used by RANDN(S, ...) to generate
normal pseudorandom values, one of 'Ziggurat' (the
default), 'Polar', or 'Inversion'.
Antithetic- a logical value indicating whether S generates antithetic
uniform pseudorandom values, that is, the usual values
subtracted from 1.The default is false.
FullPrecision - a logical value indicating whether S generates values
using its full precision.Some generators are able to
create pseudorandom values faster, but with fewer random
bits, if FullPrecision is false.The default is true.

The sequence of pseudorandom numbers produced by a random number stream S is
determined by the internal state of its random number generator.Saving and
restoring the generator's internal state via the 'State' property allows you
to reproduce output.

Examples:

Create three independent streams:
[s1,s2,s3] = RandStream.create('mrg32k3a','NumStreams',3);
r1 = rand(s1,100000,1); r2 = rand(s2,100000,1); r3 = rand(s3,100000,1);
corrcoef([r1,r2,r3])

Create only one stream from a set of three independent streams:
s2 = RandStream.create('mrg32k3a','NumStreams',3,'StreamIndices',2);

Reset the generator for the default stream that underlies RAND, RANDI,
and RANDN back to the beginning to reproduce previous results:
reset(RandStream.getDefaultStream);

Save and restore the default stream's state to reproduce the output of
RAND:
defaultStream = RandStream.getDefaultStream;
savedState = defaultStream.State;
u1 = rand(1,5)
defaultStream.State = savedState;
u2 = rand(1,5) % contains exactly the same values as u1

Return RAND, RANDI, and RANDN to their default initial settings:
s = RandStream.create('mt19937ar','seed',5489);
RandStream.setDefaultStream(s);

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.
s = RandStream.create('mt19937ar','seed',sum(100*clock));
RandStream.setDefaultStream(s);

Select the algorithm that RANDN uses:
defaultStream = RandStream.getDefaultStream;
defaultStream.RandnAlg = 'inversion';

RandStream methods:
RandStream/RandStream - Create a random number stream.
create - Create multiple independent random number streams.
list - List available random number generator algorithms.
getDefaultStream - Get the default random number stream.
setDefaultStream - Set the default random number stream.
reset- Reset a stream to its initial internal state.
rand - Pseudorandom numbers from a uniform distribution.
randn- Pseudorandom numbers from a standard normal distribution.
randi- Pseudorandom integers from a uniform discrete distribution.
randperm - Random permutation.
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯