Skip to content

Commit

Permalink
Merge pull request JuliaStats#451 from JuliaStats/anj/bernoulli
Browse files Browse the repository at this point in the history
Fix median(Bernoulli(0.5)).
  • Loading branch information
johnmyleswhite committed Jan 26, 2016
2 parents a962c88 + 4ed37da commit 806dead
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
6 changes: 1 addition & 5 deletions src/univariate/discrete/bernoulli.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ function modes(d::Bernoulli)
p > 0.5 ? [1] : [0, 1]
end

function median(d::Bernoulli)
p = succprob(d)
p < 0.5 ? 0.0 :
p > 0.5 ? 1.0 : 0.5
end
median(d::Bernoulli) = ifelse(succprob(d) <= 0.5, 0, 1)

function entropy(d::Bernoulli)
p0 = failprob(d)
Expand Down
36 changes: 18 additions & 18 deletions test/discrete_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"entropy": 0.69314718055994529,
"maximum": 1,
"mean": 0.5,
"median": 0.5,
"median": 0,
"minimum": 0,
"params": {
"failprob": 0.5,
Expand All @@ -24,11 +24,11 @@
"x": 1
}
],
"q10": 0.0,
"q25": 0.0,
"q50": 0.0,
"q75": 1.0,
"q90": 1.0,
"q10": 0,
"q25": 0,
"q50": 0,
"q75": 1,
"q90": 1,
"var": 0.25
}
],
Expand All @@ -39,7 +39,7 @@
"entropy": 0.56233514461880829,
"maximum": 1,
"mean": 0.25,
"median": 0.0,
"median": 0,
"minimum": 0,
"params": {
"failprob": 0.75,
Expand All @@ -57,11 +57,11 @@
"x": 1
}
],
"q10": 0.0,
"q25": 0.0,
"q50": 0.0,
"q75": 0.0,
"q90": 1.0,
"q10": 0,
"q25": 0,
"q50": 0,
"q75": 0,
"q90": 1,
"var": 0.1875
}
],
Expand All @@ -72,7 +72,7 @@
"entropy": 0.56233514461880829,
"maximum": 1,
"mean": 0.75,
"median": 1.0,
"median": 1,
"minimum": 0,
"params": {
"failprob": 0.25,
Expand All @@ -90,11 +90,11 @@
"x": 1
}
],
"q10": 0.0,
"q25": 0.0,
"q50": 1.0,
"q75": 1.0,
"q90": 1.0,
"q10": 0,
"q25": 0,
"q50": 1,
"q75": 1,
"q90": 1,
"var": 0.1875
}
],
Expand Down

0 comments on commit 806dead

Please sign in to comment.