问题补充说明:[a,b]=rands(2,2)a = -0.4205 0.0682 -0.3176 0.4542b = -0.3814 0.6770为什么a b 矩阵列数不同呢,希望高手详细解答,万分感谢。
这个问题和神经元算法实现有关。
你看一下程序的源代码,注意看最下下面标出的那两行:
function[w,b]=rands(s,pr)
%RANDSSymmetricrandomweight/biasinitial来自izationfunction.
%
%Syntax
%
%W=rands(360问答S,PR)
%M=rands(S,R)
%v=rand右玉晚比足s(S);
%
%Descrip帝品沙烧井生有tion
%
%RANDSisaweight/biasinitializationfunction.
%
%RANDS(S,PR)takes,
%S-numberofneurons.
%PR-Rx2matrixofRinputranges.
%andreturnsanS-by-Rweightmatrixofrandomv施于aluesbetween-1and1.
%
%RANDS(S,R)returnsan非少胞阶六S-by-Rmatrixofrandomvalues.
%RANDS(S)returnsanS-by-1vectorofrandomvalues.
%
%Examples
%
%Herethreeset列sofrandomvaluesaregeneratedwithRANDS.
%
%rands(4,[01;-22])
%rands(4)
%rands(2,3)
%
%Netw孙选都谈离地论坚够orkUse
%
%Topreparetheweightsandt一看激角英笑非略呀hebiasoflayeriofacustomnet缺布铁班治紧work
%tobeini地专着速置团须滑林tializedwithRA针NDS:
%1)SetNET.initFcnto'initlay'.
%(NET.initParamwillautomaticallybecomeINITLAY'sdefaultparameters.)
%2)SetNET.layers{i}.initFcnto'initwb'.
%3)SeteachNE充缩名室步困货严序成林T.inputWeights{i,j}.initFc息务仍字好nto'rands'.
%SeteachNET.layerWeights{i,j}.initFcnto'rands';
%SeteachNET.biases{i}.in首货队itFcnto'rands'.
%
%ToinitializethenetworkcallINIT.
%
%See都械善alsoRANDNR,RANDNC,INITWB,INITLAY,INIT
%MarkBeale,1-31-92
%Revised12每和搞行阿工缺热迅阶说-15-93,MB
%Re至段vised11-31-97,MB
%Copyright1992-2008TheMathWorks,Inc.
%$Revision:1.1.6.7$$Date:2008/06/2008:04:33$
fn=mfilename;
if(nargin<1),error('NNET:Arguments','Notenougharguments.');end
ifischar(s)
switch(s)
case'name'
w='Midpoint';
otherwise,error('NNET:Arguments',['Unrecognizedcode:'''s''''])
end
return
end
ifnargin==1
r=1;
elseifsize(pr,2)==1
r=pr;
else
r=size(pr,1);
end
w=2*rand(s,r)-1;//看着个地方
%**[NNT2Support]**
ifnargout==2
b=2*rand(s,1)-1;//看着个地方
end])