BayesianNetwork icon indicating copy to clipboard operation
BayesianNetwork copied to clipboard

Inference on multiple evidence nodes?

Open Tavpritesh opened this issue 8 years ago • 7 comments

Thanks for the great app. Is it possible to do inference on nodes of interest after setting multiple evidence conditions. Is that something that you plan to add? Perhaps a list of evidence nodes in the source code? Would be very helpful if you can provide a code snippet that can be extended. Thanks.

Tavpritesh avatar Aug 02 '17 16:08 Tavpritesh

@tavpritesh currently not possible but something I'd hoped to have time to work on. I suppose you could do this in the editor without leaving the app. I could get you a code snippet if needed. Otherwise I hope to have this option in the nearish future.

paulgovan avatar Aug 03 '17 17:08 paulgovan

Thanks Paul, a snippet would be very useful. Ability to do so will make BayesianNetwork "the tool" for my work. Currently we are tied down to a commercial software.

Tavpritesh avatar Aug 03 '17 23:08 Tavpritesh

For example, using the default discrete network and entering the following in the editor:

prop.table(
    table(
        bnlearn::cpdist(fit(), "A", (C == "c") & (E == "c"))
    )
)

Gives you the conditional probability table for "A" given C = "c" and E = "c".

Glad to hear that you're enjoying the app. I would love to hear about the types of applications that you're using it for. I'm always looking for feedback too.

paulgovan avatar Aug 05 '17 01:08 paulgovan

@paulgovan Thanks for the snippet, much appreciated. I am using BayesianNetwork for healthcare related analysis and am hoping to extend it to a stand-alone app that we can build along with our paper. Since inference arrived, your package is my hope to avoid re-inventing the wheel while moving away from commercial software. I will keep you posted on my experience and feedback with this. Thanks a lot for your quick responses.

Tavpritesh avatar Aug 08 '17 22:08 Tavpritesh

I'm making a sort of spin off with the app using the alarm dataset that's a lot less dynamic than @paulgovan's, but I used this string manipulation to create multiple evidence nodes that can be used within the cpdist function -- hope this can be of use!

CO <- "HIGH" #would really be input$CO
HIST <- "FALSE" #input$HIST
HRPB <- "" #input$HRBP

# create a string for each evidence node, allow to be left blank 
str1 <<- ifelse(CO == "NA", NA, paste0("(CO == ", "'", CO), "')"))
str2 <<- ifelse(HIST == "NA", NA, paste0("(HIST == ", "'", HIST, "')"))
str3 <<- ifelse(HRBP == "NA", NA, paste0("(HRBP == ", "'", HRBP, "')"))

# Take strings wirth values and paste together
myStr <<- na.omit(c(str1, str2, str3))

# Put &s between strings with values - use this in cpdist
finalstr <<- paste0(myStr, collapse = " & ")

Cheers!

MayaGans avatar Sep 15 '18 22:09 MayaGans

Thanks for the contribution @MayaGans. I'll try to implement this in the next few days. Would be cool to have this feature.

paulgovan avatar Sep 17 '18 17:09 paulgovan

I think I may have spoken too soon. After revisiting this issue, the problem I have is not how to capture multiple evidence nodes, but how to create a dynamic UI to capture those inputs. So if your network has 100 nodes, do you want to enter evidence for all of them? Some of them? It gets messy when thinking about all of the different possibilities.

paulgovan avatar Sep 19 '18 19:09 paulgovan