#include #include #include #include #include #include #include #define MAX_ENTRIES 10000 typedef struct { char *name; char *val; } entry; char *makeword(char *line, char stop); char *fmakeword(FILE *f, char stop, int *len); char x2c(char *what); void unescape_url(char *url); void plustospace(char *str); /**************************************************** * Simulation of Search of Associative Memory (SAM) * **************************************************** * * August 1992 * * Peter Nobel * Indiana University * Bloomington, IN 47405 * * pnobel@ucs.indiana.edu * * This program simulates the following test-conditions: * single item recognition * associative recognition: intact - rearranged * associative recognition: intact - mixed * associative recognition: intact - new * cued recall * * April 1995 * * Simon Dennis * University of Queensland * Queensland, Australia, 4072. * * mav@psy.uq.oz.au * * Added a html form interface */ #define RAND_MAX 2147483648.0 /* the maximum number returned by rand */ #define NSIM 100 /* maximum number of simulations */ #define NMAX 32 /* maximum number of pairs on a list */ #define SMAXS 5 /* maximum strength strong items */ #define SMAXW 3 /* maximum strength weak items */ #define TRUE 1 #define integer int /* used in d-prime function */ #define real float static integer c__9 = 9; static integer c__1 = 1; static integer c__4 = 4; FILE *fp; /* file pointer to output file */ char fout[100]; /* output file name */ /*********************** * function prototypes * ***********************/ void making_matrix(void); void recognition_single(void); void recognition_ass_rearr(void); void recognition_ass_mixed(void); void recognition_ass_new(void); void cued_recall(void); void ranset(void); void perm(int *, int); void simulate(void); void results(void); void display(char **, int, int); void settings(void); void screen(void); void move(int, int); void action1(int); void action2(int); void action3(int); void action4(int); void action5(int); void action6(int); void action7(int); float rand1(void); float gau(double, double); int randw(int); int getcode(void); /*************************************** * global variables for the simulation * ***************************************/ int nsim=20; /* number of simulations */ int cond=1; /* type of test */ int n=8; /* the length of the list (# of pairs): multiples of 8 */ int strength=1; /*strength of the list: 1-pure weak, 2-pure strong, 3-mixed */ int s1=1; /* strength of weak items */ int s2=2; /* strength of strong items */ /********************************** * global variables for the model * **********************************/ int m[2*NMAX+1][2*NMAX]; /* matrix for markers of items sampled in recall */ float v[4*NMAX+1][2*NMAX]; /* matrix for retrieval strengths */ int count, /* counter for the number of simulations */ count_cw, /* counter for weak corrects in cued recall */ count_cs, /* counter for strong corrects in cued recall */ count_hw, /* counter for weak hits in recognition */ count_hs, /* counter for strong hits in recognition */ count_f, /* counter for false alarms in recognition */ count_fs; /* counter for strong false alarms (ass) */ float famtw, /* total sum familiarity: weak targets */ famtw2, /* total sum familiarity squared: weak targets */ famts, /* total sum familiarity: strong targets */ famts2, /* total sum familiarity squared: strong targets */ famd, /* total sum familiarity: distractors */ famd2, /* total sum familiarity squared: distractors */ famds, /* total sum familiarity: strong distractors */ famds2; /* total sum familiarity squared: strong distractors */ float VARTW[NSIM], /* array for variance familiarity: weak targets */ VARTS[NSIM], /* array for variance familiarity: strong targets */ VARD[NSIM], /* array for variance familiarity: distractors */ VARDS[NSIM], /* array for variance familiarity: distractors */ DPRPW[NSIM], /* array for d-prime (weak) based on proportions */ DPRPS[NSIM], /* array for d-prime (strong) based on proportions */ DPRDW[NSIM], /* array for d-prime (weak) based on distributions */ DPRDS[NSIM]; /* array for d-prime (strong) based on distributions */ /**************************** * parameters for the model * ****************************/ float a=0.5, /* mean context strength */ b=0.5, /* mean inter-item strength */ c=0.5, /* mean self strength */ d=0.075; /* mean residual strength */ float alpha=0.2; /* multiplier for variance of strength parameters */ float w1=0.5, /* retrieval weight item 1 */ w2=0.0, /* retrieval weight item 2 */ w3=0.5; /* retrieval weight context */ float crit=3.3; /* criterion in recognition */ int kmax=10; /* maximum number of searches in recall */ float recov=3.0; /* multiplier for recovery probability */ int diff=0; /* differentiation: 0 = no, 1 = yes */ /************************ * variables for output * ************************/ /* cued recall */ float pcw; /* final result recall: weak items */ float pcs; /* final result recall: strong items */ /* recognition: variance and d' for both averaged and total */ float hw; /* final result recognition: weak hits */ float mtw; /* mean familiarity weak targets */ float vartw; /* variance familiarity weak targets (avg.) */ float tvartw; /* variance familiarity weak targets (total) */ float hs; /* final result recognition: strong hits */ float mts; /* mean familiarity strong targets */ float varts; /* variance familiarity strong targets (avg.) */ float tvarts; /* variance familiarity strong targets (total) */ float f; /* final result recognition: false alarms */ float fs; /* final result recognition: strong false alarms */ float md; /* mean familiarity distractors */ float mds; /* mean familiarity strong distractors */ float vard; /* variance familiarity distractors (avg.) */ float vards; /* variance familiarity strong distractors (avg.) */ float tvard; /* variance familiarity distractors (total) */ float tvards; /* variance familiarity strong distractors (total) */ float dprpw; /* dprime based on proportions: weak items (avg.) */ float tdprpw; /* dprime based on proportions: weak items (total) */ float dprps; /* dprime based on proportions: strong items (avg.) */ float tdprps; /* dprime based on proportions: strong items (total) */ float dprdw; /* dprime based on distributions: weak items (avg.) */ float tdprdw; /* dprime based on distributions: weak items (total) */ float dprds; /* dprime based on distributions: strong items (avg.) */ float tdprds; /* dprime based on distributions: strong items (total) */ /********************* * FUNCTION SIMULATE * ********************* * * simulation routine * */ void simulate(void) { int i, j, p; count_cw = 0; /* initialize the counters */ count_cs = 0; count_hw = 0; count_hs = 0; count_f = 0; count_fs = 0; count = 0; famtw = 0.0; famtw2 = 0.0; famts = 0.0; famts2 = 0.0; famd = 0.0; famd2 = 0.0; famds = 0.0; famds2 = 0.0; /* initialize the storage arrays */ for (i=0; i n)) { famts += fam; famts2 += fam * fam; fts += fam; fts2 += fam * fam; } if (fam > crit) { if ((strength == 1) || (strength == 3 && i <= n)) { count_hw++; chw++; } if ((strength == 2) || (strength == 3 && i > n)) { count_hs++; chs++; } } } for (i=2*n+1; i<=3*n; i++) { /* distractors */ fam = 0.0; sc = 0.0; si = 0.0; for (j=1; j<=2*n; j++) { sc = (float)pow((double)v[0][j],(double)w3); si = (float)pow((double)v[i][j],(double)w1); fam += sc * si; } famd += fam; famd2 += fam * fam; fd += fam; fd2 += fam * fam; if (fam > crit) { count_f++; cf++; } } /* compute results and store in arrays */ if (strength == 3) t = (float)n/2; else t = (float)n; vtw = ((t*ftw2)-(ftw*ftw))/(t*(t-1)); if (vtw < 0.0001) vtw = 0.0001; VARTW[count] = vtw; vts = ((t*fts2)-(fts*fts))/(t*(t-1)); if (vts < 0.0001) vts = 0.0001; VARTS[count] = vts; vdw = (((float)n * fd2)-(fd*fd))/((float)n*(float)n-1); if (vdw < 0.0001) vdw = 0.0001; VARD[count] = vdw; hrate = (float)chw/t; farate = (float)cf/(float)n; dprime_(&hrate, &farate, &dp); DPRPW[count] = dp; hrate = (float)chs/t; farate = (float)cf/(float)n; dprime_(&hrate, &farate, &dp); DPRPS[count] = dp; DPRDW[count] = ((ftw/t)-(fd/(float)n))/(sqrt(VARD[count])); DPRDS[count] = ((fts/t)-(fd/(float)n))/(sqrt(VARD[count])); count++; } /********************************** * FUNCTION RECOGNITION_ASS_REARR * ********************************** * * associative recognition simulation routine * targets : A-B (intact) * distractors: A-D (rearranged) * */ void recognition_ass_rearr(void) { static real hrate, farate, dp; extern int dprime_(); int i, j; float t; float sc, si1, si2; /* weighted cue strengths */ float fam; /* familiarity of test-item */ int chw = 0, chs = 0, cf = 0, cfs = 0; float ftw = 0.0, /* variables to compute means and variances */ ftw2 = 0.0, /* for the target and distractor distibutions */ fts = 0.0, fts2 = 0.0, fd = 0.0, fd2 = 0.0, fds = 0.0, fds2 = 0.0, vtw = 0.0, vts = 0.0, vdw = 0.0, vds = 0.0; for (i=1; i crit) { if (strength == 2) { count_hs++; chs++; } else { count_hw++; chw++; } } } for (i=(n/2)+1; i<=(n/2)+(n/4); i++) { /* distractors 1 */ fam = 0.0; sc = 0.0; si1 = 0.0; si2 = 0.0; for (j=1; j<=2*n; j++) { sc = (float)pow((double)v[0][j],(double)w3); si1 = (float)pow((double)v[i][j],(double)w1); si2 = (float)pow((double)v[i+n/4][j],(double)w2); fam += sc * si1 * si2; } famd += fam; famd2 += fam * fam; fd += fam; fd2 += fam * fam; if (fam > crit) { count_f++; cf++; } } for (i=n+1; i crit) { if (strength == 1) { count_hw++; chw++; } else { count_hs++; chs++; } } } for (i=n+(n/2)+1; i<=(2*n)-(n/4); i++) { /* distractors 2 */ fam = 0.0; sc = 0.0; si1 = 0.0; si2 = 0.0; for (j=1; j<=2*n; j++) { sc = (float)pow((double)v[0][j],(double)w3); si1 = (float)pow((double)v[i][j],(double)w1); si2 = (float)pow((double)v[i+n/4][j],(double)w2); fam += sc * si1 * si2; } if (strength == 3) { famds += fam; famds2 += fam * fam; fds += fam; fds2 += fam * fam; } else { famd += fam; famd2 += fam * fam; fd += fam; fd2 += fam * fam; } if (fam > crit) { if (strength == 3) { count_fs++; cfs++; } else { count_f++; cf++; } } } /* compute results and store in arrays */ if (strength == 3) t = (float)n/4; else t = (float)n/2; vtw = ((t*ftw2)-(ftw*ftw))/(t*(t-1)); if (vtw < 0.0001) vtw = 0.0001; VARTW[count] = vtw; vts = ((t*fts2)-(fts*fts))/(t*(t-1)); if (vts < 0.0001) vts = 0.0001; VARTS[count] = vts; vdw = ((t*fd2)-(fd*fd))/(t*(t-1)); if (vdw < 0.0001) vdw = 0.0001; VARD[count] = vdw; if (strength == 3) { vds = ((t*fds2)-(fds*fds))/(t*(t-1)); if (vds < 0.0001) vds = 0.0001; VARDS[count] = vds; } hrate = (float)chw/t; farate = (float)cf/t; dprime_(&hrate, &farate, &dp); DPRPW[count] = dp; hrate = (float)chs/t; if (strength == 3 ) farate = (float)cfs/t; else farate = (float)cf/t; dprime_(&hrate, &farate, &dp); DPRPS[count] = dp; DPRDW[count] = ((ftw/t)-(fd/t))/(sqrt(VARD[count])); if (strength == 3 ) DPRDS[count] = ((fts/t)-(fds/t))/(sqrt(VARDS[count])); else DPRDS[count] = ((fts/t)-(fd/t))/(sqrt(VARD[count])); count++; } /********************************** * FUNCTION RECOGNITION_ASS_MIXED * ********************************** * * associative recognition simulation routine * targets : A-B (intact) * distractors: A-X (mixed) * */ void recognition_ass_mixed(void) { static real hrate, farate, dp; extern int dprime_(); int i, j; float t; float sc, si1, si2; /* weighted cue strengths */ float fam; /* familiarity of test-item */ int chw = 0, chs = 0, cf = 0, cfs = 0; float ftw = 0.0, /* variables to compute means and variances */ ftw2 = 0.0, /* for the target and distractor distibutions */ fts = 0.0, fts2 = 0.0, fd = 0.0, fd2 = 0.0, fds = 0.0, fds2 = 0.0, vtw = 0.0, vts = 0.0, vdw = 0.0, vds = 0.0; for (i=1; i crit) { if (strength == 2) { count_hs++; chs++; } else { count_hw++; chw++; } } } for (i=(n/2)+1; i crit) { count_f++; cf++; } } for (i=n+1; i crit) { if (strength == 1) { count_hw++; chw++; } else { count_hs++; chs++; } } } for (i=n+(n/2)+1; i<2*n; i+=2) { /* distractors 2 */ fam = 0.0; sc = 0.0; si1 = 0.0; si2 = 0.0; for (j=1; j<=2*n; j++) { sc = (float)pow((double)v[0][j],(double)w3); si1 = (float)pow((double)v[i][j],(double)w1); si2 = (float)pow((double)v[i+(2*n)][j],(double)w2); fam += sc * si1 * si2; } if (strength == 3) { famds += fam; famds2 += fam * fam; fds += fam; fds2 += fam * fam; } else { famd += fam; famd2 += fam * fam; fd += fam; fd2 += fam * fam; } if (fam > crit) { if (strength == 3) { count_fs++; cfs++; } else { count_f++; cf++; } } } /* compute results and store in arrays */ if (strength == 3) t = (float)n/4; else t = (float)n/2; vtw = ((t*ftw2)-(ftw*ftw))/(t*(t-1)); if (vtw < 0.0001) vtw = 0.0001; VARTW[count] = vtw; vts = ((t*fts2)-(fts*fts))/(t*(t-1)); if (vts < 0.0001) vts = 0.0001; VARTS[count] = vts; vdw = ((t*fd2)-(fd*fd))/(t*(t-1)); if (vdw < 0.0001) vdw = 0.0001; VARD[count] = vdw; if (strength == 3) { vds = ((t*fds2)-(fds*fds))/(t*(t-1)); if (vds < 0.0001) vds = 0.0001; VARDS[count] = vds; } hrate = (float)chw/t; farate = (float)cf/t; dprime_(&hrate, &farate, &dp); DPRPW[count] = dp; hrate = (float)chs/t; if (strength == 3 ) farate = (float)cfs/t; else farate = (float)cf/t; dprime_(&hrate, &farate, &dp); DPRPS[count] = dp; DPRDW[count] = ((ftw/t)-(fd/t))/(sqrt(VARD[count])); if (strength == 3 ) DPRDS[count] = ((fts/t)-(fds/t))/(sqrt(VARDS[count])); else DPRDS[count] = ((fts/t)-(fd/t))/(sqrt(VARD[count])); count++; } /******************************** * FUNCTION RECOGNITION_ASS_NEW * ******************************** * * associative recognition simulation routine * targets : A-B * distractors: X-Y * */ void recognition_ass_new(void) { static real hrate, farate, dp; extern int dprime_(); int i, j; float t; float sc, si1, si2; /* weighted cue strengths */ float fam; /* familiarity of test-item */ int chw = 0, chs = 0, cf = 0; float ftw = 0.0, /* variables to compute means and variances */ ftw2 = 0.0, /* for the target and distractor distibutions */ fts = 0.0, fts2 = 0.0, fd = 0.0, fd2 = 0.0, vtw = 0.0, vts = 0.0, vdw = 0.0; for (i=1; i<2*n; i+=2) { /* targets */ fam = 0.0; sc = 0.0; si1 = 0.0; si2 = 0.0; for (j=1; j<=2*n; j++) { sc = (float)pow((double)v[0][j],(double)w3); si1 = (float)pow((double)v[i][j],(double)w1); si2 = (float)pow((double)v[i+1][j],(double)w2); fam += sc * si1 * si2; } if ((strength == 1) || (strength == 3 && i <= n)) { famtw += fam; famtw2 += fam * fam; ftw += fam; ftw2 += fam * fam; } if ((strength == 2) || (strength == 3 && i > n)) { famts += fam; famts2 += fam * fam; fts += fam; fts2 += fam * fam; } if (fam > crit) { if ((strength == 1) || (strength == 3 && i <= n)) { count_hw++; chw++; } if ((strength == 2) || (strength == 3 && i > n)) { count_hs++; chs++; } } } for (i=2*n+1; i<4*n; i+=2) { /* distractors */ fam = 0.0; sc = 0.0; si1 = 0.0; si2 = 0.0; for (j=1; j<=2*n; j++) { sc = (float)pow((double)v[0][j],(double)w3); si1 = (float)pow((double)v[i][j],(double)w1); si2 = (float)pow((double)v[i+1][j],(double)w2); fam += sc * si1 * si2; } famd += fam; famd2 += fam * fam; fd += fam; fd2 += fam * fam; if (fam > crit) { count_f++; cf++; } } /* compute results and store in arrays */ if (strength == 3) t = (float)n/2; else t = (float)n; vtw = ((t*ftw2)-(ftw*ftw))/(t*(t-1)); if (vtw < 0.0001) vtw = 0.0001; VARTW[count] = vtw; vts = ((t*fts2)-(fts*fts))/(t*(t-1)); if (vts < 0.0001) vts = 0.0001; VARTS[count] = vts; vdw = (((float)n * fd2)-(fd*fd))/((float)n*(float)n-1); if (vdw < 0.0001) vdw = 0.0001; VARD[count] = vdw; hrate = (float)chw/t; farate = (float)cf/(float)n; dprime_(&hrate, &farate, &dp); DPRPW[count] = dp; hrate = (float)chs/t; farate = (float)cf/(float)n; dprime_(&hrate, &farate, &dp); DPRPS[count] = dp; DPRDW[count] = ((ftw/t)-(fd/(float)n))/(sqrt(VARD[count])); DPRDS[count] = ((fts/t)-(fd/(float)n))/(sqrt(VARD[count])); count++; } /************************ * FUNCTION CUED_RECALL * ************************ * * the cued recall simulation routine */ void cued_recall(void) { int i, j, k, l, p, t; int no_search; /* counter for number of searches */ float rn1, rn2, rn3, rn4; /* random nos between 0 and 1 */ float num, sum; /* numerator and denominator of sampling rule */ float sc, si; /* temp storage for add up */ for (j=1; j<2*n; j+=2) { /* loop for the rows */ no_search = 0; /* get the total sum of (first row)*(current row) */ /* "sum" is the familiarity of the probe */ sum = 0.0; for (l = 1; l<=2*n; l++) { sc = (float)pow((double)v[0][l],(double)w3); si = (float)pow((double)v[j][l],(double)w1); sum += sc * si; } B: /* starting point for sampling/recovery sequence */ no_search++; rn1 = rand1(); /* sampling process: get the first column where num */ /* is more than sum */ num=0; for (k = 1; k<=2*n; k++) { sc = (float)pow((double)v[0][k],(double)w3); si = (float)pow((double)v[j][k],(double)w1); num += sc * si; if (num/sum > rn1) break; } sc = m[0][k] ? v[0][k]*w3 : 0.0; si = m[j][k] ? v[j][k]*w1 : 0.0; rn2 = rand1(); /* criterion for recovery */ if (k==j+1) { /* case 1: correct sample */ if (1.0-exp(-recov*(sc+si)) > rn2) { /* correct */ m[0][k] = 0; m[j][k] = 0; if (strength == 1) count_cw++; if (strength == 2) count_cs++; if (strength == 3 && j<=n) count_cw++; if (strength == 3 && j>n) count_cs++; /* correct; goto next iteration now */ } m[0][k] = 0; m[j][k] = 0; /* check number of searches */ if (no_search < kmax) { /* not reached kmax yet */ goto B; } } /* end case 1 */ else if (k==j) { /* case 2: self sample */ m[0][k] = 0; m[j][k] = 0; /* check number of searches */ if (no_search < kmax) { /* not reached kmax yet */ goto B; } } /* end case 2 */ else { /* case 3 */ m[0][k] = 0; m[j][k] = 0; /* check number of searches */ if (no_search < kmax) { /* not reached kmax yet */ goto B; } } /* end case 3 */ } /* end loop for rows */ } /* end function */ /******************* * FUNCTION RANSET * ******************* * * set up the random seed */ void ranset(void) { struct timeb timebuffer; ftime(&timebuffer); srand(timebuffer.millitm); } /***************** * FUNCTION RAND * ***************** * * random number generator between 0 and 1 * */ float rand1(void) { return((float)rand()/RAND_MAX); } /**************** * FUNCTION GAU * **************** * * gaussian distribution, truncated at 0.0 * */ float gau(double mu, double sigma) { float random_array[12]; int i; float total, result; do { total =0.0; for (i=0; i<=11; i++) { random_array[i] = rand1(); total += random_array[i]; } result = (sqrt(sigma) * ( total - 6.0)) + mu; } while (result <= 0.0); return(result); } /***************** * function PERM * ***************** * * Takes and array (list) of length (len) and permutes the order of its * elements. * * The length (len) from PERM() becomes the range delimiter (n) in RANDW() */ void perm(int *list, int len) { int i, j, temp; for (i = 0; i < len; i++) { j = randw(len); temp = list[j]; list[j] = list[i]; list[i] = temp; } } /* end function PERM */ /****************** * function RANDW * ****************** * * Calls the random number generator RAND() and uses the modulus (%) * operator to limit the random numbers to a specific range */ int randw(int n) { return(rand()%n); } /* end function RANDW */ /******************* * FUNCTION DPRIME * ******************* * * computes d-prime based on hit and false alarm rate * */ int dprime_(hr, far1, d) real *hr, *far1, *d; { static real y, z1, z2, y2; extern /* Subroutine */ int znorma_(); if (*hr == (float)1) { *hr = (float).99; } if (*hr == (float)0) { *hr = (float).01; } if (*far1 == (float)1) { *far1 = (float).99; } if (*far1 == (float)0) { *far1 = (float).01; } znorma_(hr, &z1, &y); znorma_(far1, &z2, &y2); *d = z1 - z2; return 0; } /* dprime_ */ /* Subroutine */ int znorma_(p, zz, y) real *p, *zz, *y; { /* Initialized data */ static real c1 = (float)2.515517; static real c2 = (float).802853; static real c3 = (float).010328; static real c4 = (float)1.432788; static real c5 = (float).189269; static real c6 = (float).001308; /* System generated locals */ real r_1; /* Builtin functions */ double log(), sqrt(), r_sign(), exp(); /* Local variables */ static real t, ab, cc, dd, pq, sz; if ((r_1 = *p - (float).5) < (float)0.) { goto L11; } else if (r_1 == 0.0) { goto L10; } else { goto L9; } L9: pq = (float)1. - *p; sz = (float)1.; goto L12; L10: *zz = (float)0.; goto L99; L11: pq = *p; sz = (float)-1.; L12: t = sqrt(log(pq) * (-2.0)); ab = ((c6 * t + c5) * t + c4) * t + (float)1.; cc = (c3 * t + c2) * t + c1; dd = cc / ab; *zz = t - dd; *zz = r_sign(zz, &sz); L99: *y = exp(-(double)(*zz) * (*zz) / (float)2.) * (float).39894228; return 0; } /* znorma_ */ double r_sign(a, b) real *a, *b; { if (*b<0.0) return(-1.0*fabs(*a)); else return(fabs(*a)); } /******************** * FUNCTION ACTION2 * ******************** * * performs action for MENU2 based on cursor position * Type of test */ void action2(int pos) { switch(pos) { case 0: cond = 1; a = 0.5; b = 0.5; c = 0.5; d = 0.075; alpha = 0.2; w1 = 0.5; w3 = 0.5; crit = 3.3; break; case 1: cond = 2; a = 0.5; b = 0.5; c = 0.5; d = 0.075; alpha = 0.2; w1 = 0.333; w2 = 0.333; w3 = 0.334; crit = 2.7; break; case 2: cond = 3; a = 0.5; b = 0.5; c = 0.5; d = 0.075; alpha = 0.2; w1 = 0.333; w2 = 0.333; w3 = 0.334; crit = 2.6; break; case 3: cond = 4; a = 0.5; b = 0.5; c = 0.5; d = 0.075; alpha = 0.2; w1 = 0.333; w2 = 0.333; w3 = 0.334; crit = 2.4; break; case 4: cond = 5; a = 0.5; b = 0.5; c = 0.5; d = 0.075; alpha = 0.2; w1 = 0.5; w3 = 0.5; kmax = 10; recov = 3.0; break; case 5: break; } } char *menu2[] = { "Single item recognition", "Associative recognition - rearranged", "Associative recognition - mixed", "Associative recognition - new", "Cued recall", "Return to Main Menu", }; char *menu4[] = { "Pure weak", "Pure strong", "Mixed", "Return to Main Menu", }; char *menu6[] = { "Context strength", "Inter-item strength", "Self strength", "Residual strength", "Strength variance", "Retrieval weights", "Recognition", "Recall", "Return to Main Menu", }; /********************* * FUNCTION Settings * ********************* * * * displays values for variables * */ void settings(void) { printf("Current settings:\n"); printf("\tTest:\t\t\t%s (%d sim.)\n", menu2[cond-1], nsim); printf("\tLength:\t\t\t%d\n", n); if (strength == 1) printf("\tStrength:\t\t%s; value = %d\n", menu4[strength-1], s1); if (strength == 2) printf("\tStrength:\t\t%s; value = %d\n", menu4[strength-1], s2); if (strength == 3) printf("\tStrength:\t\t%s; weak = %d, strong = %d\n", menu4[strength-1], s1, s2); if (diff == 0) printf("\tDifferentiation:\tNo\n"); else printf("\tDifferentiation:\tYes\n"); printf("\t%s:\ta = %.3f\n", menu6[0], a); printf("\t%s:\tb = %.3f\n", menu6[1], b); printf("\t%s:\t\tc = %.3f\n", menu6[2], c); printf("\t%s:\td = %.3f\n", menu6[3], d); printf("\t%s:\tAlpha = %.3f\n", menu6[4], alpha); if (cond == 1 || cond == 5) printf("\t%s:\tItem = %.3f, Context = %.3f\n", menu6[5], w1, w3); else printf("\t%s:\tItem 1 = %.3f, Item 2 = %.3f," " Context = %.3f\n", menu6[5], w1, w2, w3); if (cond == 5) printf("\t%s:\t\t\tKmax = %d, Recovery = %.3f\n", menu6[7], kmax, recov); else printf("\t%s:\t\tCrit. = %.3f\n", menu6[6], crit); } /******************* * FUNCTION SCREEN * ******************* * * put settings() and results of simulation on screen * */ void screen(void) { char junk; int i; float t, N, S; static real hrate, farate, dp; extern int dprime_(); /* intialize the variables */ pcw = pcs = 0.0; hw = mtw = vartw = tvartw = 0.0; hs = mts = varts = tvarts = 0.0; f = md = vard = tvard = 0.0; fs = mds = vards = tvards = 0.0; dprpw = tdprpw = dprps = tdprps = 0.0; dprdw = tdprdw = dprds = tdprds = 0.0; settings(); N = (float)nsim; if (cond == 2 || cond == 3) { if (strength == 3) t = (float)n/4; else t = (float)n/2; } else { if (strength == 3) t = (float)n/2; else t = (float)n; } S = t*N; if (cond == 5) { /* results cued recall */ pcw=(float)count_cw/(N*t); pcs=(float)count_cs/(N*t); if (strength == 3) { printf("\nWeak items:\tP(C) = %.3f\n\n", pcw); printf("Strong items:\tP(C) = %.3f\n", pcs); } else if (strength == 2) { printf("\nStrong items:\tP(C) = %.3f\n", pcs); } else { printf("\nWeak items:\tP(C) = %.3f\n\n", pcw); } } else { /* results recognition */ for (i=0; iforms overview.%c",10); exit(1); } if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) { printf("This script can only be used to decode form results. \n"); exit(1); } cl = atoi(getenv("CONTENT_LENGTH")); for(x=0;cl && (!feof(stdin));x++) { m=x; entries[x].val = fmakeword(stdin,'&',&cl); plustospace(entries[x].val); unescape_url(entries[x].val); entries[x].name = makeword(entries[x].val,'='); if (strcmp(entries[x].name, "TypeOfTest") == 0){ if (strcmp(entries[x].val, "Single item recognition") == 0) cond = 1; else if (strcmp(entries[x].val, "Associative recognition - rearranged") == 0) cond = 2; else if (strcmp(entries[x].val, "Associative recognition - mixed") == 0) cond = 3; else if (strcmp(entries[x].val, "Associative recognition - new") == 0) cond = 4; else if (strcmp(entries[x].val, "Cued recall") == 0) cond = 5; } else if (strcmp(entries[x].name, "ListLength") == 0){ sscanf(entries[x].val, "%d", &n); if (n > NMAX) { printf("Maximum number of pairs is %d!", NMAX); n = NMAX; } if (n % 8 != 0) { /* if not a multiple of 8 */ printf("Number of pairs should be a multiple of 8! Setting list length to 8."); n=8; } } else if (strcmp(entries[x].name, "ListStrength") == 0){ if (strcmp(entries[x].val, "Pure Weak") == 0) strength = 1; else if (strcmp(entries[x].val, "Pure Strong") == 0) strength = 2; else if (strcmp(entries[x].val, "Mixed") == 0) strength = 3; } else if (strcmp(entries[x].name, "WeakStrength") == 0){ sscanf(entries[x].val, "%d", &s1); if (s1 > SMAXW) { printf("Maximum strength for weak items is %d!", SMAXW); s1 = SMAXW; } else if (s1 < 1) { printf("Minimum strength for weak items is 1!"); s1 = 1; } } else if (strcmp(entries[x].name, "StrongStrength") == 0) { sscanf(entries[x].val, "%d", &s2); if (s2 > SMAXS) { printf("Maximum strength for strong items is %d!", SMAXS); s2 = SMAXS; } else if (s2 < 2) { printf("Minimum strength for strong items is 2!"); s2 = 2; } } else if (strcmp(entries[x].name, "Differentiation") == 0){ if (strcmp(entries[x].val, "on") == 0) diff = 1; else diff = 0; } else if (strcmp(entries[x].name, "ContextStrength") == 0) sscanf(entries[x].val, "%f", &a); else if (strcmp(entries[x].name, "InterItemStrength") == 0) sscanf(entries[x].val, "%f", &b); else if (strcmp(entries[x].name, "SelfStrength") == 0) sscanf(entries[x].val, "%f", &c); else if (strcmp(entries[x].name, "ResidualStrength") == 0) sscanf(entries[x].val, "%f", &d); else if (strcmp(entries[x].name, "StrengthVariance") == 0) sscanf(entries[x].val, "%f", &alpha); else if (strcmp(entries[x].name, "RetrievalWeight1") == 0) sscanf(entries[x].val, "%f", &w1); else if (strcmp(entries[x].name, "RetrievalWeight2") == 0) sscanf(entries[x].val, "%f", &w2); else if (strcmp(entries[x].name, "RetrievalWeightContext") == 0) sscanf(entries[x].val, "%f", &w3); else if (strcmp(entries[x].name, "RecognitionCriterion") == 0) sscanf(entries[x].val, "%f", &crit); else if (strcmp(entries[x].name, "Kmax") == 0) sscanf(entries[x].val, "%d", &kmax); else if (strcmp(entries[x].name, "Recovery") == 0) sscanf(entries[x].val, "%f", &recov); else if (strcmp(entries[x].name, "NumberOfSimulations") == 0){ sscanf(entries[x].val, "%d", &nsim); if (nsim > NSIM) { printf("Maximum number simulatoins is %d!", NSIM); nsim = NSIM; } } } printf("

Query Results

"); if ((cond == 1 || cond == 5) && (w2 != 0.0)) /* single item recognition and cued recall */ printf("The Retrieval Weight for Item 2 should be 0.
\n"); if (s2 <= s1) printf("Strong items should be stronger than weak ones!
\n"); if (fabs((double) (w1+w2+w3-1.0)) > 0.001){ printf("Retrieval Weights must sum to one.
\n"); } printf("
\n"); 
    ranset();                                 /* init the random no generator */
    simulate();
    screen();
    printf("
\n"); }