Modeling dependencies with Bayesian and
139Modeling dependencies
child for each value of the parent. Figaro has a lot of constructs that use Chain, so in many cases you’re using Chain even if it doesn’t look like it.
Here are some equivalent examples, all expressing that if the printer power button is off, the printer will definitely be down, but if the power button is on, the printer could be up or down:
val printerPowerButtonOn = Flip(0.95)
val printerState = Chain(printerPowerButtonOn, (on: Boolean) => if (on) Select(0.2 -> 'down, 0.8 -> 'up) else Constant('down)
val printerState = If(printerPowerButtonOn, Select(0.2 -> 'down, 0.8 -> 'up), Constant('down))
val printerState =
CPD(printerPowerButtonOn, false -> Constant('down), true -> Select(0.2 -> 'down, 0.8 -> 'up))
val printerState = RichCPD(printerPowerButtonOn,
OneOf(false) -> Constant('down), * -> Select(0.2 -> 'down, 0.8 -> 'up))
As mentioned earlier, one kind of asymmetric relationship is between a parameter and a variable that depends on the parameter, such as the bias of a coin and a toss of that coin. Again, this can be expressed using a Chain or using a compound version of an atomic element. Here are a couple of equivalent examples:
val toss = Chain(bias, (d: Double) => Flip(d)) val toss = Flip(bias)
5.1.2 Undirected dependencies
You’ve seen that directed dependencies can represent a variety of asymmetric rela- tionships. Undirected dependencies model relationships between variables where there’s no obvious direction between them. These kinds of relationships are called
symmetric relationships. If you have variables that are correlated, but there’s no obvious Using Chain Parent element Argument to chain function Body of chain function Using If Parent element Using CPD Outcome if parent is true Outcome if parent is false Parent element
Clause specifying outcome if parent is false Clause specifying outcome if parent is true Using RichCPD Parent element Clause specifying outcome if the parent value is in the set { false } Clause specifying outcome if
generative process whereby one variable is generated before the other, an undirected dependency might be appropriate. Symmetric relationships can arise in two ways:
■ Two effects of the same cause, where the cause isn’t modeled explicitly—For example, two measurements of the same value, when you don’t have a variable for the value, or two consequences of the same event, when you don’t have a variable for the event. Clearly, if you don’t know the underlying value of an event, the two measurements or consequences are related. Imagine, in the printer sce- nario, that you have separate variables for the print quality and speed of print- ing. If you didn’t have a variable representing the state of the printer, these two variables would be related, because they’re two aspects of printing that might have the same underlying cause.
You might ask, why don’t we include a variable for the cause in our model? One possible answer is that the cause is much more complex than the effects and would be difficult to model accurately. In this chapter, you’ll see an exam- ple of image reconstruction. The image is a two-dimensional effect of a complex three-dimensional scene. It might be harder to create a correct probabilistic model of three-dimensional scenes than to model the relationships between pixels in the image.
■ Two causes of the same known effect—This one’s interesting. Usually, there’s no relationship between two causes of the same effect. For example, the paper feeder status of a printer and the toner level both influence the status of the printer as a whole, but the paper feeder status and toner level are independent. But if you learn that the printer isn’t printing well, suddenly the paper feeder status and toner level become dependent. If you learn that the toner is low, that might lead you to believe that the reason the print quality is poor is due to low toner rather than obstructed paper flow. In this example, the overall printer sta- tus is the effect, and the toner level and paper feeder status are the possible causes, and the two causes become dependent when the effect is known. This is an example of an induced dependency, which you’ll learn about in more detail in section 5.2.3. If you don’t have a variable for the effect, this becomes a symmet- ric relationship between the two causes. But it’s less usual to leave the common effect of the two causes out of the model.
EXPRESSINGUNDIRECTEDDEPENDENCIESIN FIGARO
You can express asymmetric relationships in Figaro in two ways: using constraints and using conditions. Each has an advantage and a disadvantage. The advantage of the constraints method is that it’s conceptually simpler. But the numbers that go in the con- straints are hardcoded and can’t be learned in Figaro because they aren’t accessible to a learning algorithm. The advantage of the method that uses conditions is that the numbers can be learned.
The basic principle behind the two approaches is similar. Section 5.5 describes how undirected dependencies are encoded in detail, but here’s the short version.
141