?? randselect.m
字號:
function [index1,index2] = randselect(weights)% WBL 22 Sept 2002 To boost ANN, based on time.h r1.9% $Revision: 1.3 $ $Date: 2002/09/25 19:27:44 $%WBL 25 Sep 2002 yeild two separate indexes.% Remove in and B. They are done outside.%rand('state',0);ntests = size(weights,2);%create wheelwheel = zeros(ntests,1);wheel(1) = weights(1);for i=2:ntests wheel(i) = weights(i)+wheel(i-1);endu = zeros(ntests,1);t1 = 0;t2 = 0;for t=1:ntests %select randomly ntests using wheel r = wheel(ntests)*rand; %Binary chop bot = 1; top = ntests; while (wheel(bot)<r & top>=bot) i = floor((top+bot)/2); if(r < wheel(i)) top = i - 1; else bot = i + 1; end end%while %bot if(u(bot)==0) %test 'bot' not assigned choose index1 or index2 if(t1<=t2) u(bot) = 1; else u(bot) = -1; end end%if new test if(u(bot)==1) t1 = t1 + 1; index1(t1) = bot; else t2 = t2 + 1; index2(t2) = bot; endend
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -