annotate toolboxes/FullBNT-1.0.7/netlab3.3/som.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function net = som(nin, map_size)
wolffd@0 2 %SOM Creates a Self-Organising Map.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 % NET = SOM(NIN, MAP_SIZE) creates a SOM NET with input dimension (i.e.
wolffd@0 6 % data dimension) NIN and map dimensions MAP_SIZE. Only two-
wolffd@0 7 % dimensional maps are currently implemented.
wolffd@0 8 %
wolffd@0 9 % The fields in NET are
wolffd@0 10 % type = 'som'
wolffd@0 11 % nin = number of inputs
wolffd@0 12 % map_dim = dimension of map (constrained to be 2)
wolffd@0 13 % map_size = grid size: number of nodes in each dimension
wolffd@0 14 % num_nodes = number of nodes: the product of values in map_size
wolffd@0 15 % map = map_dim+1 dimensional array containing nodes
wolffd@0 16 % inode_dist = map of inter-node distances using Manhatten metric
wolffd@0 17 %
wolffd@0 18 % The map contains the node vectors arranged column-wise in the first
wolffd@0 19 % dimension of the array.
wolffd@0 20 %
wolffd@0 21 % See also
wolffd@0 22 % KMEANS, SOMFWD, SOMTRAIN
wolffd@0 23 %
wolffd@0 24
wolffd@0 25 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 26
wolffd@0 27 net.type = 'som';
wolffd@0 28 net.nin = nin;
wolffd@0 29
wolffd@0 30 % Create Map of nodes
wolffd@0 31 if round(map_size) ~= map_size | (map_size < 1)
wolffd@0 32 error('SOM specification must contain positive integers');
wolffd@0 33 end
wolffd@0 34
wolffd@0 35 net.map_dim = length(map_size);
wolffd@0 36 if net.map_dim ~= 2
wolffd@0 37 error('SOM is a 2 dimensional map');
wolffd@0 38 end
wolffd@0 39 net.num_nodes = prod(map_size);
wolffd@0 40 % Centres are stored by column as first index of multi-dimensional array.
wolffd@0 41 % This makes extracting them later more easy.
wolffd@0 42 % Initialise with rand to create square grid
wolffd@0 43 net.map = rand([nin, map_size]);
wolffd@0 44 net.map_size = map_size;
wolffd@0 45
wolffd@0 46 % Crude function to compute inter-node distances
wolffd@0 47 net.inode_dist = zeros([map_size, net.num_nodes]);
wolffd@0 48 for m = 1:net.num_nodes
wolffd@0 49 node_loc = [1+fix((m-1)/map_size(2)), 1+rem((m-1),map_size(2))];
wolffd@0 50 for k = 1:map_size(1)
wolffd@0 51 for l = 1:map_size(2)
wolffd@0 52 net.inode_dist(k, l, m) = round(max(abs([k l] - node_loc)));
wolffd@0 53 end
wolffd@0 54 end
wolffd@0 55 end