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