Daniel@0: function net = mlpinit(net, prior) Daniel@0: %MLPINIT Initialise the weights in a 2-layer feedforward network. Daniel@0: % Daniel@0: % Description Daniel@0: % Daniel@0: % NET = MLPINIT(NET, PRIOR) takes a 2-layer feedforward network NET and Daniel@0: % sets the weights and biases by sampling from a Gaussian distribution. Daniel@0: % If PRIOR is a scalar, then all of the parameters (weights and biases) Daniel@0: % are sampled from a single isotropic Gaussian with inverse variance Daniel@0: % equal to PRIOR. If PRIOR is a data structure of the kind generated by Daniel@0: % MLPPRIOR, then the parameters are sampled from multiple Gaussians Daniel@0: % according to their groupings (defined by the INDEX field) with Daniel@0: % corresponding variances (defined by the ALPHA field). Daniel@0: % Daniel@0: % See also Daniel@0: % MLP, MLPPRIOR, MLPPAK, MLPUNPAK Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-2001) Daniel@0: Daniel@0: if isstruct(prior) Daniel@0: sig = 1./sqrt(prior.index*prior.alpha); Daniel@0: w = sig'.*randn(1, net.nwts); Daniel@0: elseif size(prior) == [1 1] Daniel@0: w = randn(1, net.nwts).*sqrt(1/prior); Daniel@0: else Daniel@0: error('prior must be a scalar or a structure'); Daniel@0: end Daniel@0: Daniel@0: net = mlpunpak(net, w); Daniel@0: