关于matlab中的rands函数

[a,b]=rands(2,2)
a =

-0.4205 0.0682
-0.3176 0.4542

b =

-0.3814
0.6770

为什么a b 矩阵列数不同呢



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
b = 2*rand(s,1)-1; //看着个地方

end
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值