Movatterモバイル変換


[0]ホーム

URL:


KL_div()

Introduction

The Kullback-Leibler divergence, a fundamental concept in informationtheory and statistics, provides a useful framework for quantifying thedifference between two probability distributions. In the field ofbehavioral analysis, comparing distributions between different operantschedules is paramount for gaining insights into various phenomena, fromdecision-making processes to learning dynamics. By capturing therelative entropy between distributions, the Kullback-Leibler divergenceoffers a nuanced understanding of behavioral patterns.

Whether investigating the effectiveness of interventions, assessingthe impact of environmental variables, or examining the fidelity ofcomputational models to empirical data, the Kullback-Leibler divergenceserves as a versatile tool for comparing distributions and evaluatinghypotheses. Its application extends across diverse domains withinbehavioral science, offering researchers a robust methodology fordiscerning patterns, elucidating underlying mechanisms, and refiningtheoretical frameworks.

The Kullback-Leibler divergence formula for continuous variables canbe expressed as:

\[ {D_{KL}(P||Q) = \int_{-\infty}^{\infty}p(x) \log \frac{p(x)}{q(x)} dx} \]

Where\(p(x)\) and\(q(x)\) are the probability density of thedistributions\(P\) and\(Q\), respectively.

Here we implement theKL_div() function which takes twonumeric distributions (\(P\) and\(Q\)) and the upper and lower limits forintegration, returning a numeric value for the\(D_{KL}\).

The function takes the following parameters:

Example

First let’s generate and plot two random normal distributions with100 elements and calculate the\(D_{KL}\):

set.seed(420)p<-rnorm(100,20,5)q<-rnorm(100,20,5)DKL<-KL_div(p, q,-Inf,Inf)

Now let’s use real data from two different subjects performanceduring 5 Peak Interval sessions:

data("gauss_example_1",package ="YEAB",envir =environment())data("gauss_example_2",package ="YEAB",envir =environment())P<- gauss_example_1Q<- gauss_example_2DKL_real<-KL_div(P$Response_Average, Q$Response_Average,-Inf,Inf)print(DKL_real)
## [1] 0.237648


[8]ページ先頭

©2009-2025 Movatter.jp