rSMILE Network$clearEvidence

The engine.
Post Reply
CamillaNegri1
Posts: 14
Joined: Tue Mar 03, 2020 12:06 pm

rSMILE Network$clearEvidence

Post by CamillaNegri1 »

Hi,

I am having trouble using the clearEvidence function. I was wondering: does it work on all kinds of nodes? It does not seem to work for chance nodes in my case.

Thanks,
CN
piotr [BayesFusion]
Site Admin
Posts: 60
Joined: Mon Nov 06, 2017 6:41 pm

Re: rSMILE Network$clearEvidence

Post by piotr [BayesFusion] »

ClearEvidence function should work on chance nodes. Can you share the code you think is not working?
CamillaNegri1
Posts: 14
Joined: Tue Mar 03, 2020 12:06 pm

Re: rSMILE Network$clearEvidence

Post by CamillaNegri1 »

Hi piotr,

I'm not sure I can share the network, however, it was something like this

```{r}
net$getNodeDefinition("mychance_node")
net$setEvidence("mychance_node", "present")
net$getNodeValue("mychance_node") # this shows that in the line above we've set the evidence as 100% present which is correct
net$updateBeliefs()
beliefs <- net$getNodeValue("my_target_node")
updateAndShowStats(net)
net$clearEvidence("mychance_node")
net$getNodeDefinition("mychance_node")
net$getNodeValue("mychance_node")
```

the line net$getNodeDefinition("mychance_node") gets me: 0.14 0.86 which is correct, it is not 1 0 anymore. The last line net$getNodeValue("mychance_node"), which I thought I would use to check if clearEvidence worked, gets me this:

Error in net$getNodeValue() : RSmile error occured
SMILE Error Occured in: Network.GetValue
ErrNo=1

I guess using net$getNodeValue is not the best course of action, as there is no value set after I clear the evidence, right?

Thanks,
Camilla
piotr [BayesFusion]
Site Admin
Posts: 60
Joined: Mon Nov 06, 2017 6:41 pm

Re: rSMILE Network$clearEvidence

Post by piotr [BayesFusion] »

I guess using net$getNodeValue is not the best course of action, as there is no value set after I clear the evidence, right?
Yes, you have to call net$updateBeliefs before getting node values.
nzsk
Posts: 24
Joined: Thu Aug 29, 2019 8:27 am

Re: rSMILE Network$clearEvidence

Post by nzsk »

My experience is that the evidence doesn’t get cleared from chance nodes (neither does the virtual evidence), even after you update. So I don’t get the error message mentioned above but I still can’t clear the evidence. How can this be?
piotr [BayesFusion]
Site Admin
Posts: 60
Joined: Mon Nov 06, 2017 6:41 pm

Re: rSMILE Network$clearEvidence

Post by piotr [BayesFusion] »

Could you please share the code that doesn't work? If you don't want to share it on the forum, you can email me at piotr@bayesfusion.com

Code below works fine with rSMILE 2.0.10

Code: Select all

net <- Network()
handle <- net$addNode(net$NodeType$CPT)
net$setNodeDefinition(handle, c(0.2, 0.8))
net$updateBeliefs()
v <- net$getNodeValue(handle) # 0.2 0.8
net$setEvidence(handle, 0)
v <- net$getNodeValue(handle) # 1 0
net$clearEvidence(handle)
net$isValueValid(handle) # FALSE
net$updateBeliefs()
v <- net$getNodeValue(handle) # 0.2 0.8
piotr [BayesFusion]
Site Admin
Posts: 60
Joined: Mon Nov 06, 2017 6:41 pm

Re: rSMILE Network$clearEvidence

Post by piotr [BayesFusion] »

Note that:
  • evidence is not cleared after updateBeliefs
  • the node value has a 'valid' flag, which can be checked with isValueValid
  • setting or clearing the evidence invalidates the value of the node
  • node values are valid when updateBeliefs is successful
nzsk
Posts: 24
Joined: Thu Aug 29, 2019 8:27 am

Re: rSMILE Network$clearEvidence

Post by nzsk »

Dear Piotr,

Many thanks for the reply, I tested your code and in my network and I get some peculiar results. I can email you the network separately as I don't have the right to share it publicly but it's the one published in this paper https://hess.copernicus.org/articles/26/1261/2022/ and it's a hybrid network. I was hoping to use 'virtual evidence' on a discrete node whilst avoiding discretisation of the network.

My priors for the 'Crop Type' node are c(0.01,0.13,0.12,0.645,0.095)

I then run the network
net$updateBeliefs()

and get posterior probabilities
net$getNodeValue("CropType") c(0.0108, 0.1266, 0.1189, 0.6507, 0.0930)

my target node is actually Overland flow load OLR, which is a continuous node and I get 10,000 simulated posterior values with
net$getNodeValue("OLR")

Then I set Virtual Evidence - this will discretise the network - which is a problem - I would like to set virtual evidence to avoid discretisation
net$setVirtualEvidence("CropType",c(0.05,0.05,0.1,0.7,0.1))
net$isValueValid("OLR") FALSE
net$updateBeliefs()
net$getNodeValue("CropType") - gives me posterior probabilities 0.001041667 0.013541667 0.025000000 0.940625000 0.019791667
net$getNodeValue("OLR") - gives me posterior probabilities 0.72068871 0.09775436 0.18155693

Then I try to clear this virtual evidence
net$clearAllEvidence
net$updateBeliefs()
net$getNodeValue("CropType") - gives me the same posterior probabilities as above 0.001041667 0.013541667 0.025000000 0.940625000 0.019791667
net$getNodeValue("OLR") - very similar posterior prob. as above 0.71978332 0.09689689 0.18331979

It seems that the virtual evidence 'sticks' and does not get cleared from the chance node? I would expect the network to revert back to continuous, when all evidence has been cleared?

Also, why does the network get discretised, when I set virtual evidence on a chance node - even when that node is a parent node? But perhaps I should start a separate post about this second problem?

Thank you

Miriam
piotr [BayesFusion]
Site Admin
Posts: 60
Joined: Mon Nov 06, 2017 6:41 pm

Re: rSMILE Network$clearEvidence

Post by piotr [BayesFusion] »

Are you using rSMILE 2.0.10? There were changes between this version and previous ones that could affect the results when using various Virtual Evidence methods.

Also - can I ask you to share the xdsl file by email or in a private message on the forum? I tried to replicate this behavior with another hybrid network with similar ancestor-descendant dependencies and the network behaved differently - after calling clearAllEvidence and updateBeliefs the getNodeValue method called on Equation Node returns array with generated samples.
nzsk
Posts: 24
Joined: Thu Aug 29, 2019 8:27 am

Re: rSMILE Network$clearEvidence

Post by nzsk »

Hi Piotr, yes, I'm using rSMILE 2.0.10

I'll send the network in a private message - many thanks!
piotr [BayesFusion]
Site Admin
Posts: 60
Joined: Mon Nov 06, 2017 6:41 pm

Re: rSMILE Network$clearEvidence

Post by piotr [BayesFusion] »

I think you forgot the parentheses calling the clearAllEvidence function.

Change this code:

Code: Select all

net$clearAllEvidence
to this code:

Code: Select all

net$clearAllEvidence()
in your script. Clearing the evidence in the network that I got in PM works as intended - after calling clearAllEvidence, the contiguous node returns samples.
nzsk
Posts: 24
Joined: Thu Aug 29, 2019 8:27 am

Re: rSMILE Network$clearEvidence

Post by nzsk »

OK, many thanks, a simple error!
Post Reply