Learning mixtures
class pyagrum.bnmixture.BNMLearner(weights, source, template=None, states=None)
Section titled “class pyagrum.bnmixture.BNMLearner(weights, source, template=None, states=None)”Allows to learn mutiple BNs from a database. Learned BNs are given a weight and are stored in a BNMixture.
Notes
- How is memory handled? First, to reduce memory consumption, only one BNLearner is instancied at most at a given time. Their are more improvements if
sourcecontains files.
In that case, dataframes are loaded one at a time to reduce memory consumption. Otherwise all DataFrames are stored together.
- We create a reference learner using the source with maximum weight.
- Parameters:
- weights (List [**float ]) – Weights of each sample of the database.
- source (List [**str ] | List [**pandas.DataFrame ]) – Samples to learn from (csv format for now).
- states (List [ “state” ]) – List of learners state.
- template (pyagrum.BayesNet | Optional) – BN to use to find modalities.
- Raises: pyagrum.ArgumentError – If arguments don’t have the same dimensions.
add(source, weight, **kargs)
Section titled “add(source, weight, **kargs)”Adds a new BNLearner(its parameters) to the learner.
learnBNM()
Section titled “learnBNM()”Learns the BNs from the database and return them stored in a BNMixture with corresponding weights.
- Returns: The learned BNMixture.
- Return type: BNM.BNMixture
updateState(learner, **kargs)
Section titled “updateState(learner, **kargs)”Updates a learner using methods in parameters. If there are no parameters given, learner will copy state of the reference learner, if it exists.
- Parameters:
- learner (pyagrum.BNLearner) – Learner to update.
- algorithm (str) – Algorithm to use.
- order (List [**str or int ]) – Order for K2 algorithm.
- tabu_size (int) – size for local search with tabu list.
- nb_decrease (int) – decrease for local search with tabu list.
- score (str) – Type of score to use.
- correction (str) – Correction to use.
- prior (str) – Prior to use.
- source (str | pyagrum.BayesNet) – Source for dirichlet prior
- prior_weight (float) – Weight used for prior.
class pyagrum.bnmixture.BNMBootstrapLearner(source, template=None, N=100)
Section titled “class pyagrum.bnmixture.BNMBootstrapLearner(source, template=None, N=100)”Allows to learn a BN and bootsrap-generated BNs. Learning a BN is not the only goal of this class. The purpose of bootstraping is to have an accuracy indicator about the BN learned from a given database.
Notes
- How is memory handled? First, to reduce memory consumption, only one BNLearner is instancied at most at a given time.
- To keep one BNLearner at a time, we create a reference learner. To apply a method for the learning algorithm of all bootstraped BNs,
“use” methods modify the reference learner. Then the other learners make use of BNLearner.copyState to update themself according to the reference learner.
- Parameters:
- source (str | pandas.DataFrame) – Database to learn from (csv format for now).
- template (pyagrum.BayesNet | Optional) – BN to use to find modalities.
learnBNM()
Section titled “learnBNM()”Learns a reference BN from the database. Then add bootstrap-generated BNs to a BootstrapMixture object.
updateState(learner, **kargs)
Section titled “updateState(learner, **kargs)”Updates a learner using methods in parameters. If there are no parameters given, learner will copy state of the reference learner, if it exists.
- Parameters:
- learner (pyagrum.BNLearner) – Learner to update.
- algorithm (str) – Algorithm to use.
- order (List [**str or int ]) – Order for K2 algorithm.
- tabu_size (int) – size for local search with tabu list.
- nb_decrease (int) – decrease for local search with tabu list.
- score (str) – Type of score to use.
- correction (str) – Correction to use.
- prior (str) – Prior to use.
- source (str | pyagrum.BayesNet) – Source for dirichlet prior
- prior_weight (float) – Weight used for prior.
useBDeuPrior(weight=1.0)
Section titled “useBDeuPrior(weight=1.0)”useDirichletPrior(source, weight=1.0)
Section titled “useDirichletPrior(source, weight=1.0)”useGreedyHillClimbing()
Section titled “useGreedyHillClimbing()”useIter(N)
Section titled “useIter(N)”Set the number of bootstrap iterations used for learning.
- Parameters: N (int) – Number of iterations.