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

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