Changeset 67


Ignore:
Timestamp:
Jan 7, 2010, 9:01:57 AM (14 years ago)
Author:
(none)
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • proiecte/Parallel-DT/R8/Src/c4.5.c

    r26 r67  
    66/*************************************************************************/
    77
    8 
    98#include "defns.i"
    109#include "types.i"
    1110
     11#include <omp.h>
    1212
    13     /*  External data, described in extern.i  */
    1413
    15 short           MaxAtt, MaxClass, MaxDiscrVal = 2;
     14/*  External data, described in extern.i  */
    1615
    17 ItemNo          MaxItem;
     16short MaxAtt, MaxClass, MaxDiscrVal = 2;
    1817
    19 Description     *Item;
     18ItemNo MaxItem;
    2019
    21 DiscrValue      *MaxAttVal;
     20Description *Item;
    2221
    23 char            *SpecialStatus;
     22DiscrValue *MaxAttVal;
    2423
    25 String          *ClassName,
    26                 *AttName,
    27                 **AttValName,
    28                 FileName = "DF";
     24char *SpecialStatus;
    2925
    30 short           VERBOSITY = 0,
    31                 TRIALS    = 10;
     26String *ClassName, *AttName, **AttValName, FileName = "DF";
    3227
    33 Boolean         GAINRATIO  = true,
    34                 SUBSET     = false,
    35                 BATCH      = true,
    36                 UNSEENS    = false,
     28short VERBOSITY = 0, TRIALS = 10;
     29
     30Boolean GAINRATIO = true, SUBSET = false, BATCH = true, UNSEENS = false,
    3731                PROBTHRESH = false;
    3832
    39 ItemNo          MINOBJS   = 2,
    40                 WINDOW    = 0,
    41                 INCREMENT = 0;
     33ItemNo MINOBJS = 2, WINDOW = 0, INCREMENT = 0;
    4234
    43 float           CF = 0.25;
     35float CF = 0.25;
    4436
    45 Tree            *Pruned;
     37Tree *Pruned;
    4638
    47 Boolean         AllKnown = true;
     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");
    4851
    4952
    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);
    6056
    61     PrintHeader("decision tree generator");
    6257
    63     /*  Process options  */
     58           printf("nr threads = %d\n", omp_get_num_threads());
     59        /*  Process options  */
    6460
    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                }
    71135        }
    72136
    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();
    124155        }
    125     }
    126156
    127     /*  Initialise  */
     157        /*  Soften thresholds in best tree  */
    128158
    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        }
    135168
    136     /*  Build decision trees  */
     169        /*  Save best tree  */
    137170
    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");
    148177
    149     /*  Soften thresholds in best tree  */
     178        /*  Evaluation  */
    150179
    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);
    160182
    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        }
    162188
    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);
    186190}
Note: See TracChangeset for help on using the changeset viewer.