pred_cpann.m
来自「this file is leverage algorithm written 」· M 代码 · 共 48 行
M
48 行
function pred = pred_cpann(X,model)
% prediction of unknown samples with counterpropagation artificial neural networks (CPANNs)
% pred_cpann predicts classes of unknown samples by using a previuos model
% built by means of CPANNs (model_cpann)
%
% pred = pred_cpann(X,model);
%
% input:
% X data [n x p], n samples, p variables
% model model structure built with model_cpann
%
% output:
% pred is a structure, with the following fields
% pred.class predicted class [n x 1]
% pred.top_map sample position in the kohonen map [n x 2]
%
% see the HTML HELP files (help.htm) for details and examples
%
% version 1.0 - may 2007
% Davide Ballabio
% Milano Chemometrics and QSAR Research Group
% www.disat.unimib.it/chm
% checks
errortype = cpann_check(X,[],[],model,'pred');
if ~strcmp(errortype,'none')
disp(errortype)
return
end
% data scaling
[Xsca,scal] = som_scaling(X,[],model);
% projects the samples on the topmap and assigns samples to classes
nsize = size(model.net.W,1);
W_reshape = reshape(permute(model.net.W,[2 1 3]),[nsize*nsize size(X,2)]);
for i = 1:size(X,1)
x_in = Xsca(i,:);
winner = som_winner(x_in,W_reshape);
[pos(i,1),pos(i,2)] = som_which_neuron(winner,size(W_reshape,1));
class_pred(i) = model.net.neuron_ass(pos(i,1),pos(i,2));
end
% saves results
pred.type = 'cpann';
pred.class = class_pred;
pred.top_map = pos;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?