dkesada / dbnR

Gaussian dynamic Bayesian networks structure learning and inference based on the bnlearn package
GNU General Public License v3.0
47 stars 10 forks source link

DBN structure #23

Closed MLunar closed 1 year ago

MLunar commented 1 year ago

Hello! Can I define the network structure by myself, instead of acquiring the network through structure learning? I want to define an edge that go from one time slice to another. I find whitelist, blacklist, blacklist tr, but there is no whitelist tr ?

dkesada commented 1 year ago

Hi!

you can create it from scratch the same way you can create a Bayesian network in the bnlearn package with the model2network function. For example, this code:

net <- bnlearn::model2network(paste0("[X1_t_1][X3_t_1][X2_t_1|X1_t_1]",
                                     "[X4_t_1|X2_t_1:X3_t_1][X1_t_0|X1_t_1]",
                                     "[X2_t_0|X1_t_0:X1_t_1:X2_t_1]",
                                     "[X3_t_0|X3_t_1]",
                                     "[X4_t_0|X3_t_0:X2_t_0:X4_t_1]"))
class(net) <- c("dbn", class(net))
plot(net)

generates this network:

imagen

I use this method a lot in the dbnR tests to avoid learning a network and expending unnecesary time on that. It always has the same syntax of "[Node|Parent1,Parent2,...]". Just don't add whitespaces inside the strings, define all the nodes in the network and follow the naming convention of _t_0, _t_1, ...

Regarding the lack of a whitelist_tr parameter, you are right, it's missing for no particular reason. It's very likely that I forgot to add it when I was coding the blacklist_tr parameter. However, it should be very straigthforward to introduce it. I'll look into it and get back to you when I add it to the devel branch.

dkesada commented 1 year ago

I've added the whitelist_tr argument to the last version of the package in the devel branch (2d18409). With this, you should be able to force specific inter-slice arcs in the DMMHC algorithm. You can get the lastest devel version of the package with devtools by running devtools::install_github("dkesada/dbnR", ref = "devel"). I've also added the use of the whitelist_tr argument to the usage_example markdown for future reference.

MLunar commented 1 year ago

Wow, thank you very much for such clear and quick answer, I can obtain my ideal structure now, and the precision of the forecast in my DBN improves a lot!

dkesada commented 1 year ago

I'm glad to hear it!