double Denoise::gain_em(double Rprio, double Rpost, double alpha) { /* Ephraim-Malah classic noise suppression, from 1984 paper */ double gain = 0.886226925*sqrt(1.0/(1.0+Rpost)*(Rprio/(1.0+Rprio))); gain *= hypergeom((1.0+Rpost)*(Rprio/(1.0+Rprio))); return gain; }
char twotail_exact(struct tw *m, double *cp, double *sp) #define PR (*cp) #define FT (*sp) { char k; struct entry em; double sec_prob, check, orig_p; int orig_cross; em=copy_entry(m); if( !(em.x1 * em.x4 - em.x2 * em.x3) ) { printf("exact fit -> det = 0\n"); *cp=1.; *sp=0.5; exactfit=1; return 1; } /* probability of the original table */ if((PR=hypergeom(&em)) < 0.0) { PR=FT=DMY; return -1; } k=minx(&em); orig_p=PR; switch (k) { /* first tail */ case 1: while( em.x1 && em.x4 ) { --em.x1; /* decrement 11-22 diagonal */ --em.x4; ++em.x2; ++em.x3; if((check=hypergeom(&em)) < 0.0) { PR=FT=DMY; return -1; } PR+=check; } break; case 2: while( em.x2 && em.x3 ) { --em.x2; /* decrement 12-21 diagonal */ --em.x3; ++em.x1; ++em.x4; if((check=hypergeom(&em)) < 0.0) { PR=FT=DMY; return -1; } PR+=check; } break; } #define X1 em.x1 #define X2 em.x2 #define X3 em.x3 #define X4 em.x4 /* second tail */ em=copy_entry(m); orig_cross = ABS( X1*X4 - X2*X3 ); sec_prob=0.0; switch (k) { case 1: while( em.x2 && em.x3 ) { --em.x2; /* decrement 12-21 diagonal */ --em.x3; ++em.x1; ++em.x4; if ( ABS( X1*X4 - X2*X3 ) < orig_cross ) continue; if((check=hypergeom(&em)) < 0.0) { PR=FT=DMY; return -1; } if(check > orig_p) continue; sec_prob+=check; } break; case 2: while( em.x1 && em.x4 ) { --em.x1; /* decrement 11-22 diagonal */ --em.x4; ++em.x2; ++em.x3; if ( ABS( X1*X4 - X2*X3 ) < orig_cross ) continue; if((check=hypergeom(&em)) < 0.0) { PR=FT=DMY; return -1; } if(check > orig_p) continue; sec_prob+=check; } break; } /* probabilities */ FT=PR; /* first tail (closest) */ PR+=sec_prob; /* both tails */ return 1; #undef PR #undef FT #undef X1 #undef X2 #undef X3 #undef X4 }