BNLearner.useDirichletPrior

BNLearner.useDirichletPrior(source, weight=None)

Use the Dirichlet prior.

Parameters:
  • source (str|pyagrum.BayesNet) – the Dirichlet related source (filename of a database or a Bayesian network). The variables of a Bayesian network are found by their names: each column of the database must be one of them, with the same labels in the same order.

  • weight (float, optional) – the weight of the prior (the ‘size’ of the corresponding ‘virtual database’), which must not be negative. By default, it is pyagrum.config['learning', 'priorWeight'] (1.0).

Returns:

the BNLearner itself, so that we can chain useXXX() methods.

Return type:

pyagrum.BNLearner

Raises:

Example

import pyagrum as gum

with open("data.csv", "w") as f:  # C is mostly "A or B"
  f.write("A,B,C\n" + "0,0,0\n0,1,1\n1,0,1\n1,1,1\n" * 40 + "0,0,1\n0,1,0\n1,0,0\n1,1,0\n" * 5)
learner = gum.BNLearner("data.csv")
prior = gum.fastBN("A->C<-B")
learner.useDirichletPrior(prior, 10.0)  # a virtual database of 10 rows
learner.state()["Prior"][0]
# 'Dirichlet'

Class

BNLearner