DL&ML/code.data.tips

KL divergence 구현 예시

식피두 2021. 4. 13. 02:16

두 분포간의 dissimilarity를 측정하는 KL-divergence 식
두 분포간의 dissimilarity를 측정하는 KL-divergence 식

def kl_divergence(p, q):
    return np.sum(np.where(p != 0, p * np.log(p / q), 0))
    
if __name__ == '__main__':
    x = np.arange(-10, 10, 0.001)
    p = norm.pdf(x, 0, 2)
    q = norm.pdf(x, 2, 2)
    
    print(kl_divergence(p, q))

 

 

KL Divergence Python Example

We can think of the KL divergence as distance metric (although it isn’t symmetric) that quantifies the difference between two probability…

towardsdatascience.com

 

Cross Entropy, KL-Divergence

두 확률 분포 사이의 다름의 정도를 측정하는 방법에 대해 정리해 본다. Cross Entropy Cross Entropy를 이해하기 앞서서 information에 대해서 정의해야 한다. information(정보량)은 uncertainty(불확실성)을 나..

aimaster.tistory.com