UFLDL stack2params.m

传入的是stack,stack中存储着不同层的W和b。

params是向量化之后的所有的参数,存储为一列。

function [params] = stack2params(stack)

% Converts a "stack" structure into a flattened parameter vector and also
% stores the network configuration. This is useful when working with
% optimization toolboxes such as minFunc.
%
% [params, netconfig] = stack2params(stack)
%
% stack - the stack structure, where stack{1}.w = weights of first layer
%                                    stack{1}.b = weights of first layer
%                                    stack{2}.w = weights of second layer
%                                    stack{2}.b = weights of second layer
%                                    ... etc.
% This is a non-standard version of the code to support conv nets
% it allows higher layers to have window sizes >= 1 of the previous layer
% If using a gpu pass inParams as your gpu datatype
% Setup the compressed param vector
params = [];


for d = 1:numel(stack)
    % This can be optimized. But since our stacks are relatively short, it
    % is okay
    params = [params ; stack{d}.W(:) ; stack{d}.b(:) ];

    % Check that stack is of the correct form
    assert(size(stack{d}.W, 1) == size(stack{d}.b, 1), ...
        ['The bias should be a *column* vector of ' ...
         int2str(size(stack{d}.W, 1)) 'x1']);
     % no layer size constrain with conv nets
     if d < numel(stack)
        assert(mod(size(stack{d+1}.W, 2), size(stack{d}.W, 1)) == 0, ...
            ['The adjacent layers L' int2str(d) ' and L' int2str(d+1) ...
             ' should have matching sizes.']);
     end
end

end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值