next up previous contents
Next: Adding a new estimator Up: Adding your own Bayesian Previous: Adding your own Bayesian   Contents

Adding a new structure learner

Here is the quick guide for adding a structure learner:

  1. Create a class that derives from weka.classifiers.bayes.net.search.SearchAlgorithm. If your searcher is score based, conditional independence based or cross-validation based, you probably want to derive from ScoreSearchAlgorithm, CISearchAlgorithm or CVSearchAlgorithm instead of deriving from SearchAlgorithm directly. Let's say it is called
    weka.classifiers.bayes.net.search.local.MySearcher derived from ScoreSearchAlgorithm.

  2. Implement the method
    public void buildStructure(BayesNet bayesNet, Instances instances). Essentially, you are responsible for setting the parent sets in bayesNet. You can access the parentsets using bayesNet.getParentSet(iAttribute) where iAttribute is the number of the node/variable.

    To add a parent iParent to node iAttribute, use
    bayesNet.getParentSet(iAttribute).AddParent(iParent, instances) where instances need to be passed for the parent set to derive properties of the attribute.

    Alternatively, implement public void search(BayesNet bayesNet, Instances instances). The implementation of buildStructure in the base class. This method is called by the SearchAlgorithm will call search after initializing parent sets and if the initAsNaiveBase flag is set, it will start with a naive Bayes network structure. After calling search in your custom class, it will add arrows if the markovBlanketClassifier flag is set to ensure all attributes are in the Markov blanket of the class node.

  3. If the structure learner has options that are not default options, you want to implement public Enumeration listOptions(), public void setOptions(String[] options), public String[] getOptions() and the get and set methods for the properties you want to be able to set.

    NB 1. do not use the -E option since that is reserved for the BayesNet class to distinguish the extra options for the SearchAlgorithm class and the Estimator class. If the -E option is used, it will not be passed to your SearchAlgorithm (and probably causes problems in the BayesNet class).

    NB 2. make sure to process options of the parent class if any in the get/setOpions methods.


next up previous contents
Next: Adding a new estimator Up: Adding your own Bayesian Previous: Adding your own Bayesian   Contents
Remco Bouckaert 2008-05-12