Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
openmole
openmole
Commits
15a731ca
Commit
15a731ca
authored
Nov 17, 2021
by
Romain Reuillon
Browse files
[Tool] enh: implement KL divergence
parent
e319119c
Pipeline
#1240
passed with stages
in 45 minutes and 46 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
openmole/third-parties/org.openmole.tool.statistics/src/main/scala/org/openmole/tool/statistics/Stat.scala
View file @
15a731ca
...
@@ -206,4 +206,12 @@ trait Stat {
...
@@ -206,4 +206,12 @@ trait Stat {
Some
(
test
.
kolmogorovSmirnovTest
(
new
NormalDistribution
(
null
,
mu
,
sigma
),
data
.
toArray
))
Some
(
test
.
kolmogorovSmirnovTest
(
new
NormalDistribution
(
null
,
mu
,
sigma
),
data
.
toArray
))
}
}
def
klDivergence
(
p1
:
Array
[
Double
],
p2
:
Array
[
Double
])
=
{
val
s
=
(
p1
zip
p2
).
filter
{
case
(
p1
,
p2
)
⇒
p1
==
0.0
||
p2
==
0.0
}.
map
{
case
(
p1
,
p2
)
⇒
p1
*
math
.
log
(
p1
/
p2
)
}.
sum
s
/
math
.
log
(
2
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment