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