Kullback-Leibler(KL) diviergence
åã確çå¤æ°xã«å¯¾ããï¼ã¤ã®ç¢ºçåå¸P(x)ã¨Q(x)ãããã¨ãã ãããã®ç¢ºçåå¸ã®è·é¢ãKullback-Leibler(KL) divergenceã使ãè©ä¾¡ã§ããã
KL divergenceã¯ä»¥ä¸ã®å¼ã§è¡¨ãããã $$ \begin{align} D_{KL}(P||Q) &= \mathbb{E}_{x \sim P}[log \frac{P(x)}{Q(x)}] \\ &= \mathbb{E}_{x \sim P}[log P(x) - log Q(x)] \\ &= \int_{x} P(x) (log P(x) - log Q(x)) \end{align} $$
ãã®KL divergenceã¯äº¤å·®ã¨ã³ãããã¼ã§ä»¥ä¸ã®ããã«è¡¨ããã¨ãã§ããã $$ D_{KL}(P||Q) = -\mathbb{H}(P) + -\mathbb{H}(P,Q) $$
KL divergenceã«ã¯ä½¿ãåæã®ããæ§è³ªãããã¤ãããã
ä¸ã¤ã¯éè² æ§ãã©ã®ãããªP,Qã«å¯¾ãã¦ãéè² ã®å¤ã¨ãªãã
(証æã¯このサイトを参照ãé常ã«åãããããã§ã)
Pã¨Qãåãåå¸ã¨ãªãå ´åã«ã®ã¿ãKL divergenceã¯0ã¨ãªãã
ãã KL divergenceã¯å¯¾ç§°æ§ããªãï¼Pã¨Qã交æãããç価ã§ãªãï¼ãããè·é¢ã®å ¬çãæºãããªãã 家ããé§ ã¾ã§ã®è·é¢ã¨é§ ãã家ã¾ã§ã®è·é¢ã¯æ®éåãã¯ããªã®ã ããKL divergenceã§ã¯å¯¾ç§°ã§ã¯ãªãã ãã®ããããã®ã©ã¡ãã使ããã¯éè¦ãªé¸æã¨ãªãã
KL divergenceã®ã¤ã¡ã¼ã¸ãã¤ããããã åãåæ£ããã¤æ£è¦åå¸P,Qãå¾ã ã«ãããã¦ãKL divergenceãè¨ç®ãããã®ã以ä¸ã«ç¤ºãã
åå¸ã®éãªããå°ãããªãã«ã¤ãã¦ãKL divergenceãå°ãããªãã®ããããã
Jensen-Shannon divergence
ä¸è¨ã®KL divergenceã¯é対称ãªã®ã§ä¸ä¾¿ã ããã§å¯¾ç§°ã¨ãªãããã«å®ç¾©ããææ¨ã¨ãã¦Jensen-Shannon(JS) divergenceãããã $$ D_{JS} = \frac{1}{2}D_{KL}(P||M) + \frac{1}{2} D_{KL}(Q||M) \\ (ãã ã M(x) = \frac{P(x) + Q(X)}{2}) $$
ä¸ã¨åãåå¸ã使ã£ã¦JS divergenceãè¦ã¦ã¿ãã
赤ã¨éãããããã¨ã®åå¸ã§ã é»è²ã£ã½ããªã£ã¦ããåå¸ãã¨ã®å¹³åã®åå¸ã§ã§ããã KL divergenceã®å ´åã¨åããã赤ã¨éã®åå¸ãé¢ããã«ã¤ãã¦JS divergenceã®å¤ã大ãããªã£ã¦ããã
Bengioæ¬ã«ã¯JS divergenceè¼ã£ã¦ããªãããMurphyæ¬ã«ã¯è¼ã£ã¦ããããã…
追è¨ï¼ ä¸å¿ã³ã¼ããæ®ãã¦ãã
import matplotlib.pyplot as plt import numpy as np from scipy.stats import norm, entropy x = np.linspace(-10.0, 10.0, 10000) # å³å½¢ãµã¤ãº plt.figure(figsize=(12,8)) # 3x3ã®subplot for i in np.arange(3): for j in np.arange(3): index = i*3 + j # å確çåå¸ãå®ç¾© p = norm.pdf(x, loc=0, scale=1) q = norm.pdf(x, loc=index*0.5, scale=1) # pã¨qã®å¹³åã®ç¢ºçåå¸ m = (p+q)/2 # KL divergenceã¨JS divergenceã®è¨ç® kl = entropy(p, q) kl_pm = entropy(p, m) kl_qm = entropy(q, m) js = (kl_pm + kl_qm)/2 # subplot plt.subplot(3,3,i*3+j+1) # å³å½¢å¡ãã¤ã¶ã plt.fill_between(x, m, facecolor="y", alpha=0.2) plt.fill_between(x, p, facecolor="b", alpha=0.2) plt.fill_between(x, q, facecolor="r", alpha=0.2) # 以ä¸ã¯æ´å½¢ plt.xlim(-5, 7) plt.ylim(0,0.45) plt.title("KLD:{:>.3f}".format(kl) + ", JSD:{:>.3f}".format(js)) plt.tick_params(labelbottom="off") plt.tick_params(labelleft="off") plt.subplots_adjust(wspace=0.1, hspace=0.5) plt.show()