📄 gnp.m
字号:
% Basic implementation of a global SOM-based novelty detection method
%
% Source:
% Barreto, G.A.; Mota, J.C.M.; Souza, L.G.M.; Frota, R.A.; Aguayo, L.
% Condition monitoring of 3G cellular networks through competitive neural models
% IEEE Trans. on Neural Networks, vol. 16, no. 5, p. 1064- 1075, 2005.
%
% Author: Guilherme A. Barreto
% Date: November 21th 2005
clear; clc; close all;
% Generate uncorrelated Multivariate Gaussian Data (Better impossible!)
DIM_INPUT=5; % Dimension of the data vectors
LEN_DATA=1000; % Number of generated samples
Dw=randn(LEN_DATA,DIM_INPUT); % 1000 random 5-dimensional data vectors
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define size of the network %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Mx = 6; % Number of neurons in the X-dimension
My = 6; % Number of neurons in the Y-dimension
MAP_SIZE = [Mx My]; % Size of SOM map
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create a CL network structure %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sMap = som_map_struct(DIM_INPUT,'msize',MAP_SIZE,'rect','sheet');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Different weights initialization methods %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% sMap = som_randinit(Dw, sMap); % Random weight initialization
% sMap = som_lininit(Dw, sMap); % Linear weight initialization
I=randperm(LEN_DATA); sMap.codebook=Dw(I(1:Mx*My),:); % Select Mx*My data vectors at random
% Training parameters specification
sMap.trainhist.radius_ini=round(max(Mx,My)/2); % Initial neighborhood
sMap.trainhist.radius_fin=0; % Final neighborhood
sMap.trainhist.alpha_ini=0.8; % Initial learning rate
sMap.trainhist.alpha_type='power'; % Type of learning rate annealing
sMap.neigh='gaussian'; % Type of neighborhod function
Nep=100; % Number of epochs
% Train the SOM for Nep epochs
sMap = som_seqtrain(sMap,Dw,'sample_order','random','trainlen_type','epochs','trainlen',Nep);
% Computation of Global Normality Profile (GNP) Using Training Data
[Winners GNP] = som_bmus(sMap,Dw);
figure; hist(GNP,30); % Plot the histogram
% Find decision thresholds for the normality profile (GNP)
p=95; % Confidence level
Linf = prctile(GNP,(100-p)/2); % lower threshold
Lsup = prctile(GNP,(100+p)/2); % upper threshold
%%%%%%%%%%%%%%%%%%% Computation of the False Alarm Rate %%%%%%%%%%%%%%%%%
% Generate a new sample of data vectors with the same joint PDF of training data vectors
Dtest=randn(LEN_DATA,DIM_INPUT);
% Find the corresponding quantization errors
[Winners Qerrors] = som_bmus(sMap,Dtest);
I1=find(Qerrors <= Linf); % find Qerrors <= Linf
I2=find(Qerrors >= Lsup); % find Qerrors >= Lsup
false_alarm_rate = 100*((length(I1)+length(I2))/LEN_DATA);
% NOTE 1: IF (PDF testing data = PDF training data) THEN (few false alarms are generated).
% NOTE 2: The False alarm rate should be approximately equal to "alpha=100-p"%.
% This can help finding the (sub)optimal number of neurons for representing the data.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -