📄 klgamma.m
字号:
%kl = klgamma(pa,pb,qa,qb);%%Calculates KL(P||Q) where P and Q are Gamma distributions with%parameters {pa,pb} and {qa,qb}.%% KL(P||Q) = \int d\pi P(\pi) ln { P(\pi) / Q(\pi) }.%%This routine handles factorised P distributions, if their parameters%are specified multiply in either 'pa' or 'pb', as elements of a row%vector.%%Matthew J. Beal GCNU 06/02/01function [kl] = klgamma(pa,pb,qa,qb)n = max([size(pb,2) size(pa,2)]);if size(pa,2) == 1, pa = pa*ones(1,n); endif size(pb,2) == 1, pb = pb*ones(1,n); endqa = qa*ones(1,n); qb = qb*ones(1,n);kl = sum( pa.*log(pb)-gammaln(pa) ... -qa.*log(qb)+gammaln(qa) ... +(pa-qa).*(digamma(pa)-log(pb)) ... -(pb-qb).*pa./pb ,2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -