01: /*
02: * This program is free software; you can redistribute it and/or modify
03: * it under the terms of the GNU General Public License as published by
04: * the Free Software Foundation; either version 2 of the License, or
05: * (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: * GNU General Public License for more details.
11: *
12: * You should have received a copy of the GNU General Public License
13: * along with this program; if not, write to the Free Software
14: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15: */
16:
17: /*
18: * NaiveBayes.java
19: * Copyright (C) 2004 University of Waikato, Hamilton, New Zealand
20: *
21: */
22: package weka.classifiers.bayes.net.search.fixed;
23:
24: import weka.classifiers.bayes.BayesNet;
25: import weka.classifiers.bayes.net.search.SearchAlgorithm;
26: import weka.core.Instances;
27:
28: /**
29: <!-- globalinfo-start -->
30: * The NaiveBayes class generates a fixed Bayes network structure with arrows from the class variable to each of the attribute variables.
31: * <p/>
32: <!-- globalinfo-end -->
33: *
34: <!-- options-start -->
35: <!-- options-end -->
36: *
37: * @author Remco Bouckaert
38: * @version $Revision: 1.5 $
39: */
40: public class NaiveBayes extends SearchAlgorithm {
41:
42: /** for serialization */
43: static final long serialVersionUID = -4808572519709755811L;
44:
45: /**
46: * Returns a string describing this object
47: * @return a description of the classifier suitable for
48: * displaying in the explorer/experimenter gui
49: */
50: public String globalInfo() {
51: return "The NaiveBayes class generates a fixed Bayes network structure "
52: + "with arrows from the class variable to each of the attribute "
53: + "variables.";
54: }
55:
56: /**
57: *
58: * @param bayesNet
59: * @param instances the instances to work with
60: * @throws Exception if something goes wrong
61: */
62: public void buildStructure(BayesNet bayesNet, Instances instances)
63: throws Exception {
64: for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
65: if (iAttribute != instances.classIndex()) {
66: bayesNet.getParentSet(iAttribute).addParent(
67: instances.classIndex(), instances);
68: }
69: }
70: } // buildStructure
71:
72: } // class NaiveBayes
|