text stringlengths 128 2.05k |
|---|
[EQUATION] Any single value [MATH] that is certain (i.e. non-random) is then associated to -expression [MATH] ; this covers for example constant numerical values [MATH] [MATH] , booleans [MATH] , as well as the empty tuple [MATH] . For the case of a non-empty tuple RV, the rule is to recursively decompose the tuple int... |
Derived -expressions form recursive structures that can be represented as direct acyclic graphs (DAG). Figure shows the graphical convention used to represent the different types of -expression seen in table above. Note that the arrow direction, from parent node [MATH] to child node [MATH] , is meant to represent that ... |
depends of [MATH] In the simplest cases, each RV occurs only once and the graph is a simple tree. For instance, consider the functional RV [MATH] representing the fact that the added values of two dice is greater or equal to 6: |
[EQUATION] [EQUATION] Then, the associated -expressions are: [EQUATION] [EQUATION] which can be represented by the following tree: |
Now, consider the conditional RV [MATH] [EQUATION] The associated -expression is: [EQUATION] By expanding this -expression, we see that [MATH] and [MATH] are referred twice. The associated graph is not a tree but a DAG (that is a more general type of graph). |
As a last example, here is the DAG for the table RV [MATH] depending of elementary RV [MATH] in the BN seen in 2.2.5 The DAG of table RV [MATH] depending of RVs [MATH] and [MATH] |
shall not be represented here because too convoluted. Note that the four plain arcs should have been labelled with tuples [MATH] [MATH] , etc. |
3.2 The Statues algorithm As we have seen, our probabilistic models are formalized as -expressions ( pex in the following); each such model is a DAG linking several -expressions together. The terminal pex correspond to elementary RV, which are defined by given pmf (also known as ”prior probabilities”). The aim of the S... |
The Statues algorithm uses a construction called generator , which is a special case of coroutine (Knuth,, 1997 ; Saba,, 2014 . Generators are available in several modern programming languages (e.g. C#, Python, Ruby, Lua, Go, Scheme, …), whether natively or as libraries. To state it in simple words, a generator is a sp... |
For detailing the algorithm, we shall use the term atom in the context of a given RV [MATH] to designate a couple [MATH] made up of a value [MATH] and a probability [MATH] ; an atom relates to a particular event that does not overlap with events related to other atoms. Such condition makes it possible to add without er... |
The other important concept used in the algorithm is the binding . At any stage of the execution, any given pex is either bound or unbound. At start-up, all pexes are unbound, which means that they have not yet been assigned a value. When a pex is required to browse the values of its domain, each yielded value is bound... |
The Statues algorithm is made up of three parts. The entry-point is the subroutine marg , which takes a given -expression [MATH] as argument and returns the marginalized pmf. This subroutine is not recursive but relies on genAtoms and genAtomsByType generators, which are mutually recursive. The calling graph is given o... |
We shall present the algorithm in a top-down manner. The entry-point marg subroutine is given in algorithm Algorithm 1 Statues algorithm – part 1: marg subroutine (entry-point) |
1: function marg [MATH] 2: [MATH] [MATH] init global binding store 3: [MATH] [MATH] init unnormalized pmf 4: for [MATH] do [MATH] collect atoms |
5: if [MATH] then 6: [MATH] 7: end if 8: [MATH] [MATH] condense pmf 9: end for 10: if [MATH] then [MATH] pmf is empty: error 11: |
halt with error 12: end if 13: [MATH] [MATH] normalize pmf 14: return [MATH] 15: end function marg takes the given pex [MATH] to be evaluated as argument. It invokes the genAtoms generator and collects the atoms yielded one by one (line 4). We will see soon that genAtoms uses the global binding store [MATH] , an associ... |
Algorithm 2 Statues algorithm – part 2: genAtoms generator 1: generator genAtoms [MATH] 2: if [MATH] then [MATH] [MATH] is bound |
3: yield [MATH] [MATH] yield unique atom to caller 4: else [MATH] [MATH] is unbound 5: for [MATH] do 6: [MATH] [MATH] (re)bind [MATH] to value [MATH] |
7: yield [MATH] [MATH] yield atom to caller 8: end for 9: delete [MATH] [MATH] unbind [MATH] 10: end if 11: end generator The genAtoms generator (algorithm ) uses the binding store [MATH] to check whether, in the current stage of the algorithm, the given pex is bound or not. If the given pex is not bound (lines 5-9), w... |
Algorithm 3 Statues algorithm – part 3: genAtomsByType generator 1: generator genAtomsByType [MATH] 2: 3: switch [MATH] do 4: 5: |
case [MATH] [MATH] [MATH] is an elementary pex 6: for [MATH] do 7: yield [MATH] 8: end for 9: 10: case [MATH] [MATH] [MATH] is a functional pex |
11: for [MATH] do 12: yield [MATH] 13: end for 14: 15: case [MATH] [MATH] [MATH] is a tuple pex 16: for [MATH] do 17: for [MATH] |
do 18: yield [MATH] 19: end for 20: end for 21: 22: case [MATH] [MATH] [MATH] is a conditional pex 23: for [MATH] do 24: if [MATH] |
then 25: for [MATH] do 26: yield [MATH] 27: end for 28: end if 29: end for 30: 31: case [MATH] [MATH] [MATH] is a table pex 32: for |
[MATH] do 33: for [MATH] do 34: yield [MATH] 35: end for 36: end for 37: 38: end generator The genAtomsByType generator (algorithm ) is the last part of the Statues algorithm. It yields the atoms according to the semantic of each type of pex. The dispatching is presented here as a pattern matching switch construct alth... |
For elementary pex (lines 5-8), the atoms are simply the ones found in the pmf. For functional pex [MATH] (lines 10-13), the treatment consists in applying the given function [MATH] on the values of yielded atoms. As explained before, only unary functions are accepted; [MATH] -ary functions are emulated by functions ha... |
For tuple pex [MATH] (lines 15-20), the treatment consists in evaluating the combinatorial between head and tail values. Note that tuples having two or more elements are handled through recursive calls. The recursion halts when reaching the empty tuple, which is treated in the elementary pex case (i.e. singleton with p... |
For conditional pex [MATH] (lines 22-29), the atoms of condition pex [MATH] are collected one by one; for each atom containing the value [MATH] , the treatment goes on and collects the atoms of the conditioned pex [MATH] . The atoms containing the value [MATH] are simply skipped; this bypass is important because it mak... |
For table pex [MATH] (lines 31-36), the [MATH] operand represents an associative array value-to-pex [MATH] . The atoms of the key pex [MATH] are collected one by one; for the value [MATH] of each atom, the associated pex [MATH] is retrieved and the related atoms are collected in turn. |
To get a true understanding of the algorithm, one has to remember that genAtoms and genAtomsByType are not subroutines returning a list of atoms; these are generators working cooperatively and yielding atoms one by one. At each yield, new bindings are created or removed. For instance, in the treatment of the conditiona... |
The correctness of the Statues algorithm is proved in appendix 3.3 Examples of execution To demonstrate how this algorithm works practically, we shall consider a couple of toy problems and trace the key steps of the execution (more involved use cases will be given in section ). |
Example 1 We define a model that adds two Bernoulli RV [MATH] and [MATH] , with respective probabilities [MATH] and [MATH] [EQUATION] |
The DAG of [MATH] is displayed hereafter. The pmf of [MATH] is calculated by invoking [MATH] . The following table shows the sequence of steps executed by the algorithm. A step is defined by all the actions made by the main generator genAtoms to yield a new atom (line 4 of marg ). Each row shows some key data present o... |
#3 [MATH] [MATH] [MATH] [MATH] [MATH] [MATH] #4 [MATH] [MATH] [MATH] [MATH] [MATH] [MATH] Here are some explanations on this trace table. When starting [MATH] , generators genAtoms genAtomsByType will be created for each node of the DAG, in a top-down order until reaching the elementary pex [MATH] and [MATH] . At step ... |
[EQUATION] which is correct. Note that the binding mechanism has been useless in this simple example: actually, we could have the same result by skipping the genAtoms generator, e.g. replacing all the calls to it by calls to genAtomsByType . This is due to the fact that each RV appears no more than once in the queried ... |
Example 2 To demonstrate the handling of referential consistency, we consider here the addition of a RV with itself: [EQUATION] where [MATH] is defined as in the previous example. The DAG of [MATH] is displayed hereafter. |
Since the Statues algorithm enforces referential consistency, we shall legitimately expect that [MATH] is equivalent to [MATH] . Here is the trace of the execution of [MATH] following the same convention as before. |
[MATH] [MATH] [MATH] [MATH] [MATH] #1 [MATH] [MATH] [MATH] [MATH] [MATH] #2 [MATH] [MATH] [MATH] [MATH] [MATH] In contrast with the previous example, the embedded loops of tuple pex (line 17 of genAtomsByType ) both refer to the same pex, namely [MATH] ; the outer loop receives the two atoms as before but the inner loo... |
[EQUATION] that is the same as [MATH] , as expected. Example 3 We shall elaborate example 1 to demonstrate conditional RV by querying the model under some given condition. Suppose we know (by whatever means) that the sum [MATH] does not exceed 1; we want to get the pmf of [MATH] given this evidence. This query can be m... |
[EQUATION] which corresponds to the following DAG: Here is the trace of the execution of [MATH] following the same convention as example 1’s. |
[MATH] [MATH] [MATH] [MATH] Since the root node is the condition pex, the first processing is the evaluation of the condition defined on the [MATH] node of the DAG (line 23 of genAtomByType ). This shall cause the same processing as we have seen for example 1. What differs is that the atoms containing the sum are yield... |
[EQUATION] which is correct and, incidentally, different from the pmf of [MATH] : this shows that the given evidence does bring information on top of our prior beliefs. |
We have seen in this last example how the treatment of conditional pex [MATH] works: at each step, the evaluation of condition [MATH] performs some bindings; for the steps where the condition is [MATH] [MATH] is evaluated in turn taking into account these bindings ; so, the yielded values are guaranteed to verify the c... |
The three examples seen above are very basic use cases of the Statues algorithm. Actually, this algorithm is able to treat correctly far more involved probabilistic problems, in particular, all the examples given in sections 2.2 and section |
Discussion As stated before, the Statues algorithm belongs to the category of exact probabilistic algorithms. The correctness of the algorithm is established by a proof (appendix ); this proof uses invariants, formal specifications, propositional logic and basic probability theory. Beside this proof (and well before it... |
The Statues algorithm, at its very heart, explore all possible paths or ”possible worlds” (De Raedt & Kimmig,, 2013 compatible with given query. Without much surprise, it is limited by the NP-hard nature of inference on unconstrained BN (Cooper,, 1990 . However, it performs far more efficiently than a naive inference b... |
Due to the usage of generators, the execution model of the Statues algorithm is quite singular considering the large majority of algorithms based on subroutines. During algorithm execution, each pex involved in the evaluated query give rise to two generators, namely genAtoms and genAtomsByType . These generators live t... |
Since the Statues algorithm is an exact probabilistic inference algorithm, let us briefly discuss the general merits and liabilities of calculating exact probabilities. As stated before, any exact probabilistic inference algorithm is limited in practice by the intractability of many problems, including large or densely... |
Further research is definitely needed to factually assess the assets and liabilities of the Statues algorithm among the existing probabilistic inference algorithms. This includes at least the following research tracks: |
to make an objective comparison of the expressiveness of the underlying probabilistic framework with those used in other systems, |
to study the complexity of the algorithm, both for space and time aspects, and to put these results in perspective with other comparable algorithms. |
Possible extensions We present here several possible extensions or improvements that can be added to the statues algorithm and its underlying framework. |
The algorithm presents a drawback compared to other algorithms handling BN. If given evidences can be, fully or partially, expressed as a conjunctions of equalities on some elementary RVs, like [MATH] , then there is some waste of time for browsing X, Y, … domains, evaluating equalities and eventually binding them to t... |
We have seen that our probabilistic models are made up of five building blocks, namely the RV types; these are summarized in table and treated individually by the genAtomsByType generator. Although these five types have a broad scope in probabilistic modeling, it is possible, and even advisable, to add new pex types in... |
The first new type of RV is called the multi-conditional RV . The idea is to express a conjunction of given conditions as a sequence of boolean RVs: [MATH] . Actually, such conjunction is already expressible with the conditional RV presented in section 2.2.4 since the condition can be a functional RV defined by a logic... |
The second new type of RV is called the multi-functional RV . It is a generalization of the functional RV (see section 2.2.4 ): instead of being defined with one single function, it accepts a RV having a set of functions as domain. So, a multi-functional RV not only randomizes the argument but it randomizes also the fu... |
The third and last new type of RV is called mixture RV . Unlike, the two previous new types, the mixture RV is not a generalization of any RV presented so far. Basically, it is a RV choosing its value from a given set of RVs, which are equiprobable. A notation for such RV could be: |
[EQUATION] The most basic usage is to model ”bag of dice” processes (first, draw a die from the bag, then, throw this die). A more advanced usage of mixture RV regards the CPT used in Bayesian networks. In section 2.2.5 , we have seen that a CPT can be modeled as a table RV and that possible contextual independence can... |
[EQUATION] Such kind of construct could prove to be effective also when the decision logic is more naturally expressed by conditions than by a lookup table. This happens in particular when the decision RV is numerical and can be divided in non-overlapping ranges; the following example assumes that [MATH] is such RV, wh... |
[EQUATION] As explained for cascaded table RVs, the present approach is sensible to avoid redundancies on large CPT. Note however that the algorithm shall have to evaluate all conditions one by one, which could be more demanding than in the table RV approach. Therefore, it is advisable to consider mixture RVs only for ... |
Implementation – Lea and MicroLea libraries The Statues algorithm has been successfully implemented in the Python programming language (van Rossum,, 1996 ; Python Software Foundation,, 2001 , namely in the Lea and MicroLea libraries that are introduced below. Python is well suited for the task because it natively suppo... |
We provide in appendix some general suggestions about the implementation of the Statues algorithm, whatever the programming language chosen. |
6.1 Lea library The prime implementation in Python is an open-source library called Lea (Denis,, 2014 . Lea is fully workable, comprehensive and well documented; also it encompasses all the extensions presented in section |
It is worth pointing out that Lea, up to its version 2, stores probabilities as integer weights instead of commonly used floating-point numbers, as suggested in section ; this enables unlimited precision but the implementation requires special care when mixing distributions with different weight sums. Version 3 of Lea ... |
Let us mention that the understanding of the core marginalization algorithm is hard because Lea’s implementation contains several optimizations and extraneous functions, as standard indicators, information theory, random sampling, etc.; also, beside the Statues algorithm, Lea implements an approximation algorithm based... |
6.2 MicroLea library To help the understanding of the core algorithm, we have developed from scratch another open-source Python library: MicroLea, abbreviated as [MATH] Lea (Denis,, 2017 [MATH] Lea is much smaller and much simpler than Lea: it focuses on the Statues algorithm and not more; also, it represents probabili... |
As a short introduction to [MATH] Lea, we shall model the Rain-Sprinkler-Grass BN seen in section 2.2.5 and we shall perform various queries on it. Here are the statements to instantiate this BN in [MATH] Lea: |
from microlea import * rain = ElemPex.bool(0.20) sprinkler = TablePex( rain, { True : ElemPex.bool(0.01), False: ElemPex.bool(0.40)} ) grass_wet = TablePex( TuplePex(sprinkler, rain ), { (False , False): False, (False , True ): ElemPex.bool(0.80), (True , False): ElemPex.bool(0.90), (True , True ): ElemPex.bool(0.99)} ... |
Note that [MATH] Lea makes automatic conversion of fixed values into elementary pexes, when needed; this is why we can write False in place of ElemPex.bool(0) in the first entry of grass_wet |
From these definitions, [MATH] Lea allows making several queries for which the marg subroutine is called implicitly. Since Python is an interpreted language, the BN model can be queried in an interactive session, which is handy for experimenting. The method given builds a conditional pex from the boolean pex passed in ... |
sprinkler # -> False: 0.6780, True: 0.3220 P(sprinkler) # -> 0.32200000000000006 P(rain & sprinkler & grass_wet) # -> 0.00198 P(grass_wet.given(rain)) # -> 0.8019000000000001 P(rain.given(grass_wet)) # -> 0.35768767563227616 To check the consistency of these results, it is possible to retrieve the very last calculated ... |
P(rain & grass_wet) / P(grass_wet) # -> 0.35768767563227616 P(grass_wet.given(rain)) * P(rain) / P(grass_wet) # -> 0.35768767563227616 Other relationships, including the axioms of probability and the chain rule, can be verified similarly in [MATH] Lea. Note that these relationships do not appear explicitly in the Statu... |
As detailed before, functional pexes allow expressing more complex queries or evidences: P(rain.given(grass_wet & ~sprinkler)) # -> 1.0 P(rain.given(~grass_wet | ~sprinkler)) # -> 0.27889355229430157 P((rain | sprinkler).given(~grass_wet)) # -> 0.12983575649903917 P((rain == sprinkler).given(~grass_wet)) # -> 0.8702005... |
As an academic exercise, we can easily build the full joint probability distribution of the BN by using the tuple pex; this gives the probability of each atomic state of the three variables taking their interdependence into account: |
TuplePex(rain,sprinkler,grass_wet) # -> (False, False, False): 0.4800, (False, True, False): 0.0320, (False, True, True): 0.2880, (True, False, False): 0.0396, (True, False, True): 0.1584, (True, True, False): 0.0000, (True, True, True): 0.0020 One can notice that there are only 7 entries in this joint probability dist... |
To provide an example involving numerical RV, let us extend the BN with a device indicating a random value from 0 to 4; a CPT defines the pmf depending on the state of the grass: |
measure = TablePex( grass_wet, { True : ElemPex({2: 0.125, 3: 0.375, 4: 0.500 }), False: ElemPex({0: 0.500, 1: 0.375, 2: 0.125 })}) On this basis, we can freely mix booleans, numerical values and comparison operators in the same query: |
measure # -> 0: 0.2758, 1: 0.2069, 2: 0.1250, 3: 0.1681, 4: 0.2242 measure.given(~rain) # -> 0: 0.3200, 1: 0.2400, 2: 0.1250, 3: 0.1350, 4: 0.1800 P((measure <= 2).given(~rain)) # -> 0.685 P(~rain.given(measure <= 2)) # -> 0.9018089662521034 Finally, from the measure variable, we can derive a normalized value ranging f... |
norm_measure = (measure-2.) / 2. norm_measure.given(~rain) # -> -1.0: 0.3200, -0.5: 0.2400, 0.0: 0.1250, 0.5: 0.1350, 1.0: 0.1800 P(~rain.given(norm_measure <= 0.)) # -> 0.9018089662521034 |
As a last example, we present a job scheduling problem with tasks having uncertain durations. There are 3 tasks to schedule: A, B and C. There is only one precedence constraint: task B shall not be started before the end of task A; we assume that there is enough resources to execute two tasks in parallel. |
Durations of tasks A and B are characterized by known pmf (see below); duration of task C is conditioned by three possible scenarii, viz. CONSERVATIVE / EVOLUTIVE / DISRUPTIVE, each having a known probability to happen; the duration of task C is then modeled as a CPT giving a specific pmf for each scenario. We want the... |
d_A = ElemPex({3: 0.1, 4: 0.8, 5: 0.1}) d_B = ElemPex({2: 0.5, 3: 0.5}) s = ElemPex({"CONSERVATIVE": 0.6, "EVOLUTIVE": 0.3, "DISRUPTIVE": 0.1}) d_C = TablePex(s,{"CONSERVATIVE": ElemPex({2: 0.7, 3: 0.3}), "EVOLUTIVE" : ElemPex({3: 0.5, 4: 0.5}), "DISRUPTIVE" : ElemPex({7: 0.2, 8: 0.7, 9: 0.1 })}) makespan = FuncPex(max... |
The makespan has been defined by evaluating the duration of the critical path; this uses a functional pex that applies Python’s max function on the two possible paths. From this probabilistic job scheduling model, one can now make several queries to calculate probability distributions of makespan and efforts, possibly ... |
makespan # -> 5: 0.0450, 6: 0.4050, 7: 0.4240, 8: 0.1160, 9: 0.0100 makespan.given(s == "CONSERVATIVE") # -> 5: 0.0500, 6: 0.4500, 7: 0.4500, 8: 0.0500 makespan.given(s != "CONSERVATIVE") # -> 5: 0.0375, 6: 0.3375, 7: 0.3850, 8: 0.2150, 9: 0.0250 efforts.given((s == "DISRUPTIVE") & (efforts <= 14)) # -> 12: 0.0183, 13:... |
Although not conventional, backward reasoning may be done also to infer explanations from posterior measures, assuming that some causal variables (namely, the scenario and/or specific task durations) remain uncertain. |
We see in all these examples that the different pex types can be used and composed together to make expressive probabilistic models and queries, following the idea of probabilistic programming. There are many other examples and use cases provided on [MATH] Lea and Lea project pages (the syntax and output format in Lea ... |
Conclusions In the present paper, we have introduced a framework, namely the -expressions, that is meant to cover several probabilistic modeling techniques for discrete random variables having a finite domain. In essence, this framework provides primitives to define probabilistic models as direct acyclic graphs capturi... |
We have then presented a new algorithm, the Statues algorithm, which makes exact marginalization inference on those models. This algorithm relies on a special binding mechanism that uses recursive generators. Some simple examples have been provided to show this algorithm in action. In the last part, we have presented t... |
The merits and liabilities of the Statues algorithm have been shortly discussed, as well as possible extensions. The algorithm handles only discrete elements and it does not overcome the computational limitations of exact probabilistic inference. However, one of its interests in the perspective of probabilistic program... |
Acknowledgments The author warmly thanks Nicky van Foreest for reviewing the first version of the present paper and for providing fruitful advices to improve it. The author is grateful to Frédéric and Marie-Astrid Buelens for their wise recommendations about writing a scientific paper. The author thanks Gilles Scouvart... |
This research did not receive any specific grant from funding agencies in the public, commercial, or not-for-profit sectors. Appendix A Programming with generators |
The concept of generator in programming is linked to those of subroutine and coroutine . We assume that the prevalent notion of subroutine (known also as subprogram, function or procedure) does not require further explanation. Coroutines are generalizations of subroutines that allow for multiple entry points, that can ... |
For introducing the idea practically, let us consider the following example where we define a generator [MATH] ) and a subroutine ( main ) that calls this generator. |
Algorithm 4 basic example of generator 1: generator genMessages ( ) 2: yield "1, 2, 3!" 3: for [MATH] do 4: yield [MATH] 5: end for |
6: end generator 7: 8: function main ( ) 9: display "starting..." 10: for [MATH] do 11: display [MATH] 12: end for 13: display "end" |
14: end function When calling main , the genMessages is called and it yields three textual messages, one by one, to main ’s loop. Just after each yield statement, genMessages freezes and gives back the control to main ; at each for loop iteration of main , the generator genMessages is resumed just after the yield . Her... |
starting... received: 1, 2, 3! received: Red light! received: Green light! end This trace clearly shows that the generator and its caller work in close cooperation, the execution being interleaved, the control flow going back and forth between the two. This contrasts with a usual subroutine, which returns one single re... |
To elaborate the idea, let us present a less contrived example, which demonstrates the use of recursive generators. Consider the following problem: |
– Given two integers [MATH] and [MATH] such that [MATH] , which are the binary words of [MATH] bits having exactly [MATH] bits equal to one? |
To give an example of results that we expect, here is the list of 4 bits-long words having exactly 2 ones ( [MATH] [MATH] ): [EQUATION] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.