/* Ethan Wolf 1995 */ #include #include #include "scio.h" #include "likelihood.h" #include "methods.h" #include "postscript.h" #include "scatter_ps.h" #include "compute_like.h" /* ax+b is the likelihood line approximation computed in likelihood region */ /* from low % to hight % */ void likelihood(long n[2], int mode, int filenum, double ratio, int minplace, int maxplace, double *means[2], long *counts[2], double gauss_mean[2], double sd[2], double down[2], FILE *fout, FILE *foutps, FILE *scatter, FILE *scores, double a[2], double b[2], double low_percent, double high_percent, double error_allowed) { int i, f; double x, hist_height; double _likelihood[2][201-2*MINSCORE]; double *likelihood[2]; double area1=0, area2=0; int low[2]={0,0}; /* How many consectutive low % found. */ int high[2]={0,0}; /* How many consecutive high % found. */ int low_box[2], high_box[2]; /* These hold the first */ /* and last boxes that are low, high % likely, where these */ /* determined by finding the first box above the gaussian mean such */ /* that it has likelihood above low percent and the next two boxes */ /* are also above low-error percent. Similarly, high% is the first */ /* following box such that it has likelihood < %high and the two */ /* following have likelihood at least high-error */ double error=0; likelihood[0] = &(_likelihood[0][-2*MINSCORE]); likelihood[1] = &(_likelihood[1][-2*MINSCORE]); if (mode & STOCK_METHOD) { for(i=minplace; i<=maxplace; i++) likelihood[0][i]= stock_like(ratio, (double)i/2, gauss_mean[0],sd[0], down[0],gauss_mean[1], sd[1], down[1]); filenum=1; /*** For printout purposes. ***/ } else for(f=0; f low_percent - error) && ( (double)i/2 > gauss_mean[f]) ) { /* Guessing low percentage is higher than mean. */ low[f]++; error= error_allowed; /* For 2nd and 3d boxes.*/ if (low[f]==3) { low_box[f]=i-2; /* First of 3 consecutive low-error boxes */ error=0; /* Now find first high percentage.*/ } } else { low[f]=0; error=0; /* Back to finding first low box. */ } } else if (high[f]<3) if (likelihood[f][i] >= high_percent - error) { high[f]++; error=error_allowed; if (high[f]==3) high_box[f]=i-3; /* Last box < high_percent was three before.*/ } else { high[f]=0; error=0; /* Back to finding first high box. */ } } if (high[f] < 3) /* didn't find a high_box, so make it last box. */ high_box[f]=maxplace; if (low[f]< 3) /* didn't find a low_box so make it the mean. */ low_box[f] = (int)(2*gauss_mean[f]); fprintf(fout, "For txt file %d:", f); least_sq_fit(&a[f], &b[f],(double)low_box[f]/2, (double)high_box[f]/2, means[f],likelihood[f],fout); } for(f=0;fmax_count) max_count=counts[i]; for (first_half_box=minplace; counts[first_half_box] < (double)max_count/2; ++first_half_box); for (last_half_box=maxplace; counts[last_half_box] < (double)max_count/2; --last_half_box); for (i=first_half_box; i<=last_half_box; i++) { new_gauss_mean += means[i]* (double)counts[i]; half_count += counts[i]; } new_gauss_mean /= half_count; fprintf(stderr, "\nGaussian mean based on half_max boxes = %lf\n", new_gauss_mean); return(new_gauss_mean); }