1 | /*************************************************************************/ |
---|
2 | /* */ |
---|
3 | /* Type definitions for C4.5 */ |
---|
4 | /* ------------------------- */ |
---|
5 | /* */ |
---|
6 | /*************************************************************************/ |
---|
7 | |
---|
8 | |
---|
9 | typedef char Boolean, *String, *Set; |
---|
10 | |
---|
11 | typedef int ItemNo; /* data item number */ |
---|
12 | typedef float ItemCount; /* count of (partial) items */ |
---|
13 | |
---|
14 | typedef short ClassNo, /* class number, 0..MaxClass */ |
---|
15 | DiscrValue; /* discrete attribute value (0 = ?) */ |
---|
16 | typedef short Attribute; /* attribute number, 0..MaxAtt */ |
---|
17 | |
---|
18 | typedef union _attribute_value |
---|
19 | { |
---|
20 | DiscrValue _discr_val; |
---|
21 | float _cont_val; |
---|
22 | } |
---|
23 | AttValue, *Description; |
---|
24 | |
---|
25 | #define CVal(Case,Attribute) Case[Attribute]._cont_val |
---|
26 | #define DVal(Case,Attribute) Case[Attribute]._discr_val |
---|
27 | #define Class(Case) Case[MaxAtt+1]._discr_val |
---|
28 | |
---|
29 | #define Unknown -999 /* unknown value for continuous attribute */ |
---|
30 | |
---|
31 | |
---|
32 | #define BrDiscr 1 /* node types: branch */ |
---|
33 | #define ThreshContin 2 /* threshold cut */ |
---|
34 | #define BrSubset 3 /* subset test */ |
---|
35 | |
---|
36 | typedef struct _tree_record *Tree; |
---|
37 | typedef struct _tree_record |
---|
38 | { |
---|
39 | short NodeType; /* 0=leaf 1=branch 2=cut 3=subset */ |
---|
40 | ClassNo Leaf; /* most frequent class at this node */ |
---|
41 | ItemCount Items, /* no of items at this node */ |
---|
42 | *ClassDist, /* class distribution of items */ |
---|
43 | Errors; /* no of errors at this node */ |
---|
44 | Attribute Tested; /* attribute referenced in test */ |
---|
45 | short Forks; /* number of branches at this node */ |
---|
46 | float Cut, /* threshold for continuous attribute */ |
---|
47 | Lower, /* lower limit of soft threshold */ |
---|
48 | Upper; /* upper limit ditto */ |
---|
49 | Set *Subset; /* subsets of discrete values */ |
---|
50 | Tree *Branch; /* Branch[x] = (sub)tree for outcome x */ |
---|
51 | } |
---|
52 | TreeRec; |
---|
53 | |
---|
54 | #define IGNORE 1 /* special attribute status: do not use */ |
---|
55 | #define DISCRETE 2 /* ditto: collect values as data read */ |
---|
56 | |
---|
57 | |
---|
58 | typedef short RuleNo; /* rule number */ |
---|
59 | |
---|
60 | |
---|
61 | typedef struct TestRec *Test; |
---|
62 | |
---|
63 | struct TestRec |
---|
64 | { |
---|
65 | short NodeType; /* test type (see tree nodes) */ |
---|
66 | Attribute Tested; /* attribute tested */ |
---|
67 | short Forks; /* possible branches */ |
---|
68 | float Cut; /* threshold (if relevant) */ |
---|
69 | Set *Subset; /* subset (if relevant) */ |
---|
70 | }; |
---|
71 | |
---|
72 | |
---|
73 | typedef struct CondRec *Condition; |
---|
74 | |
---|
75 | struct CondRec |
---|
76 | { |
---|
77 | Test CondTest; /* test part of condition */ |
---|
78 | short TestValue; /* specified outcome of test */ |
---|
79 | }; |
---|
80 | |
---|
81 | |
---|
82 | typedef struct ProdRuleRec PR; |
---|
83 | |
---|
84 | struct ProdRuleRec |
---|
85 | { |
---|
86 | short Size; /* number of conditions */ |
---|
87 | Condition *Lhs; /* conditions themselves */ |
---|
88 | ClassNo Rhs; /* class given by rule */ |
---|
89 | float Error, /* estimated error rate */ |
---|
90 | Bits; /* bits to encode rule */ |
---|
91 | ItemNo Used, /* times rule used */ |
---|
92 | Incorrect; /* times rule incorrect */ |
---|
93 | }; |
---|
94 | |
---|
95 | |
---|
96 | typedef struct RuleSetRec RuleSet; |
---|
97 | |
---|
98 | struct RuleSetRec |
---|
99 | { |
---|
100 | PR *SRule; /* rules */ |
---|
101 | RuleNo SNRules, /* number of rules */ |
---|
102 | *SRuleIndex; /* ranking of rules */ |
---|
103 | ClassNo SDefaultClass; /* default class for this ruleset */ |
---|
104 | }; |
---|