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