DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T d

⟦457eab815⟧ TextFile

    Length: 2745 (0xab9)
    Types: TextFile
    Names: »dprime.c«

Derivation

└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen
    └─ ⟦this⟧ »cph85dist/stat/src/dprime.c« 

TextFile

#include "unixstat.h"
PGM(dprime,Signal Detection Theory Analysis,5.0,1985)
/* Copyright (c) 1982 Gary Perlman (see Copyright file) */

#define	MAXCOLS	2
char	*column[MAXCOLS];
int 	presented, obtained;
int 	hit, miss, false_alarm, correct_rejection;
double	hr, far;
double	dprime, beta;

#define	table(fmt,v1,v2,v3,v4) printf ("%fmt %fmt %fmt %fmt\n",v1,v2,v3,v4)

fparseline (ioptr, array, maxcols)
FILE	*ioptr;
char	**array;
	{
	static	char	line[BUFSIZ];
	if (fgets (line, BUFSIZ, ioptr))
		return (parseline (line, array, maxcols));
	else return (EOF);
	}

main (argc, argv) char **argv;
	{
	double	ptoz (), normaldensity ();
	int 	ncols;
	ARGV0;
	if (argc != 1 && argc != 3)
		USAGE ([hit-rate false-alarm-rate])
	if (argc == 1)
		{
		checkstdin (Argv0);
		while ((ncols = fparseline (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');
			hr = hit ? hit / (double) (hit + miss) : 0.0;
			far = false_alarm
				? false_alarm / (double) (false_alarm + correct_rejection)
				: 0.0;
		}
	else /* hit rate and false alarm rate supplied */
		{
			if (!number (argv[1])) ERRNUM (argv[1],hit-rate)
			if (!number (argv[2])) ERRNUM (argv[2],false-alarm-rate)
			hr = atof (argv[1]);
			if (hr < 0.0 || hr > 1.0)
				ERRVAL (g,hr,hit rate)
			far = atof (argv[2]);
			if (far < 0.0 || far > 1.0)
				ERRVAL (g,far,false-alarm rate)
		}
	dprime = ptoz (hr) - ptoz (far);
	beta   = normaldensity (ptoz (hr)) / normaldensity (ptoz (far));
	table (15s,"hr","far","dprime","beta");
	table (15.2f,hr,far,dprime,beta);
	exit (0);
	}

char	*yesses[] = {"yes", "1", "1.0000", "signal", ""};
char	*noes[]   = {"no",  "0", "0.0000", "noise",  ""};
yesno (string) char *string;
	{
	int 	strno;
	for (strno = 0; *yesses[strno] && strcmp (string, yesses[strno]); strno++);
	if (*yesses[strno]) return (1);
	for (strno = 0; *noes[strno] && strcmp (string, noes[strno]); strno++);
	if (*noes[strno]) return (0);
	ERRMSG1 (illegal value (%s) in input, string)
	/*NOTREACHED*/
	}

double	Pi;        /* 3.15159 and all that */
double	Denom;     /* used by normal density function */

double normaldensity (z) double z;
	{
	double exp ();
	return (exp (-z*z / 2.0) / Denom);
	}

initial ()
	{
	double	sqrt ();
	Pi = acos (-1.0);
	Denom = sqrt (2.0 * Pi);
	}