forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace 10MB breeze jar with simple gaussian implementation
- Loading branch information
Showing
4 changed files
with
38 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package lila.insight | ||
|
||
import math.{ Pi, log1p } | ||
import org.apache.commons.math3.special.Erf.{ erf, erfInv } | ||
import scala.math.{ sqrt, log } | ||
|
||
/** Represents a Gaussian distribution over a single real variable. */ | ||
final class Gaussian(mu: Double, sigma: Double): | ||
|
||
def draw(): Double = mu + sigma * ornicar.scalalib.ThreadLocalRandom.nextGaussian() | ||
|
||
/** Computes the inverse cdf of the p-value for this gaussian. | ||
* | ||
* @param p: | ||
* a probability in [0,1] | ||
* @return | ||
* x s.t. cdf(x) = numYes | ||
*/ | ||
def inverseCdf(p: Double): Double = { | ||
require(p >= 0) | ||
require(p <= 1) | ||
|
||
mu + sigma * sqrt2 * erfInv(2 * p - 1) | ||
} | ||
|
||
/** Computes the cumulative density function of the value x. | ||
*/ | ||
def cdf(x: Double): Double = .5 * (1 + erf((x - mu) / (sqrt2 * sigma))) | ||
|
||
private val sqrt2 = math.sqrt(2.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters