|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - downloadIndex: ┃ T d ┃
Length: 4595 (0x11f3) Types: TextFile Names: »dprime.c«
└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki └─ ⟦this⟧ »EUUGD11/stat-5.3/eu/stat/src/dprime.c«
/* Copyright 1982 Gary Perlman */ #include "stat.h" PGM(dprime,Signal Detection Theory Analysis,5.2,10/14/86) Boole InfoVersion; /* print version information */ Boole InfoLimits; /* print program limits */ Boole InfoOptions; /* print usage information */ #define SQRT2PI 2.506628274631000502415765 #define normaldensity(z) (exp (-z*z * .5) / SQRT2PI) double critz (); #define MAXCOLS 2 #define MAXCHARS BUFSIZ /* maximum number of chars in lines */ char *Column[MAXCOLS]; int Presented, Obtained; int Hit, Miss, False_alarm, Correct_rejection; double Hit_rate, False_alarm_rate; double Dprime, Beta; #define table(fmt,v1,v2,v3,v4) printf ("%fmt %fmt %fmt %fmt\n",v1,v2,v3,v4) fparselin (ioptr, array, maxcols) FILE *ioptr; char **array; { static char line[MAXCHARS]; if (fgets (line, sizeof (line), ioptr)) return (parselin (line, array, maxcols)); else return (EOF); } main (argc, argv) char **argv; { int ncols; int optind; int nargs; ARGV0; optind = initial (argc, argv); nargs = argc - optind; if (nargs != 0 && nargs != 2) USAGE ([hit-rate false-alarm-rate]) if (nargs == 0) { checkstdin (); while ((ncols = fparselin (stdin, Column, MAXCOLS)) != EOF) { if (ncols == 0) continue; if (ncols != 2) ERRMSG0 (each line must have 2 columns) Presented = yesno (Column[0]); Obtained = yesno (Column[1]); if (Presented) { if (Obtained) Hit++; else Miss++; } else /* not presented */ { if (Obtained) False_alarm++; else Correct_rejection++; } } printf ("%15s%15s%15s\n", "", "signal", "noise"); printf ("%15s%15d%15d\n", "yes", Hit, False_alarm); printf ("%15s%15d%15d\n", "no", Miss, Correct_rejection); putchar ('\n'); Hit_rate = Hit ? Hit / (double) (Hit + Miss) : 0.0; False_alarm_rate = False_alarm ? False_alarm / (double) (False_alarm + Correct_rejection) : 0.0; } else /* hit rate and false alarm rate supplied */ { if (!number (argv[optind])) ERRNUM (argv[optind],hit-rate) if (!number (argv[optind+1])) ERRNUM (argv[optind+1],false-alarm-rate) Hit_rate = atof (argv[optind]); if (Hit_rate < 0.0 || Hit_rate > 1.0) ERRVAL (g,Hit_rate,hit rate) False_alarm_rate = atof (argv[optind+1]); if (False_alarm_rate < 0.0 || False_alarm_rate > 1.0) ERRVAL (g,False_alarm_rate,false-alarm rate) } Dprime = critz (Hit_rate) - critz (False_alarm_rate); Beta = normaldensity (critz (Hit_rate)) / normaldensity (critz (False_alarm_rate)); table (15s,"hr","far","dprime","beta"); table (15.2f,Hit_rate,False_alarm_rate,Dprime,Beta); exit (0); } yesno (string) char *string; { int val; if (isinteger (string)) { val = atoi (string); if (val == 1 || val == 0) return (val); } else /* check for upper/lower case strings */ { if (!strcmp (string, "yes")) return (1); if (!strcmp (string, "YES")) return (1); if (!strcmp (string, "no")) return (1); if (!strcmp (string, "NO")) return (1); if (!strcmp (string, "signal")) return (1); if (!strcmp (string, "SIGNAL")) return (1); if (!strcmp (string, "noise")) return (1); if (!strcmp (string, "NOISE")) return (1); } ERRMSG1 (illegal value (%s) in input, string) /*NOTREACHED*/ } /*FUNCTION initial: returns local version of optind, index to first operand */ int initial (argc, argv) char **argv; { extern char *optarg; /* option value accessed through this by getopt */ extern int optind; /* will be index to first operand */ int opterr = 0; /* count of number of errors */ int flag; /* option flag characters read in here */ char *optstring = /* getopt string to be filled in */ "LOV"; char *usage = /* part of usage summary to match optstring */ "[hit-rate false-alarm-rate]"; while ((flag = getopt (argc, argv, optstring)) != EOF) switch (flag) { default: opterr++; break; /* put option cases here */ case 'O': InfoOptions = TRUE; break; case 'V': InfoVersion = TRUE; break; case 'L': InfoLimits = TRUE; break; } if (opterr) /* print usage message and bail out */ { fprintf (stderr, "Usage: %s %s\n", argv[0], usage); exit (1); } usinfo (); return (optind); } usinfo () { if (InfoVersion) pver (Version); if (InfoLimits) { plim (Argv0); const (MAXCHARS, "maximum number of characters in lines"); } if (InfoOptions) { ppgm (Argv0, Purpose); } if (InfoVersion || InfoLimits || InfoOptions) exit (0); }