partition.m

来自「用Cross validation的方法建立人工神经网络的模型!」· M 代码 · 共 46 行

M
46
字号
%
% function [region] = partition(points, cdbk, blocksize): partion the
% points into 'nwds' partions based on given cdbk
% 
%
% Input: points -- the original 2D gray points used to generate code book
%   temp_cdbk -- nwds*2 matrix, contains the vector of all code words
%
% Output:    
%       region -- cell stores "nwds" matrices of different sizes, 
%                 each matrix has certain number of rows and 2 columns,
%                 which represents all the points in one region
%       

function region = partition(points, temp_cdbk)

n_point = size(points,1);

nwds = size(temp_cdbk, 1);
region = cell(nwds,1);

for i_point = 1: n_point
    % get the vector of one point
    p = points(i_point,:);
    
    % partition this point into one region based on nearest
    % neighbor condition
    % initialize the parameter to be impractical    
    mindis = Inf;
    index_nwds = 0;
    
    for ic = 1: nwds
        cw = temp_cdbk(ic,:);
        dis = my_distance(p,cw);
        if dis < mindis
            mindis = dis;
            index_nwds = ic;
        end
    end
    % add the point to the corresponding region cell
    region{index_nwds} = [region{index_nwds}; p];
end

%disp 'one partion done ...'

⌨️ 快捷键说明

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