UFLDL params2stack.m

    xiaoxiao2023-06-01  3

    主要有两个参数,所有参数的列向量params和网络的参数ei。 params保存着所有的参数值,而ei保存着每一层的大小,也就是参数reshape的矩阵维度。 最后返回的stack保存着网络层间的参数矩阵。

    function stack = params2stack(params, ei) % Converts a flattened parameter vector into a nice "stack" structure % for us to work with. This is useful when you're building multilayer % networks. % % stack = params2stack(params, netconfig) % % params - flattened parameter vector % ei - auxiliary variable containing % the configuration of the network % % Map the params (a vector into a stack of weights) depth = numel(ei.layer_sizes); stack = cell(depth,1); % the size of the previous layer prev_size = ei.input_dim; % mark current position in parameter vector cur_pos = 1; for d = 1:depth % Create layer d stack{d} = struct; hidden = ei.layer_sizes(d); % Extract weights wlen = double(hidden * prev_size); stack{d}.W = reshape(params(cur_pos:cur_pos+wlen-1), hidden, prev_size); cur_pos = cur_pos+wlen; % Extract bias blen = hidden; stack{d}.b = reshape(params(cur_pos:cur_pos+blen-1), hidden, 1); cur_pos = cur_pos+blen; % Set previous layer size prev_size = hidden; end end
    转载请注明原文地址: https://ju.6miu.com/read-1262205.html
    最新回复(0)