bnlearn | : exclamation : This is a read-only mirror of the CRAN R | Machine Learning library

 by   cran C Version: Current License: No License

kandi X-RAY | bnlearn Summary

kandi X-RAY | bnlearn Summary

bnlearn is a C library typically used in Artificial Intelligence, Machine Learning applications. bnlearn has no bugs, it has no vulnerabilities and it has low support. You can download it from GitHub.

bnlearn
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              bnlearn has a low active ecosystem.
              It has 33 star(s) with 33 fork(s). There are 8 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              bnlearn has no issues reported. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of bnlearn is current.

            kandi-Quality Quality

              bnlearn has 0 bugs and 0 code smells.

            kandi-Security Security

              bnlearn has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              bnlearn code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              bnlearn does not have a standard license declared.
              Check the repository for any license declaration and review the terms closely.
              OutlinedDot
              Without a license, all rights are reserved, and you cannot use the library in your applications.

            kandi-Reuse Reuse

              bnlearn releases are not available. You will need to build from source code and install.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of bnlearn
            Get all kandi verified functions for this library.

            bnlearn Key Features

            No Key Features are available at this moment for bnlearn.

            bnlearn Examples and Code Snippets

            No Code Snippets are available at this moment for bnlearn.

            Community Discussions

            QUESTION

            Bayesian network using BNLEARN package in python
            Asked 2022-Mar-07 at 16:08

            can we create a Bayesian network using bnlearn package in python for 7 continuous variables (if the variables are categorical I can create a BN model)? If so, can you please guide me to any reference or example.

            ...

            ANSWER

            Answered 2022-Mar-07 at 16:08

            At the moment bnlearn can only be used for discrete/categorical modeling. There are possibilities to model your data though. You can for example discretize your variables with domain/experts knowledge or maybe a more data-driven threshold. Lets say, if you have a temperature, you can mark temperature < 0 as freezing, and >0 as normal. Or many smaller categories.

            Source https://stackoverflow.com/questions/69434821

            QUESTION

            bnlearn Error: Wrong number of conditional probability distributions
            Asked 2021-Oct-10 at 19:29

            I am learning to work with bnlearn and I keep running into the following error in the last line of my code below:

            Error in custom.fit(dag, cpt) : wrong number of conditional probability distributions

            What am I doing wrong?

            ...

            ANSWER

            Answered 2021-Oct-10 at 19:29

            You have several errors in your CPT definitions. Primarily, you need to make sure that:

            • the number of probabilities supplied are equal to the product of the number of states in the child and parent nodes,
            • that the number of dimensions of the matrix/array is equal to the number of parent nodes plus one, for the child node,
            • the child node should be given in the first dimension when the node dimension is greater than one.
            • the names given in the dimnames arguments (e.g. the names in dimnames=list(ThisName = ...)) should match the names that were defined in the DAG, in your case with modelstring and in my answer with model2network. (So my earlier suggestion of using dimnames=list(cptNBLW = ...) should be dimnames=list(nblw = ...) to match how node nblw was declared in the model string)

            You also did not add node f into your cpt list.

            Below is your code with comments where things have been changed. (I have commented out the offending lines and added ones straight after)

            Source https://stackoverflow.com/questions/69508863

            QUESTION

            simulating data with bayesian network in R using own specification
            Asked 2021-Sep-30 at 16:42

            Say I have a simple DAG representing a confounding variable X = Smoking, a treatment T and outcome Y = Death such that:

            T ~ X
            Y ~ T + X

            Is it possible to produce a synthetic dataset of say 1m observations that follows some specified conditional probabilities:

            ...

            ANSWER

            Answered 2021-Sep-30 at 16:42

            It will be easier to let existing packages do this for you; like bnlearn. You can use custom.fit to specify the DAG and the CPTs and then use rbn to draw samples from it.

            An example

            Source https://stackoverflow.com/questions/69395642

            QUESTION

            How do I graph a Bayesian Network with instantiated nodes using bnlearn and graphviz?
            Asked 2021-Sep-14 at 21:41

            I am trying to graph a Bayesian Network (BN) with instantiated nodes using the libraries bnlearn and Rgraphviz. My workflow is as follow:

            After creating a data frame with random data (the data I am actually using is obviously not random) I then discretise the data, structure learn the directed acyclic graph (DAG), fit the data to the DAG and then plot the DAG. I also plot a DAG which shows the posterior probabilities of each of the nodes.

            ...

            ANSWER

            Answered 2021-Sep-14 at 21:41

            How about using cpdist to draw samples from the posterior given the evidence. You can then estimate the updated parameters using bn.fit using the cpdist samples. Then plot as before.

            An example:

            Source https://stackoverflow.com/questions/69184390

            QUESTION

            How do I represent domain knowledge information with bnlearn
            Asked 2021-Jun-05 at 14:47

            I am learning about Dynamic Bayesian Network models using the R package bnlearn. To this end, I am following this paper where they impose certain constraints in the form of 6 layers (Table 1 in the paper):

            ...

            ANSWER

            Answered 2021-Jun-05 at 14:47

            You can add domain knowledge or constraints to structure learning in a couple of ways.

            • If you want to specify the network structure and parameters using domain knowledge, you can build the network manually using custom.fit.

            • If you want to estimate the structure of the BN from data then you can impose constraints on edge direction & edge presence using the whitelist and blacklist parameters in the structure learning algorithms.

            • A prior can be placed on the edges in structure learning (e.g. prior="cs", where "If prior is cs, beta is a data frame with columns from, to and prob specifying the prior probability for a set of arcs. A uniform probability distribution is assumed for the remaining arcs."). There are other priors that can be used.

            Source https://stackoverflow.com/questions/67785734

            QUESTION

            How to change probability table in object of class bn.fit (bn.fit.dnet) from bnlearn library?
            Asked 2020-Jun-21 at 21:34

            I try to modify object of class bn.fit (bn.fit.dnet) from R's bnlearn library. I need

            1. to set equal probabilities for every row in bn.fit$node$prob table. For this I use next code: ...

            ANSWER

            Answered 2020-Jun-21 at 21:34

            Regarding (1), modify takes a list or an atomic vector. bn_fit is of class bn.fit, bn.fit.dnet, however, under the hood it is a list too, since calling typeof() yields list. My guess is that there is no S3 generic method for subsetting these classes so R figures out that it is essentially a list and accordingly strips the class arguments. So subsetting bn_fit turns it into class list, and therefore you can use modify on it. Subsetting can even be done with empty brackets [], it will just return the object, but this time as class list. An alternative that I use below is to "manually" set the class attribute to NULL via attr(bnfit, "class") <- NULL.

            Regarding (2), I wrote a tidyverse based function which can be used to alter the prob table of each node into a bayesm::rdirichlet distribution (see code below). The user still needs to provide part of the alpha argument (the length argument is given by the length of each prob table). Under the hood the function is relying on purrr::modify. It takes care of the classes by stripping them first and adding them back once the modification is done. My approach is to turn the prob tables into data.frames then modify the Freq column and adjust it for existing other variables (groups) and then translate that data.frame back into a table using xtabs and formulation notation via reformulate.

            I'm not so deep into bayesian networks, so I do not know to what extent this function can be generalized, or whether it only works on the dataset you provided. Further, please test if the modified object is accepted by functions expecting class bn.fit, bn.fit.dnet.

            I tried to comment each step of my code, but please ask if something is not clear.

            (3) Regarding your question why NROW(.x) does not work in your code and you have to use NROW(node$prob) instead: This has to do with the way modify loops over the prob tables. A good way to check over what elements modify is looping over is to use purrr::pluck.

            Source https://stackoverflow.com/questions/62430457

            QUESTION

            Using cpquery function for several pairs from dataset
            Asked 2020-Jun-01 at 15:33

            I am relatively beginner in R and trying to figure out how to use cpquery function for bnlearn package for all edges of DAG.

            First of all, I created a bn object, a network of bn and a table with all strengths.

            ...

            ANSWER

            Answered 2020-Jun-01 at 15:33

            cpquery is quite difficult to work with programmatically. If you look at the examples in the help page you can see the author uses eval(parse(...)) to build the queries. I have added two approaches below, one using the methods from the help page and one using cpdist to draw samples and reweighting to get the probabilities.

            Your example

            Source https://stackoverflow.com/questions/62124076

            QUESTION

            Setting layers for a Dynamic Bayesian Network with bnstruct in R
            Asked 2020-May-08 at 13:58

            I am currently creating a DBN using bnstruct package in R. I have 9 variables in each 6 time steps. I have biotic and abiotic variables. I want to prevent the biotic variables to be parents of the abiotic variables.For a Bayesian Network, it's pretty easy to implement using for instance layering = c(1,1,2,2,2) in learn.dynamic.network().

            But a problem rises for the Dynamic part: I would like to keep preventing biotic variables to be parents of abiotic ones in every time step while preventing edges to appear between any variables from t+1 to t.

            If I use in layering =:

            • 1 for abiotic variables at t1
            • 2 for biotic variables at t1
            • 3 for abiotic variables at t2
            • 4 for biotic variables at t2...

            I allow biotic variables from t-1 to explain the abiotic variables at t (and I don't want that).

            So I tried:

            ...

            ANSWER

            Answered 2020-May-08 at 08:25

            With the mmhc algorithm that is used as default, you can use the layer.struct parameter to specify which pairs of layers are allowed to have edges between them. layer.struct takes a binary matrix where cell i,j is 1 if there can be edges going from variables in layer i to variables in layer j, and 0 otherwise.

            The best way to use this is to combine it with the manually-specified layering of your first solution.

            Source https://stackoverflow.com/questions/61662014

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install bnlearn

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/cran/bnlearn.git

          • CLI

            gh repo clone cran/bnlearn

          • sshUrl

            git@github.com:cran/bnlearn.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link