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 | * Rule.java |
---|
19 | * Copyright (C) 2001 University of Waikato, Hamilton, New Zealand |
---|
20 | */ |
---|
21 | |
---|
22 | package weka.classifiers.rules; |
---|
23 | |
---|
24 | import weka.core.Copyable; |
---|
25 | import weka.core.Instance; |
---|
26 | import weka.core.Instances; |
---|
27 | import weka.core.RevisionHandler; |
---|
28 | import weka.core.WeightedInstancesHandler; |
---|
29 | |
---|
30 | import java.io.Serializable; |
---|
31 | |
---|
32 | /** |
---|
33 | * Abstract class of generic rule |
---|
34 | * |
---|
35 | * @author Xin Xu (xx5@cs.waikato.ac.nz) |
---|
36 | * @version $Revision: 1.8 $ |
---|
37 | */ |
---|
38 | public abstract class Rule |
---|
39 | implements WeightedInstancesHandler, Copyable, Serializable, RevisionHandler { |
---|
40 | |
---|
41 | /** for serialization */ |
---|
42 | private static final long serialVersionUID = 8815687740470471229L; |
---|
43 | |
---|
44 | /** |
---|
45 | * Get a shallow copy of this rule |
---|
46 | * |
---|
47 | * @return the copy |
---|
48 | */ |
---|
49 | public Object copy(){ return this;} |
---|
50 | |
---|
51 | /** |
---|
52 | * Whether the instance covered by this rule |
---|
53 | * |
---|
54 | * @param datum the instance in question |
---|
55 | * @return the boolean value indicating whether the instance |
---|
56 | * is covered by this rule |
---|
57 | */ |
---|
58 | public abstract boolean covers(Instance datum); |
---|
59 | |
---|
60 | /** |
---|
61 | * Build this rule |
---|
62 | * |
---|
63 | * @param data the data used to build the rule |
---|
64 | * @exception Exception if rule cannot be built |
---|
65 | */ |
---|
66 | public abstract void grow(Instances data) throws Exception; |
---|
67 | |
---|
68 | /** |
---|
69 | * Whether this rule has antecedents, i.e. whether it is a default rule |
---|
70 | * |
---|
71 | * @return the boolean value indicating whether the rule has antecedents |
---|
72 | */ |
---|
73 | public abstract boolean hasAntds(); |
---|
74 | |
---|
75 | /** |
---|
76 | * Get the consequent of this rule, i.e. the predicted class |
---|
77 | * |
---|
78 | * @return the consequent |
---|
79 | */ |
---|
80 | public abstract double getConsequent(); |
---|
81 | |
---|
82 | /** |
---|
83 | * The size of the rule. Could be number of antecedents in the case |
---|
84 | * of conjunctive rule |
---|
85 | * |
---|
86 | * @return the size of the rule |
---|
87 | */ |
---|
88 | public abstract double size(); |
---|
89 | } |
---|