wolffd@0
|
1 function net = mlpunpak(net, w)
|
wolffd@0
|
2 %MLPUNPAK Separates weights vector into weight and bias matrices.
|
wolffd@0
|
3 %
|
wolffd@0
|
4 % Description
|
wolffd@0
|
5 % NET = MLPUNPAK(NET, W) takes an mlp network data structure NET and a
|
wolffd@0
|
6 % weight vector W, and returns a network data structure identical to
|
wolffd@0
|
7 % the input network, except that the first-layer weight matrix W1, the
|
wolffd@0
|
8 % first-layer bias vector B1, the second-layer weight matrix W2 and the
|
wolffd@0
|
9 % second-layer bias vector B2 have all been set to the corresponding
|
wolffd@0
|
10 % elements of W.
|
wolffd@0
|
11 %
|
wolffd@0
|
12 % See also
|
wolffd@0
|
13 % MLP, MLPPAK, MLPFWD, MLPERR, MLPBKP, MLPGRAD
|
wolffd@0
|
14 %
|
wolffd@0
|
15
|
wolffd@0
|
16 % Copyright (c) Ian T Nabney (1996-2001)
|
wolffd@0
|
17
|
wolffd@0
|
18 % Check arguments for consistency
|
wolffd@0
|
19 errstring = consist(net, 'mlp');
|
wolffd@0
|
20 if ~isempty(errstring);
|
wolffd@0
|
21 error(errstring);
|
wolffd@0
|
22 end
|
wolffd@0
|
23
|
wolffd@0
|
24 if net.nwts ~= length(w)
|
wolffd@0
|
25 error('Invalid weight vector length')
|
wolffd@0
|
26 end
|
wolffd@0
|
27
|
wolffd@0
|
28 nin = net.nin;
|
wolffd@0
|
29 nhidden = net.nhidden;
|
wolffd@0
|
30 nout = net.nout;
|
wolffd@0
|
31
|
wolffd@0
|
32 mark1 = nin*nhidden;
|
wolffd@0
|
33 net.w1 = reshape(w(1:mark1), nin, nhidden);
|
wolffd@0
|
34 mark2 = mark1 + nhidden;
|
wolffd@0
|
35 net.b1 = reshape(w(mark1 + 1: mark2), 1, nhidden);
|
wolffd@0
|
36 mark3 = mark2 + nhidden*nout;
|
wolffd@0
|
37 net.w2 = reshape(w(mark2 + 1: mark3), nhidden, nout);
|
wolffd@0
|
38 mark4 = mark3 + nout;
|
wolffd@0
|
39 net.b2 = reshape(w(mark3 + 1: mark4), 1, nout);
|