wolffd@0: function net = netunpak(net, w) wolffd@0: %NETUNPAK Separates weights vector into weight and bias matrices. wolffd@0: % wolffd@0: % Description wolffd@0: % NET = NETUNPAK(NET, W) takes an net network data structure NET and a wolffd@0: % weight vector W, and returns a network data structure identical to wolffd@0: % the input network, except that the componenet weight matrices have wolffd@0: % all been set to the corresponding elements of W. If there is a MASK wolffd@0: % field in the NET data structure, then the weights in W are placed in wolffd@0: % locations corresponding to non-zero entries in the mask (so W should wolffd@0: % have the same length as the number of non-zero entries in the MASK). wolffd@0: % wolffd@0: % See also wolffd@0: % NETPAK, NETFWD, NETERR, NETGRAD wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: unpakstr = [net.type, 'unpak']; wolffd@0: wolffd@0: % Check if we are being passed a masked set of weights wolffd@0: if (isfield(net, 'mask')) wolffd@0: if length(w) ~= size(find(net.mask), 1) wolffd@0: error('Weight vector length does not match mask length') wolffd@0: end wolffd@0: % Do a full pack of all current network weights wolffd@0: pakstr = [net.type, 'pak']; wolffd@0: fullw = feval(pakstr, net); wolffd@0: % Replace current weights with new ones wolffd@0: fullw(logical(net.mask)) = w; wolffd@0: w = fullw; wolffd@0: end wolffd@0: wolffd@0: net = feval(unpakstr, net, w);