/******************************************************************************** A Bayesian network for fault diagnosis in a power supply network modelled in PRISM Version 2- adding a weather random variable {goodWeather,badWeather}, whose value changes the probability that wires are up. An attempt to get more 'natural' answers pp: a power plant wi: wires ni: connecting nodes vi: villages ~~~~~~ || __ ######## w1 w2 w3 w4 /||\ ## pp ##---------(n1)---------(n2)---------(n3)---------[v3] ######## | | | ######## | w5 | w6 | w7 | | | | __ __ (n4) /||\ /||\ / \ [v1] [v2] w8 / \ w9 / \ __ __ /||\ /||\ [v4] [v5] Each entity may be *up* or *down* meaning: - for pp, whether it is working or not - for ni and vi, whether electric current is present - for wi, whether it is able to port electric current or not (read up/down literally) The villages are observables, meaning that information about whether each village has electricity or not can be observed. The state of the other entities are 'hidden' in the sense that from observations we will try to figure out the most probably states of other components. This is useful in order to decide where it is best to send out a repair team to check entities and possibly repair them. Whether the power plant or a given wire is up or down is independent of anything else. Whether any other given entity ni or vi is up or down depends on the previous ni-or-vi-or-pp and the wire supposed to connect them. In the probabilities below, we assume a very high reliability of any component, and we assume also a small small probability that electricity is observed at a given place even if the there is no electricity in the previous node or connecting cable is down - this may be due to disturbed information or the unlikely event that the villagers has set up some a small motor driven electricity generator. However, if weather is 'bad', be lower probabilities that wires are up. As we will se below, the high prior probability that wires and other entities are up has unexpected consequences. (C) Henning Christiansen, 2007 *********************************************************************/ values(weather,[goodWeather,badWeather]). values(pp, [ppup,ppdown]). values(w1(_), [w1up,w1down]). % w1(weather). values(w2(_), [w2up,w2down]). % ... values(w3(_), [w3up,w3down]). values(w4(_), [w4up,w4down]). values(w5(_), [w5up,w5down]). values(w6(_), [w6up,w6down]). values(w7(_), [w7up,w7down]). values(w8(_), [w8up,w8down]). values(w9(_), [w9up,w9down]). values(n1(_,_), [n1up,n1down]). %n(ppState,w1state) values(n2(_,_), [n2up,n2down]). %n(n1State,w2state) values(n3(_,_), [n3up,n3down]). %n(n2State,w3state) values(n4(_,_), [n4up,n4down]). %n(n1State,w5state) values(v1(_,_), [v1up,v1down]). %n(n2State,w6state) values(v2(_,_), [v2up,v2down]). %n(n3State,w7state) values(v3(_,_), [v3up,v3down]). %n(n3State,w4state) values(v4(_,_), [v4up,v4down]). %n(n4State,w8state) values(v5(_,_), [v5up,v5down]). %n(n4State,w9state) target(observable_world,5). observable_world(WEATHER,V1,V2,V3,V4,V5):- world(WEATHER,PP,W1,W2,W3,W4,W5,W6,W7,W8,W9, N1,N2,N3,N4, V1,V2,V3,V4,V5). world(WEATHER,PP,W1,W2,W3,W4,W5,W6,W7,W8,W9, N1,N2,N3,N4, V1,V2,V3,V4,V5):- msw(weather,WEATHER), msw(pp,PP), msw(w1(WEATHER),W1), msw(w2(WEATHER),W2), msw(w3(WEATHER),W3), msw(w4(WEATHER),W4), msw(w5(WEATHER),W5), msw(w6(WEATHER),W6), msw(w7(WEATHER),W7), msw(w8(WEATHER),W8), msw(w9(WEATHER),W9), msw(n1(PP,W1),N1), msw(n2(N1,W2),N2), msw(n3(N2,W3),N3), msw(n4(N1,W5),N4), msw(v1(N2,W6),V1), msw(v2(N3,W7),V2), msw(v3(N3,W4),V3), msw(v4(N4,W8),V4), msw(v5(N4,W9),V5). set_params:- set_sw(weather, [0.85, 0.15]), set_sw(pp, [0.999,0.001]), set_sw(w1(goodWeather), [0.999,0.001]), set_sw(w2(goodWeather), [0.999,0.001]), set_sw(w3(goodWeather), [0.999,0.001]), set_sw(w4(goodWeather), [0.999,0.001]), set_sw(w5(goodWeather), [0.999,0.001]), set_sw(w6(goodWeather), [0.999,0.001]), set_sw(w7(goodWeather), [0.999,0.001]), set_sw(w8(goodWeather), [0.999,0.001]), set_sw(w9(goodWeather), [0.999,0.001]), set_sw(w1(badWeather), [0.9,0.1]), set_sw(w2(badWeather), [0.9,0.1]), set_sw(w3(badWeather), [0.9,0.1]), set_sw(w4(badWeather), [0.9,0.1]), set_sw(w5(badWeather), [0.9,0.1]), set_sw(w6(badWeather), [0.9,0.1]), set_sw(w7(badWeather), [0.9,0.1]), set_sw(w8(badWeather), [0.9,0.1]), set_sw(w9(badWeather), [0.9,0.1]), set_sw(n1(ppup,w1up), [0.999,0.001]), set_sw(n1(ppup,w1down), [0.001, 0.999]), set_sw(n1(ppdown,w1up), [0.001, 0.999]), set_sw(n1(ppdown,w1down), [0.001, 0.999]), set_sw(n2(n1up,w2up), [0.999,0.001]), set_sw(n2(n1up,w2down), [0.001, 0.999]), set_sw(n2(n1down,w2up), [0.001, 0.999]), set_sw(n2(n1down,w2down), [0.001, 0.999]), set_sw(n3(n2up,w3up), [0.999,0.001]), set_sw(n3(n2up,w3down), [0.001, 0.999]), set_sw(n3(n2down,w3up), [0.001, 0.999]), set_sw(n3(n2down,w3down), [0.001, 0.999]), set_sw(n4(n1up,w5up), [0.999,0.001]), set_sw(n4(n1up,w5down), [0.001, 0.999]), set_sw(n4(n1down,w5up), [0.001, 0.999]), set_sw(n4(n1down,w5down), [0.001, 0.999]), set_sw(v1(n2up,w6up), [0.999,0.001]), set_sw(v1(n2up,w6down), [0.001, 0.999]), set_sw(v1(n2down,w6up), [0.001, 0.999]), set_sw(v1(n2down,w6down), [0.001, 0.999]), set_sw(v2(n3up,w7up), [0.999,0.001]), set_sw(v2(n3up,w7down), [0.001, 0.999]), set_sw(v2(n3down,w7up), [0.001, 0.999]), set_sw(v2(n3down,w7down), [0.001, 0.999]), set_sw(v3(n3up,w4up), [0.999,0.001]), set_sw(v3(n3up,w4down), [0.001, 0.999]), set_sw(v3(n3down,w4up), [0.001, 0.999]), set_sw(v3(n3down,w4down), [0.001, 0.999]), set_sw(v4(n4up,w8up), [0.999,0.001]), set_sw(v4(n4up,w8down), [0.001, 0.999]), set_sw(v4(n4down,w8up), [0.001, 0.999]), set_sw(v4(n4down,w8down), [0.001, 0.999]), set_sw(v5(n4up,w9up), [0.999,0.001]), set_sw(v5(n4up,w9down), [0.001, 0.999]), set_sw(v5(n4down,w9up), [0.001, 0.999]), set_sw(v5(n4down,w9down), [0.001, 0.999]). :- set_params. w1GoodWeather:- chindsight_agg(observable_world(goodWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,query,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)). w2GoodWeather:- chindsight_agg(observable_world(goodWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,query,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)). w3GoodWeather:- chindsight_agg(observable_world(goodWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,query,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)). w4GoodWeather:- chindsight_agg(observable_world(goodWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,query,_,_,_,_,_,_,_,_,_,_,_,_,_,_)). w5GoodWeather:- chindsight_agg(observable_world(goodWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,_,query,_,_,_,_,_,_,_,_,_,_,_,_,_)). w6GoodWeather:- chindsight_agg(observable_world(goodWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,_,_,query,_,_,_,_,_,_,_,_,_,_,_,_)). w7GoodWeather:- chindsight_agg(observable_world(goodWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,_,_,_,query,_,_,_,_,_,_,_,_,_,_,_)). w8GoodWeather:- chindsight_agg(observable_world(goodWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,_,_,_,_,query,_,_,_,_,_,_,_,_,_,_)). w9GoodWeather:- chindsight_agg(observable_world(goodWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,_,_,_,_,_,query,_,_,_,_,_,_,_,_,_)). wwGoodWeather:- w1GoodWeather,w2GoodWeather,w3GoodWeather,w4GoodWeather,w5GoodWeather,w6GoodWeather,w7GoodWeather,w8GoodWeather,w9GoodWeather. w1BadWeather:- chindsight_agg(observable_world(badWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,query,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)). w2BadWeather:- chindsight_agg(observable_world(badWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,query,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)). w3BadWeather:- chindsight_agg(observable_world(badWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,query,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)). w4BadWeather:- chindsight_agg(observable_world(badWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,query,_,_,_,_,_,_,_,_,_,_,_,_,_,_)). w5BadWeather:- chindsight_agg(observable_world(badWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,_,query,_,_,_,_,_,_,_,_,_,_,_,_,_)). w6BadWeather:- chindsight_agg(observable_world(badWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,_,_,query,_,_,_,_,_,_,_,_,_,_,_,_)). w7BadWeather:- chindsight_agg(observable_world(badWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,_,_,_,query,_,_,_,_,_,_,_,_,_,_,_)). w8BadWeather:- chindsight_agg(observable_world(badWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,_,_,_,_,query,_,_,_,_,_,_,_,_,_,_)). w9BadWeather:- chindsight_agg(observable_world(badWeather,v1up,v2down,v3up,v4down,v5down), world(_,_,_,_,_,_,_,_,_,_,query,_,_,_,_,_,_,_,_,_)). wwBadWeather:- w1BadWeather,w2BadWeather,w3BadWeather,w4BadWeather,w5BadWeather,w6BadWeather,w7BadWeather,w8BadWeather,w9BadWeather. /******************* | ?- w7GoodWeather. conditional hindsight probabilities: world(*,*,*,*,*,*,*,*,w7down,*,*,*,*,*,*,*,*,*,*,*): 0.499124850902673 world(*,*,*,*,*,*,*,*,w7up,*,*,*,*,*,*,*,*,*,*,*): 0.500875149097325 % looks a bit counterintuitive, but due to high prior probs that wires are up. | ?- w7BadWeather conditional hindsight probabilities: world(*,*,*,*,*,*,*,*,w7down,*,*,*,*,*,*,*,*,*,*,*): 0.989956672723413 world(*,*,*,*,*,*,*,*,w7up,*,*,*,*,*,*,*,*,*,*,*): 0.010043327276590 % This look more natural! Let us make viterbi calculation. When weather is given to be bad, we get the expected result. | ?- viterbig( world(badWeather,PP,W1,W2,W3,W4,W5,W6,W7,W8,W9,N1,N2,N3,N4,v1up,v2down,v3up,v4down,v5down) ). N3 = n3up N2 = n2up N1 = n1up W9 = w9up W8 = w8up W7 = w7down W6 = w6up W5 = w5down W4 = w4up W3 = w3up W2 = w2up W1 = w1up PP = ppup N4 = n4down ? yes In the very unlikely situation the the weather is good and 3 wires are down, we get strange results: | ?- viterbig( world(goodWeather,PP,W1,W2,W3,W4,W5,W6,W7,W8,W9,N1,N2,N3,N4,v1up,v2down,v3up,v4down,v5down) ). N3 = n3up N2 = n2up N1 = n1up W9 = w9up W8 = w8up W7 = w7up W6 = w6up W5 = w5down W4 = w4up W3 = w3up W2 = w2up W1 = w1up PP = ppup N4 = n4down ? yes The following shows that the systems easily can figure out about the weaher when something is wrong: | ?- viterbig( world(Weather,PP,W1,W2,W3,W4,W5,W6,W7,W8,W9,N1,N2,N3,N4,v1up,v2down,v3up,v4down,v5down) ). N3 = n3up N2 = n2up N1 = n1up W9 = w9up W8 = w8up W7 = w7down W6 = w6up W5 = w5down W4 = w4up W3 = w3up W2 = w2up W1 = w1up PP = ppup Weather = badWeather N4 = n4down ? yes ******************/