function [ d ] = hcompare_KL(h1,h2)
%This routine evaluates the Kullback-Leibler (KL) distance between histograms.
% Input: h1, h2 - histograms
% Output: d – the distance between the histograms.
% Method: KL is defined as:
% Note, KL is not symmetric, so compute both sides.
% Take care not to divide by zero or log zero: disregard entries of the sum for which with H2(i) == 0.
temp = sum(h1 .* log(h1 ./ h2));
temp(isinf(temp)) = 0; % this resloves where h1(i) == 0
d1 = sum(temp);
temp = sum(h2 .* log(h2 ./ h1)); % other direction of compare since it's not symetric
temp(isinf(temp)) = 0;
d2 = sum(temp);
d = d1 + d2;
end
私の問題は、H1(i)又はH2(I)== 0 iは期待通りにあるinfファイルを取得していたときにということです。しかし、KL距離では、h1またはh2 == 0のときはいつでも0を返すと思われます。ループを使用せずにどうすればいいですか?カルバック・ライブラー(KL)距離 - MATLAB
でなければならない方が良い聞いていない場合、あなたを助けるために本当に難しいです質問。私はあなたの間違いを見つけることができません、もし私がプログラムが最初に何をすべきか分からなければ。サンプルの入力を提案し、どの出力を期待しているのか、何がうまくいかないのかを教えてください。関数はエラーをスローしますか?関数はあなたが望むものを返さないのですか?私はあなたの質問を下落させましたが、質問が改善すれば私の投票を修正することができます。 – Jonas
こんにちは@Jonas毎日のお返事ありがとうございます。後で私の質問を指定してよろしくお願いします。ありがとうございます。 – Gilad
@jonas私は私の質問を編集しました。それを見てください。私はh1 = [0:9]とh2 = [1:10]私が入力として0を持っているときのエラー.. log(0) – Gilad