source: proiecte/Parallel-DT/R8/Src/c4.5.c @ 105

Last change on this file since 105 was 105, checked in by (none), 14 years ago
File size: 3.8 KB
Line 
1/*************************************************************************/
2/*                                                                       */
3/*      Main routine, c4.5                                               */
4/*      ------------------                                               */
5/*                                                                       */
6/*************************************************************************/
7
8#include "defns.i"
9#include "types.i"
10
11#include <omp.h>
12
13
14/*  External data, described in extern.i  */
15
16short MaxAtt, MaxClass, MaxDiscrVal = 2;
17
18ItemNo MaxItem;
19
20Description *Item;
21
22DiscrValue *MaxAttVal;
23
24char *SpecialStatus;
25
26String *ClassName, *AttName, **AttValName, FileName = "DF";
27
28short VERBOSITY = 0, TRIALS = 10;
29
30Boolean GAINRATIO = true, SUBSET = false, BATCH = true, UNSEENS = false,
31                PROBTHRESH = false;
32
33ItemNo MINOBJS = 2, WINDOW = 0, INCREMENT = 0;
34
35float CF = 0.25;
36
37Tree *Pruned;
38
39Boolean AllKnown = true;
40
41main(Argc, Argv)
42        /*  ----  */
43        int Argc;char *Argv[]; {
44        int o;
45        extern char *optarg;
46        extern int optind;
47        Boolean FirstTime = true;
48        short Best, BestTree();
49
50        PrintHeader("decision tree generator");
51
52        (void) omp_set_dynamic(0);
53        if (omp_get_dynamic()) {printf("Warning: dynamic adjustment of threads has been set\n");}
54        (void) omp_set_num_threads(2);
55
56        printf("nr threads = %d\n", omp_get_max_threads());
57        /*  Process options  */
58
59        while ((o = getopt(Argc, Argv, "f:bupv:t:w:i:gsm:c:")) != EOF) {
60                if (FirstTime) {
61                        printf("\n    Options:\n");
62                        FirstTime = false;
63                }
64
65                switch (o) {
66                case 'f':
67                        FileName = optarg;
68                        printf("\tFile stem <%s>\n", FileName);
69                        break;
70                case 'b':
71                        BATCH = true;
72                        printf("\tWindowing disabled (now the default)\n");
73                        break;
74                case 'u':
75                        UNSEENS = true;
76                        printf("\tTrees evaluated on unseen cases\n");
77                        break;
78                case 'p':
79                        PROBTHRESH = true;
80                        printf("\tProbability thresholds used\n");
81                        break;
82                case 'v':
83                        VERBOSITY = atoi(optarg);
84                        printf("\tVerbosity level %d\n", VERBOSITY);
85                        break;
86                case 't':
87                        TRIALS = atoi(optarg);
88                        printf("\tWindowing enabled with %d trials\n", TRIALS);
89                        Check(TRIALS, 1, 10000)
90                        ;
91                        BATCH = false;
92                        break;
93                case 'w':
94                        WINDOW = atoi(optarg);
95                        printf("\tInitial window size of %d items\n", WINDOW);
96                        Check(WINDOW, 1, 1000000)
97                        ;
98                        BATCH = false;
99                        break;
100                case 'i':
101                        INCREMENT = atoi(optarg);
102                        printf("\tMaximum window increment of %d items\n", INCREMENT);
103                        Check(INCREMENT, 1, 1000000)
104                        ;
105                        BATCH = false;
106                        break;
107                case 'g':
108                        GAINRATIO = false;
109                        printf("\tGain criterion used\n");
110                        break;
111                case 's':
112                        SUBSET = true;
113                        printf("\tTests on discrete attribute groups\n");
114                        break;
115                case 'm':
116                        MINOBJS = atoi(optarg);
117                        printf("\tSensible test requires 2 branches with >=%d cases\n",
118                                        MINOBJS);
119                        Check(MINOBJS, 1, 1000000)
120                        ;
121                        break;
122                case 'c':
123                        CF = atof(optarg);
124                        printf("\tPruning confidence level %g%%\n", CF);
125                        Check(CF, Epsilon, 100)
126                        ;
127                        CF /= 100;
128                        break;
129                case '?':
130                        printf("unrecognised option\n");
131                        exit(1);
132                }
133        }
134
135        /*  Initialise  */
136
137        GetNames();
138        //printf(">>>the force is with us\n");
139        GetData(".data");
140        //printf(">>>the force is with us222\n");
141        printf("\nRead %d cases (%d attributes) from %s.data\n", MaxItem + 1,
142                        MaxAtt + 1, FileName);
143
144        /*  Build decision trees  */
145
146        if (BATCH) {
147                TRIALS = 1;
148                OneTree_Discr();
149                //OneTree();
150                Best = 0;
151        } else {
152                Best = BestTree();
153        }
154
155        /*  Soften thresholds in best tree  */
156
157        if (PROBTHRESH) {
158                printf("Softening thresholds");
159                if (!BATCH)
160                        printf(" for best tree from trial %d", Best);
161                printf("\n");
162                SoftenThresh(Pruned[Best]);
163                printf("\n");
164                PrintTree(Pruned[Best]);
165        }
166
167        /*  Save best tree  */
168
169        if (BATCH || TRIALS == 1) {
170                printf("\nTree saved\n");
171        } else {
172                printf("\nBest tree from trial %d saved\n", Best);
173        }
174        SaveTree(Pruned[Best], ".tree");
175
176        /*  Evaluation  */
177
178        printf("\n\nEvaluation on training data (%d items):\n", MaxItem + 1);
179        Evaluate(false, Best);
180
181        if (UNSEENS) {
182                GetData(".test");
183                printf("\nEvaluation on test data (%d items):\n", MaxItem + 1);
184                Evaluate(true, Best);
185        }
186
187        exit(0);
188}
Note: See TracBrowser for help on using the repository browser.