Skip to content

Commit be0df4a

Browse files
committed
Added approximate entropy computation for random variables with distributions
1 parent 61e23dc commit be0df4a

File tree

1 file changed

+8
-0
lines changed
  • dynaml-core/src/main/scala-2.11/io/github/mandar2812/dynaml/probability

1 file changed

+8
-0
lines changed

dynaml-core/src/main/scala-2.11/io/github/mandar2812/dynaml/probability/package.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.mandar2812.dynaml
22

33
import breeze.stats.distributions.ContinuousDistr
4+
import io.github.mandar2812.dynaml.pipes.DataPipe
45

56
import scalaxy.streams.optimize
67
import spire.algebra.InnerProductSpace
@@ -42,6 +43,13 @@ package object probability {
4243
}
4344

4445

46+
def entropy[I, Distr <: ContinuousDistr[I]](rv: ContinuousRVWithDistr[I, Distr]): Double = {
47+
val logp_x: RandomVariable[Double] = MeasurableFunction[I, Double, ContinuousRVWithDistr[I, Distr]](
48+
rv, DataPipe((sample: I) => -1d*rv.underlyingDist.logPdf(sample)))
49+
E(logp_x)
50+
}
51+
52+
4553
/**
4654
* Calculate the (monte carlo approximation to) mean, median, mode, lower and upper confidence interval.
4755
*

0 commit comments

Comments
 (0)