avg_distortion.m

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

M
34
字号
%
% function D = distortion(region, cdbk, imagesize): compute the average 
% distortion overall partitions based on newly generated cdbk
% 
%
% Input:     
%       region -- cell stores "nwds" matrices of different sizes, 
%                 each matrix has certain number of rows and 3 columns,
%                 which represents all the points in one region
%         cdbk -- optimal code book
% parameter:   n_features -- total number of vectors over the whole regions
%
% Output:
%            D -- average distortion of all vectors in this region
%
%      

function D = avg_distortion(region, cdbk)

nwds = size(cdbk, 1);
all_D = 0;
n_features = 0;

for i_nwds = 1: nwds
    p = region{i_nwds};
    n_reg = size(p, 1);
    n_features = n_features + n_reg;
    for i_reg = 1: n_reg
        all_D = all_D + my_distance(p(i_reg, :), cdbk(i_nwds,:));
    end    
end

D = all_D/n_features;

⌨️ 快捷键说明

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