about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/netlab3.3/glm.m
diff options
context:
space:
mode:
authorziejd22017-09-28 15:04:40 -0500
committerziejd22017-09-28 15:04:40 -0500
commit8070dc963753142bb86c4ed698d91fd623ed28e7 (patch)
treed0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/netlab3.3/glm.m
parent7cc31810d53176e805532b2789955f4eedbce6bb (diff)
downloadBNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning.

I am calling this BNW_1.02. It can be accessed at:
compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/netlab3.3/glm.m')
-rw-r--r--sourcecodes/bnt-master/netlab3.3/glm.m82
1 files changed, 82 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/netlab3.3/glm.m b/sourcecodes/bnt-master/netlab3.3/glm.m
new file mode 100644
index 00000000..7741171a
--- /dev/null
+++ b/sourcecodes/bnt-master/netlab3.3/glm.m
@@ -0,0 +1,82 @@
+function net = glm(nin, nout, outfunc, prior, beta)
+%GLM	Create a generalized linear model.
+%
+%	Description
+%
+%	NET = GLM(NIN, NOUT, FUNC) takes the number of inputs and outputs for
+%	a generalized linear model, together with a string FUNC which
+%	specifies the output unit activation function, and returns a data
+%	structure NET. The weights are drawn from a zero mean, isotropic
+%	Gaussian, with variance scaled by the fan-in of the output units.
+%	This makes use of the Matlab function RANDN and so the seed for the
+%	random weight initialization can be  set using RANDN('STATE', S)
+%	where S is the seed value. The optional argument ALPHA sets the
+%	inverse variance for the weight initialization.
+%
+%	The fields in NET are
+%	  type = 'glm'
+%	  nin = number of inputs
+%	  nout = number of outputs
+%	  nwts = total number of weights and biases
+%	  actfn = string describing the output unit activation function:
+%	      'linear'
+%	      'logistic'
+%	      'softmax'
+%	  w1 = first-layer weight matrix
+%	  b1 = first-layer bias vector
+%
+%	NET = GLM(NIN, NOUT, FUNC, PRIOR), in which PRIOR is a scalar, allows
+%	the field  NET.ALPHA in the data structure NET to be set,
+%	corresponding  to a zero-mean isotropic Gaussian prior with inverse
+%	variance with value PRIOR. Alternatively, PRIOR can consist of a data
+%	structure with fields ALPHA and INDEX, allowing individual Gaussian
+%	priors to be set over groups of weights in the network. Here ALPHA is
+%	a column vector in which each element corresponds to a  separate
+%	group of weights, which need not be mutually exclusive.  The
+%	membership of the groups is defined by the matrix INDEX in which the
+%	columns correspond to the elements of ALPHA. Each column has one
+%	element for each weight in the matrix, in the order defined by the
+%	function GLMPAK, and each element is 1 or 0 according to whether the
+%	weight is a member of the corresponding group or not.
+%
+%	NET = GLM(NIN, NOUT, FUNC, PRIOR, BETA) also sets the  additional
+%	field NET.BETA in the data structure NET, where beta corresponds to
+%	the inverse noise variance.
+%
+%	See also
+%	GLMPAK, GLMUNPAK, GLMFWD, GLMERR, GLMGRAD, GLMTRAIN
+%
+
+%	Copyright (c) Ian T Nabney (1996-2001)
+
+net.type = 'glm';
+net.nin = nin;
+net.nout = nout;
+net.nwts = (nin + 1)*nout;
+
+outtfns = {'linear', 'logistic', 'softmax'};
+
+if sum(strcmp(outfunc, outtfns)) == 0
+  error('Undefined activation function. Exiting.');
+else
+  net.outfn = outfunc;
+end
+
+if nargin > 3
+  if isstruct(prior)
+    net.alpha = prior.alpha;
+    net.index = prior.index;
+  elseif size(prior) == [1 1]
+    net.alpha = prior;
+  else
+    error('prior must be a scalar or structure');
+  end
+end
+  
+net.w1 = randn(nin, nout)/sqrt(nin + 1);
+net.b1 = randn(1, nout)/sqrt(nin + 1);
+
+if nargin == 5
+  net.beta = beta;
+end
+