📄 balance_snn.m
字号:
function [alpha, ym] = balance_snn(nets, bootn, testdatasets, trdatasets)%BALANCE_SNN Compute weights for balancing networks%% Syntax%% [alpha, ym] = balance_snn(nets, bootn, datasets)%% Description%% BALANCE_SNN takes% nets - [1 x M] matrix of net_structs trained with % costFcn = wcf_snn.% bootn - number of bootstraps% datasets - [1 x M] matrix of dataset_structs containing% information on the data used in training 'nets'. % and returns% alpha - [1 x M] matrix of weights computed by balancing;% ym - [N x MU x M] matrix of networks outputs;%% Algorithm%% See: T. Heskes; Balancing between bagging and bumping.% Advancesin Neural Information Processing Systems 9, pages% 466-472, Cambridge, 1997, MIT Press. %% See also%% TRAIN_BOOTSTRAP_SNN, TRAIN_HALFOUT_SNN, AVERAGE_OUTPUTS_SNN, % ETESTBOOT_SNN%%% Syntax also% [alpha, ym] = balance_snn(nets, bootn, testdatasets, trdatasets)%if (nargin == 3) trdatasets = testdatasets;endtrdata = trdatasets(1).data;testdata = testdatasets(1).data;M = size(nets,2);N = size(nets(1).biases{nets(1).numLayers},1);MU = size(testdata.T,2);g = getg_snn(nets(1), testdata);stdout_snn('building H voor QP-problem');H = zeros(M,M);ym = zeros(N, MU, M);for m = 1:M ym(:,:,m) = simff_snn(nets(1,m), testdata);endfor m1 = 1:M for m2 = m1:M H(m1,m2) = -0.5 * ... ( wef_snn(ym(:,:,m1), ym(:,:,m2), g, nets(1).costFcn.fn) + ... wef_snn(ym(:,:,m2), ym(:,:,m1), g, nets(1).costFcn.fn) ); stdout_snn('.'); endendH = H + H' - diag(diag(H));stdout_snn('(done); ');%A = [ones(1,M);-eye(M)];%b = [1;zeros(M,1)];%VLB = zeros(M,1);%VUB = ones(M,1);%X0 = ones(M,1)/M;%N = 1;Aeq = ones(1,M);A = -eye(M);beq = 1;b = zeros(M,1);LB = zeros(M,1);UB = ones(M,1);X0 = ones(M,1)/M;options = optimset('display', 'off');sigma = 0.05;stdout_snn('bootstrapping...');X = zeros(M, bootn);for boot = 1:bootn fboot = 2*etestboot_snn(nets, trdatasets)';% X(:,boot) = qp(H, fboot, A, b, VLB, VUB, X0, N); X(:,boot) = quadprog(H, fboot, A, b, Aeq, beq, LB, UB, X0, options); X(:,boot) = X(:,boot)/(sum(X(:,boot),1)); stdout_snn('.');endalpha = mean(X,2);stdout_snn('(done); ');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -