analyze_data_snn.m

来自「神经网络的工具箱, 神经网络的工具箱,」· M 代码 · 共 107 行

M
107
字号
function analysis = analyze_data_snn(P)%ANALYZE_DATA_SNN classify inputs in bool/boolgroup/cycle/continous variables.%%  Syntax%%   analysis = analyze_data_snn(P)%%  Description%%   ANALYZE_DATA_SNN takes%    P   - [N x MU] matrix of inputs/outputs%   and returns %    analysis - a struct containing information about P.%%   (N = #inputs/outputs; MU = #patterns)%if isnumeric(P)   readdata = P';   [MU, NM] = size(readdata);      %check for booleans.   bool_ind = find ...      (  ( sum((readdata == repmat(min(readdata),MU,1)) + ...               (readdata == repmat(max(readdata),MU,1))) + ...           sum(isnan(readdata)) ) == MU  );     % BUGFIX: use function double, because in Matlab 6.5 bools % form a logical array, while it was a double array in former% Matlab versions.  %<    bools = ...%<      (readdata(:,bool_ind) == repmat(max(readdata(:,bool_ind)), MU, 1));%>   bools = double(...       (readdata(:,bool_ind) == repmat(max(readdata(:,bool_ind)), MU, 1)));     %>>>   bools(find(isnan(readdata(:,bool_ind)))) = NaN;   %check for 'boolgroups' % boolgroup: sum(group) = 1, with group = [i:k];   NBOOL = size(bool_ind,2);   ngroups = 0;   bool_groups = [];   group_begin = 1;   while(group_begin<=NBOOL)	for group_end = NBOOL:-1:group_begin	    score = sum(bools(:, group_begin:group_end),2); 	    if (sum(score == 1 | isnan(score)) == MU)                ngroups = ngroups + 1;	       bool_groups = [bool_groups; zeros(1,NM)];	       bool_groups(ngroups, bool_ind([group_begin:group_end])) = 1;               group_begin = group_end + 1;	       break;            end        end         group_begin = group_begin + 1;   end   %continuous variables   cont_ind = setdiff([1:NM], bool_ind);   conts = readdata(:, cont_ind);      %check for cycles: x^2 + y^2 = 1   NCONT = size(cont_ind, 2);   ncycles = 0;    cycles = [];   cycle_begin = 1;   while (cycle_begin < NCONT)      score = abs(sum((conts(:,[cycle_begin, cycle_begin+1])).^2, 2) - 1);      if (score < 0.001) 	 ncycles = ncycles + 1;         cycles = [cycles; zeros(1,NM)];	 cycles(ncycles, cont_ind([cycle_begin:(cycle_begin+1)])) = 1;         cycle_begin = cycle_begin + 1;      end      cycle_begin = cycle_begin + 1;   end   for nm = 1:NM       analysis(nm).min = min(P(nm,:), [], 2);       analysis(nm).max = max(P(nm,:), [], 2);       analysis(nm).group = nm;   end   for ind = bool_ind       analysis(ind).type = 'bool';   end   for ind = cont_ind       analysis(ind).type = 'continuous';   end   for k = 1:size(cycles,1)       cycle = find(cycles(k,:));       for ind = cycle           analysis(ind).group = cycle;        end   end   for k = 1:size(bool_groups,1)       group = find(bool_groups(k,:));       for ind = group           analysis(ind).group = group;        end   end  else   error('ANALYZE_DATA_SNN: input must be (numeric) matrix');end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?