about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/netlab3.3/som.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/som.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/som.m')
-rw-r--r--sourcecodes/bnt-master/netlab3.3/som.m55
1 files changed, 55 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/netlab3.3/som.m b/sourcecodes/bnt-master/netlab3.3/som.m
new file mode 100644
index 00000000..4c975c2f
--- /dev/null
+++ b/sourcecodes/bnt-master/netlab3.3/som.m
@@ -0,0 +1,55 @@
+function net = som(nin, map_size)
+%SOM	Creates a Self-Organising Map.
+%
+%	Description
+%	NET = SOM(NIN, MAP_SIZE) creates a SOM NET with input dimension (i.e.
+%	data dimension) NIN and map dimensions MAP_SIZE.  Only two-
+%	dimensional maps are currently implemented.
+%
+%	The fields in NET are
+%	  type = 'som'
+%	  nin = number of inputs
+%	  map_dim = dimension of map (constrained to be 2)
+%	  map_size = grid size: number of nodes in each dimension
+%	  num_nodes = number of nodes: the product of values in map_size
+%	  map = map_dim+1 dimensional array containing nodes
+%	  inode_dist = map of inter-node distances using Manhatten metric
+%
+%	The map contains the node vectors arranged column-wise in the first
+%	dimension of the array.
+%
+%	See also
+%	KMEANS, SOMFWD, SOMTRAIN
+%
+
+%	Copyright (c) Ian T Nabney (1996-2001)
+
+net.type = 'som';
+net.nin = nin;
+
+% Create Map of nodes
+if round(map_size) ~= map_size | (map_size < 1)
+    error('SOM specification must contain positive integers');
+end
+
+net.map_dim = length(map_size);
+if net.map_dim ~= 2
+    error('SOM is a 2 dimensional map');
+end
+net.num_nodes = prod(map_size);
+% Centres are stored by column as first index of multi-dimensional array.
+% This makes extracting them later more easy.
+% Initialise with rand to create square grid
+net.map = rand([nin, map_size]);
+net.map_size = map_size;
+
+% Crude function to compute inter-node distances
+net.inode_dist = zeros([map_size, net.num_nodes]);
+for m = 1:net.num_nodes
+    node_loc = [1+fix((m-1)/map_size(2)), 1+rem((m-1),map_size(2))];
+    for k = 1:map_size(1)
+	for l = 1:map_size(2)
+	    net.inode_dist(k, l, m) = round(max(abs([k l] - node_loc)));
+	end
+    end
+end