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