testclassif.c File Reference

Test classification algorithm. More...

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <libgen.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <classif.h>
Include dependency graph for testclassif.c:

Go to the source code of this file.

Defines

#define _GNU_SOURCE
 GNU extensions.

Functions

void show_usage (char *pgm)
 C prototypes.
int main (int argc, char **argv)
 Main program.

Detailed Description

Test classification algorithm.

Definition in file testclassif.c.


Define Documentation

#define _GNU_SOURCE

GNU extensions.

Definition at line 59 of file testclassif.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Main program.

Parameters:
[in] argc Number of command-line arguments.
[in] argv Vector of command-line argument strings.
Returns:
Status.

Definition at line 102 of file testclassif.c.

References alloc_error(), banner(), generate_clusters(), and show_usage().

00103 {
00111   int i;
00112   int j;
00113   int neof;
00114   int ndays;
00115   int nclusters;
00116   int nclassif;
00117 
00118   double *pc_eof_days = NULL;
00119   double *clusters = NULL;
00120 
00121   const gsl_rng_type *T;
00122   gsl_rng *rng;
00123 
00124   /* Print BEGIN banner */
00125   (void) banner(basename(argv[0]), "1.0", "BEGIN");
00126 
00127   /* Get command-line arguments and set appropriate variables */
00128   for (i=1; i<argc; i++) {
00129     if ( !strcmp(argv[i], "-h") ) {
00130       (void) show_usage(basename(argv[0]));
00131       (void) banner(basename(argv[0]), "OK", "END");
00132       return 0;
00133     }
00134     else {
00135       (void) fprintf(stderr, "%s:: Wrong arg %s.\n\n", basename(argv[0]), argv[i]);
00136       (void) show_usage(basename(argv[0]));
00137       (void) banner(basename(argv[0]), "ABORT", "END");
00138       (void) abort();
00139     }
00140   }
00141 
00142   /* Use simulated 10 EOFs */
00143   neof = 10;
00144   /* Use simulated 15000 days */
00145   ndays = 15000;
00146   /* Try 1000 classifications */
00147   nclassif = 1000;
00148   /* Use 8 clusters */
00149   nclusters = 8;
00150 
00151   /* Initialize random number generator */
00152   T = gsl_rng_default;
00153   rng = gsl_rng_alloc(T);
00154   (void) gsl_rng_set(rng, time(NULL));
00155 
00156   /* Allocate memory */
00157   pc_eof_days = (double *) calloc(neof*ndays, sizeof(double));
00158   if (pc_eof_days == NULL) alloc_error(__FILE__, __LINE__);
00159   clusters = (double *) calloc(neof*nclusters, sizeof(double));
00160   if (clusters == NULL) alloc_error(__FILE__, __LINE__);
00161   
00162   /* Generate a double between 0.0 and 1.0 */
00163   for (i=0; i<neof; i++) {
00164     for (j=0; j<ndays/2; j++) {
00165       pc_eof_days[i+j*neof] = fabs(gsl_ran_gaussian(rng, 1.0) / 2.0);
00166 #ifdef DEBUG
00167       /*      (void) fprintf(stderr, "eof %d day %d pc_eof_days %lf\n", i, j, pc_eof_days[i+j*neof]);*/
00168 #endif
00169     }
00170     for (j=ndays/2; j<ndays; j++) {
00171       pc_eof_days[i+j*neof] = fabs((gsl_ran_gaussian(rng, 1.0) / 2.0))+ 0.5;
00172 #ifdef DEBUG
00173       /*      (void) fprintf(stderr, "eof %d day %d pc_eof_days %lf\n", i, j, pc_eof_days[i+j*neof]);*/
00174 #endif
00175     }
00176   }
00177 
00178   (void) gsl_rng_free(rng);
00179 
00180   /* Find clusters: test classification algorithm */
00181   (void) generate_clusters(clusters, pc_eof_days, "euclidian", nclassif, neof, nclusters, ndays);
00182 
00183   /* Output data */
00184   for (i=0; i<neof; i++)
00185     for (j=0; j<nclusters; j++)
00186       (void) fprintf(stdout, "%d %d %lf\n", i, j, clusters[i+j*neof]);
00187 
00188   /* Free memory */
00189   (void) free(pc_eof_days);
00190   (void) free(clusters);
00191 
00192   /* Print END banner */
00193   (void) banner(basename(argv[0]), "OK", "END");
00194 
00195   return 0;
00196 }

void show_usage ( char *  pgm  ) 

C prototypes.

Local Subroutines.

Show usage for program command-line arguments.

Parameters:
[in] pgm Program name.

Definition at line 202 of file testclassif.c.

00202                            {
00207   (void) fprintf(stderr, "%s: usage:\n", pgm);
00208   (void) fprintf(stderr, "-h: help\n");
00209 
00210 }


Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1