Daniel@0: function net = mlpunpak(net, w) Daniel@0: %MLPUNPAK Separates weights vector into weight and bias matrices. Daniel@0: % Daniel@0: % Description Daniel@0: % NET = MLPUNPAK(NET, W) takes an mlp 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 first-layer weight matrix W1, the Daniel@0: % first-layer bias vector B1, the second-layer weight matrix W2 and the Daniel@0: % second-layer bias vector B2 have all been set to the corresponding Daniel@0: % elements of W. Daniel@0: % Daniel@0: % See also Daniel@0: % MLP, MLPPAK, MLPFWD, MLPERR, MLPBKP, MLPGRAD Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-2001) Daniel@0: Daniel@0: % Check arguments for consistency Daniel@0: errstring = consist(net, 'mlp'); Daniel@0: if ~isempty(errstring); Daniel@0: error(errstring); Daniel@0: end Daniel@0: Daniel@0: if net.nwts ~= length(w) Daniel@0: error('Invalid weight vector length') Daniel@0: end Daniel@0: Daniel@0: nin = net.nin; Daniel@0: nhidden = net.nhidden; Daniel@0: nout = net.nout; Daniel@0: Daniel@0: mark1 = nin*nhidden; Daniel@0: net.w1 = reshape(w(1:mark1), nin, nhidden); Daniel@0: mark2 = mark1 + nhidden; Daniel@0: net.b1 = reshape(w(mark1 + 1: mark2), 1, nhidden); Daniel@0: mark3 = mark2 + nhidden*nout; Daniel@0: net.w2 = reshape(w(mark2 + 1: mark3), nhidden, nout); Daniel@0: mark4 = mark3 + nout; Daniel@0: net.b2 = reshape(w(mark3 + 1: mark4), 1, nout);