注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

数据挖掘

学习数据挖掘

 
 
 

日志

 
 

RandStream类  

2013-05-05 23:01:50|  分类: Matlab |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
RandStream Random number stream. 随机数流
    (Pseudo)random numbers in MATLAB come from one or more random number streams.  
 (Pseudo 虚伪的,虚假的)  随机数来自一个或者多个随机数流


The simplest way to generate arrays of random numbers is to use  RAND, RANDI, or RANDN. 
简单快捷生成随机数的函数是RAND, RANDI, or RANDN

 These functions all draw values from the same    stream of uniform pseudorandom numbers, known as the global random number  stream.  
这些函数产生的随机数 都源于共同的随机数流

You can create other streams that act separately from the current  global stream, and you can use their RAND, RANDI, or RANDN methods to
    generate arrays of random numbers.  You can also designate any random  number stream you create as the global stream.
 可以创建自己的流

    To create a single random number stream, use the RandStream constructor.

使用 RandStream 创建流
    To create multiple independent random number streams, use RandStream.CREATE.
使用 RandStream.CREATE. 创建过个相互独立的随机数流

    The RNG function provides a simple interface to create a new global stream.
 
    STREAM = RandStream.GETGLOBALSTREAM returns the current global random
    number stream, i.e., the one that the RAND, RANDI, and RANDN functions
    currently draw values from.
 
    PREVSTREAM = RandStream.SETGLOBALSTREAM(STREAM) sets STREAM as the current
    global random number stream, i.e., designates it as the stream that the
    RAND, RANDI, and RANDN functions will draw values from.  PREVSTREAM is the
    stream that was previously designated as the global random number stream.
重新设置当前流,并且可以供RAND, RANDI, and RANDN使用。
 
    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, or attempt to improvise a
                         property value.  The value you assign to S.State must be a
                         value read from S.State previously.  Use RESET to return a
                         stream to a predictable state without having previously read
                         from the State property.
       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.
       NormalTransform - the transformation algorithm that RANDN(S, ...) uses
                         to generate normal pseudorandom values from uniform
                         values.  The property value is 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 a single stream and designate it as the current global stream:
          s = RandStream('mt19937ar','Seed',1)
          RandStream.setGlobalStream(s);
 
       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, and
       designate it as the current global stream:
          s2 = RandStream.create('mrg32k3a','NumStreams',3,'StreamIndices',2)
          RandStream.setGlobalStream(s2);
 
       Reset the global random number stream that underlies RAND, RANDI, and
       RANDN back to its beginning, to reproduce previous results:
          stream = RandStream.getGlobalStream;
          reset(stream);
 
       Save and restore the current global stream's state to reproduce the
       output of RAND:
          stream = RandStream.getGlobalStream;
          savedState = stream.State;
          u1 = rand(1,5)
          stream.State = savedState;
          u2 = rand(1,5) % u2 contains exactly the same values as u1
 
       Reset the global random number stream to its "factory default" initial
       settings.  This causes RAND, RANDI, and RANDN to start over, as if in a
       new MATLAB session.
          s = RandStream('mt19937ar','Seed',0)
          RandStream.setGlobalStream(s);
 
       Reinitialize the global random number stream using a seed based on the
       current time.  This causes RAND, RANDI, and RANDN to return different
       values in different MATLAB sessions.  NOTE: It is usually not desirable
       to do this more than once per MATLAB session.
          s = RandStream('mt19937ar','Seed','shuffle')
          RandStream.setGlobalStream(s);
 
       Change the transformation algorithm that RANDN uses to create normal
       pseudorandom values from uniform values.  Note that this does not
       replace or reset the global stream.
          stream = RandStream.getGlobalStream;
          stream.NormalTransform = 'inversion'
 
    RandStream methods:
        RandStream/RandStream  - Create a random number stream.
        create                 - Create multiple independent random number streams.
        list                   - List available random number generator algorithms.
        getGlobalStream        - Get the current global random number stream.
        setGlobalStream        - Replace the global 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.

RandStream类 - 小坏 - Do  What
 
 
  评论这张
 
阅读(1036)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017