~ubuntu-branches/ubuntu/precise/weka/precise

« back to all changes in this revision

Viewing changes to weka/classifiers/bayes/net/search/fixed/NaiveBayes.java

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg
  • Date: 2008-02-24 09:18:45 UTC
  • Revision ID: james.westby@ubuntu.com-20080224091845-1l8zy6fm6xipbzsr
Tags: upstream-3.5.7+tut1
ImportĀ upstreamĀ versionĀ 3.5.7+tut1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This program is free software; you can redistribute it and/or modify
 
3
 * it under the terms of the GNU General Public License as published by
 
4
 * the Free Software Foundation; either version 2 of the License, or
 
5
 * (at your option) any later version.
 
6
 * 
 
7
 * This program is distributed in the hope that it will be useful,
 
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
 * 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 
 
41
        extends SearchAlgorithm {
 
42
 
 
43
        /** for serialization */
 
44
        static final long serialVersionUID = -4808572519709755811L;
 
45
            
 
46
        /**
 
47
         * Returns a string describing this object
 
48
         * @return a description of the classifier suitable for
 
49
         * displaying in the explorer/experimenter gui
 
50
         */
 
51
        public String globalInfo() {
 
52
          return 
 
53
              "The NaiveBayes class generates a fixed Bayes network structure "
 
54
            + "with arrows from the class variable to each of the attribute "
 
55
            + "variables.";
 
56
        }
 
57
        
 
58
        /**
 
59
         * 
 
60
         * @param bayesNet
 
61
         * @param instances the instances to work with
 
62
         * @throws Exception if something goes wrong
 
63
         */
 
64
        public void buildStructure (BayesNet bayesNet, Instances instances) throws Exception {
 
65
        for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
 
66
                if (iAttribute != instances.classIndex()) {
 
67
                        bayesNet.getParentSet(iAttribute).addParent(instances.classIndex(), instances);
 
68
                }
 
69
        }
 
70
        } // buildStructure
 
71
        
 
72
} // class NaiveBayes