Bayes is a Domain-Specific Language for probability theory. The goal is to mimic mathematical notation as closely as possible. There is an emphasis on choice in the API – many expressions can be written in several different ways, allowing you to choose between being concise and explicit. I have grand plans of expanding it into a full probability/statistics package, but for now the project is much more modest.
I’m glad you asked!
Working with boolean random variables:
p = Bayes::P.new a = Bayes::RV.new p[a] = { true => 0.1, false => 0.9 } #or… p[a] = [0.1, 0.9] #or even… p[a] = [0.1] #final value is inferred p[ a[true] ] = 0.1 p[+a] #=> 0.1 p[~a] #=> 0.9 p[a] #=> [0.1, 0.9]
Discrete random variables:
p = Bayes::P.new a = Bayes::RV.new [:yes, :no, :maybe], [0.1, 0.4, 0.5] p[ a[:yes] ] #=> 0.1 p[ a.maybe ] = 0.7 p[ a.no ] = 0.2 p[a] #=> [0.1, 0.2, 0.7]
Package as a gem
Compound Variables
Something like this:
p = Bayes::P.new a = Bayes::RV.new :bool, [0.1, 0.9] b = Bayes::RV.new :bool p[b & a] = { :true => { :true => 0.25, :false => 0.75 }, :false => { :true => 0.1, :false => 0.9 } } p[+b & ~a] #=> 0.75
Conditional Variables
Something like this:
p = Bayes::P.new a = Bayes::RV.new :bool, [0.1, 0.9] b = Bayes::RV.new :bool p[b|a] = { :true => { :true => 0.25, :false => 0.75 }, :false => { :true => 0.1, :false => 0.9 } } p[+b|~a] #=> 0.75
Continuous Variables
Something like this:
p = Bayes::P.new a = Bayes::RV.new :continuous, :normal => { :mean => 1, :variance: 0.2 } p[ a[1.2] ] = #=> whatever this is