加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

matlab rands函数的用法

(2014-06-04 14:32:38)

原文地址:http://blog.csdn.net/superdont/article/details/5497654

注意:rands函数与rand不同

有如下程序,

 

[c-sharp] view plaincopy
  1. clc;  
  2. clear;  
  3. [a,b]=rands(5,1);  
  4.  
  5.  
  6. [c,d]=rands(1,5);  
  7.  
  8.  

输出如下:

a =

   -0.5749
    0.6785
    0.2576
   -0.7325
   -0.5857


b =

    0.2144
    0.2598
   -0.2590
    0.1503
   -0.0972


c =

   -0.9122   -0.9456   -0.3746   -0.9743   -0.2321


d =

    0.3662

 

有关rands函数说明如下:

rands 

Symmetric random weight/bias initialization function 
Syntax
W = rands(S,PR)
M = rands(S,R)
v = rands(S);

Description

rands is a weight/bias initialization function. 
rands(S,PR) takes, 
S -- Number of neurons 
PR -- R x 2 matrix of R input ranges 
and returns an S-by-R weight matrix of random values between -1 and 1. 
rands(S,R) returns an S-by-R matrix of random values. rands(S) returns an S-by-1 vector of random values. 
Examples

Here three sets of random values are generated with rands. rands(4,[0 1; -2 2])
rands(4)
rands(2,3)

Network Use

To prepare the weights and the bias of layer i of a custom network to be initialized with rands Set net.initFcn to 'initlay'. (net.initParam will automatically become initlay's default parameters.) Set net.layers{i}.initFcn to 'initwb'. Set each net.inputWeights{i,j}.initFcn to 'rands'. Set each net.layerWeights{i,j}.initFcn to 'rands'. Set each net.biases{i}.initFcn to 'rands'. 
To initialize the network call init

 


没有说明,如何出现上述结果,百度之:

 


function [w,b] = rands(s,pr)

%RANDS Symmetric random weight/bias initialization function.

%

% Syntax

%

% W = rands(S,PR)

% M = rands(S,R)

% v = rands(S);

%

% Description

%

% RANDS is a weight/bias initialization function.

%

% RANDS(S,PR) takes,

% S - number of neurons.

% PR - Rx2 matrix of R input ranges.

% and returns an S-by-R weight matrix of random values between -1 and 1.

%

% RANDS(S,R) returns an S-by-R matrix of random values.

% RANDS(S) returns an S-by-1 vector of random values.

%

% Examples

%

% Here three sets of random values are generated with RANDS.

%

% rands(4,[0 1; -2 2])

% rands(4)

% rands(2,3)

%

% Network Use

%

% To prepare the weights and the bias of layer i of a custom network

% to be initialized with RANDS:

% 1) Set NET.initFcn to 'initlay'.

% (NET.initParam will automatically become INITLAY's default parameters.)

% 2) Set NET.layers{i}.initFcn to 'initwb'.

% 3) Set each NET.inputWeights{i,j}.initFcn to 'rands'.

% Set each NET.layerWeights{i,j}.initFcn to 'rands';

% Set each NET.biases{i}.initFcn to 'rands'.

%

% To initialize the network call INIT.

%

% See also RANDNR, RANDNC, INITWB, INITLAY, INIT



% Mark Beale, 1-31-92

% Revised 12-15-93, MB

% Revised 11-31-97, MB

% Copyright 1992-2008 The MathWorks, Inc.

% $Revision: 1.1.6.7 $ $Date: 2008/06/20 08:04:33 $



fn = mfilename;

if (nargin < 1), error('NNET:Arguments','Not enough arguments.'); end

if ischar(s)

switch(s)

case 'name'

w = 'Midpoint';

otherwise, error('NNET:Arguments',['Unrecognized code: ''' s ''''])

end

return

end



if nargin == 1

r = 1;

elseif size(pr,2) == 1

r = pr;

else

r = size(pr,1);

end

w = 2*rand(s,r)-1;//注意




% **[ NNT2 Support ]**

if nargout == 2

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有