Daniel@0: function net = mdninit(net, prior, t, options) Daniel@0: %MDNINIT Initialise the weights in a Mixture Density Network. Daniel@0: % Daniel@0: % Description Daniel@0: % Daniel@0: % NET = MDNINIT(NET, PRIOR) takes a Mixture Density Network NET and Daniel@0: % sets the weights and biases by sampling from a Gaussian distribution. Daniel@0: % It calls MLPINIT for the MLP component of NET. Daniel@0: % Daniel@0: % NET = MDNINIT(NET, PRIOR, T, OPTIONS) uses the target data T to Daniel@0: % initialise the biases for the output units after initialising the Daniel@0: % other weights as above. It calls GMMINIT, with T and OPTIONS as Daniel@0: % arguments, to obtain a model of the unconditional density of T. The Daniel@0: % biases are then set so that NET will output the values in the Daniel@0: % Gaussian mixture model. Daniel@0: % Daniel@0: % See also Daniel@0: % MDN, MLP, MLPINIT, GMMINIT Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-2001) Daniel@0: % David J Evans (1998) Daniel@0: Daniel@0: % Initialise network weights from prior: this gives noise around values Daniel@0: % determined later Daniel@0: net.mlp = mlpinit(net.mlp, prior); Daniel@0: Daniel@0: if nargin > 2 Daniel@0: % Initialise priors, centres and variances from target data Daniel@0: temp_mix = gmm(net.mdnmixes.dim_target, net.mdnmixes.ncentres, 'spherical'); Daniel@0: temp_mix = gmminit(temp_mix, t, options); Daniel@0: Daniel@0: ncentres = net.mdnmixes.ncentres; Daniel@0: dim_target = net.mdnmixes.dim_target; Daniel@0: Daniel@0: % Now set parameters in MLP to yield the right values. Daniel@0: % This involves setting the biases correctly. Daniel@0: Daniel@0: % Priors Daniel@0: net.mlp.b2(1:ncentres) = temp_mix.priors; Daniel@0: Daniel@0: % Centres are arranged in mlp such that we have Daniel@0: % u11, u12, u13, ..., u1c, ... , uj1, uj2, uj3, ..., ujc, ..., um1, uM2, Daniel@0: % ..., uMc Daniel@0: % This is achieved by transposing temp_mix.centres before reshaping Daniel@0: end_centres = ncentres*(dim_target+1); Daniel@0: net.mlp.b2(ncentres+1:end_centres) = ... Daniel@0: reshape(temp_mix.centres', 1, ncentres*dim_target); Daniel@0: Daniel@0: % Variances Daniel@0: net.mlp.b2((end_centres+1):net.mlp.nout) = ... Daniel@0: log(temp_mix.covars); Daniel@0: end