stripe / rainier

Bayesian inference in Scala.
https://rainier.fit
Apache License 2.0
432 stars 51 forks source link

Track bounds for Real #420

Closed avibryant closed 4 years ago

avibryant commented 4 years ago

This tracks a (lower,upper) bound (as a double) for any Real, by starting each Variable at (-inf,inf), and starting each Constant(k) at (k,k), and then doing interval arithmetic to transform the bounds for any operations.

It works surprisingly well - eg Exponential(3).param.logistic.bounds gives Bounds(0.5,1.0).

The idea is then to have assertions in the constructors for distributions that enforce bounds like stddev has to be positive. This acts a bit like type checking for your models.

Before this is useful, we'll need to also add accurate bounds to Placeholder that are computed during Model.observe, otherwise we'll likely get assertion failures every time we use Fn. (We also need to add in the actual assertions).

avibryant commented 4 years ago

I'll add an issue for adding tests for this.

codecov-io commented 4 years ago

Codecov Report

Merging #420 into 0.3-dev will increase coverage by 1.07%. The diff coverage is 81.25%.

Impacted file tree graph

@@             Coverage Diff             @@
##           0.3-dev     #420      +/-   ##
===========================================
+ Coverage     54.9%   55.97%   +1.07%     
===========================================
  Files           69       70       +1     
  Lines         2683     2751      +68     
  Branches       149      150       +1     
===========================================
+ Hits          1473     1540      +67     
- Misses        1210     1211       +1
Impacted Files Coverage Δ
...src/main/scala/com/stripe/rainier/core/Model.scala 64.7% <0%> (ø) :arrow_up:
...c/main/scala/com/stripe/rainier/plot/Jupyter.scala 0% <0%> (ø) :arrow_up:
...c/main/scala/com/stripe/rainier/compute/Real.scala 79.01% <94.44%> (+4.4%) :arrow_up:
...main/scala/com/stripe/rainier/compute/Bounds.scala 96% <96%> (ø)
...ain/scala/com/stripe/rainier/compute/RealOps.scala 79.16% <0%> (+1.66%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 910b853...f21a96d. Read the comment docs.