(This post is specifically about the Python wrapper of SMILE)
Can prob_evidence(...) be called on a network with equation nodes?
For reference, prob_evidence() works for me just fine on networks trained with BS (and CPT nodes).
However, after creating a network with PC (using the same training data), calling prob_evidence() causes my script to crash without any error messages.
Genie (academic version) also crashes when trying to get the Log Likelihood using the same data set and trained network, but I chalked it up to my many open tabs and programs.
On an unrelated note, this "silent crash" also happens if I try to call get_outcome_ids() on an equation node. But at least the incompatibility here between equation nodes and trying to get their "outcome ids" is expected and could be avoided.
Calculating the probability of evidence across equation nodes
-
- Site Admin
- Posts: 1438
- Joined: Mon Nov 26, 2007 5:51 pm
Re: Calculating the probability of evidence across equation nodes
Thanks for the bug report, we will ensure the silent crashes do not occur (the program should generate a Python exception instead of crashing, of course).
Regarding P(e) for equation-based networks, I'll need to ask our theoretical division. Will post answer here once I know it.
Regarding P(e) for equation-based networks, I'll need to ask our theoretical division. Will post answer here once I know it.
-
- Site Admin
- Posts: 436
- Joined: Tue Dec 11, 2007 4:24 pm
Re: Calculating the probability of evidence across equation nodes
Probability of any evidence in a continuous node will be zero, so you cannot do that even theoretically. I suggest that you discretize your network first and then calculate P(E). You can make the interval around the evidence as small as you want but not empty/zero length.
I hope this helps,
Marek
I hope this helps,
Marek
Re: Calculating the probability of evidence across equation nodes
Thanks for the replies and suggestion!
Chance nodes with small bins seems to be working great for now, but I will keep the discretization idea of equation nodes in mind for future reference.
Chance nodes with small bins seems to be working great for now, but I will keep the discretization idea of equation nodes in mind for future reference.
Re: Calculating the probability of evidence across equation nodes
I've started using PC nets and am currently experimenting with evidence setting. Therefore, a follow-up question please:
In tutorial 7, if we insert a prob_evidence statement at the end (1.), when only node tma has evidence, we get 0.346871673479135.
This makes sense to me that it works because all other nodes are discretized.
If uncomment the inserted block of code (2.), the second prob_evidence statement causes a silent crash (as addressed before).
It's unclear to me why this doesn't work anymore, because all nodes in the network are still either discretized or with evidence.
Could anyone clarify a reason for this behavior?
Does it have anything to do with only having child nodes with evidence set, in order for prob_evidence to work?
In tutorial 7, if we insert a prob_evidence statement at the end (1.), when only node tma has evidence, we get 0.346871673479135.
This makes sense to me that it works because all other nodes are discretized.
If uncomment the inserted block of code (2.), the second prob_evidence statement causes a silent crash (as addressed before).
It's unclear to me why this doesn't work anymore, because all nodes in the network are still either discretized or with evidence.
Could anyone clarify a reason for this behavior?
Does it have anything to do with only having child nodes with evidence set, in order for prob_evidence to work?
Code: Select all
class Tutorial7:
def __init__(self):
print("Starting Tutorial7...")
net = pysmile.Network()
net.set_outlier_rejection_enabled(True)
net.set_rand_seed(42)
self.create_equation_node(
net, "tra", "Return Air Temperature", "tra=24", 23.9, 24.1, 280, 100
)
self.create_equation_node(
net,
"u_d",
"Damper Control Signal",
"u_d=Bernoulli(0.539)*0.8+0.2",
0,
1,
160,
100,
)
toa = self.create_equation_node(
net, "toa", "Outside Air Temperature", "toa=Normal(11,15)", -10, 40, 60, 100
)
# tra, toa and u_d are referenced in equation
# arcs are created automatically
tma = self.create_equation_node(
net,
"tma",
"Mixed Air Temperature",
"tma=toa*u_d+(tra-tra*u_d)",
10,
30,
110,
200,
)
print("Results with no evidence and no intervals:")
self.update_and_show_stats(net)
self.set_uniform_intervals(net, toa, 5)
self.set_uniform_intervals(net, tma, 4)
print("Results with no evidence but with set intervals for toa and tma:")
self.update_and_show_stats(net)
net.set_cont_evidence(toa, 28.5)
print("Results with outside air temperature set to 28.5:")
self.update_and_show_stats(net)
net.clear_evidence(toa)
print("Results with mixed air temperature set to 21:")
net.set_cont_evidence(tma, 21.0)
self.update_and_show_stats(net)
print("Probability of evidence:")
print(net.prob_evidence()) # 1.
# 2.
# net.set_cont_evidence(toa, 28.5)
# print("Results with outside air temperature set to 28.5:")
# self.update_and_show_stats(net)
# print("Probability of evidence:")
# print(net.prob_evidence())
-
- Site Admin
- Posts: 436
- Joined: Tue Dec 11, 2007 4:24 pm
Re: Calculating the probability of evidence across equation nodes
Hi Maghnie,
The silent crash has to do with the fact that we have not yet programmed this functionality for continuous nodes. We will fix this in one of the next releases. To make it work at the moment, please change the type of the continuous nodes from continuous/equation to discrete chance nodes before running p(e). Specifying discretization, which is I assume what you did is not quite enough. I suggest that you make a copy of the model or just copy all nodes and paste them into a new workspace/window before changing types.
I hope this helps,
Marek
The silent crash has to do with the fact that we have not yet programmed this functionality for continuous nodes. We will fix this in one of the next releases. To make it work at the moment, please change the type of the continuous nodes from continuous/equation to discrete chance nodes before running p(e). Specifying discretization, which is I assume what you did is not quite enough. I suggest that you make a copy of the model or just copy all nodes and paste them into a new workspace/window before changing types.
I hope this helps,
Marek