double gsl_ran_binomial_pdf (const unsigned int k, const double p, const unsigned int n) { if (k > n) { return 0; } else { double P; if (p == 0) { P = (k == 0) ? 1 : 0; } else if (p == 1) { P = (k == n) ? 1 : 0; } else { double ln_Cnk = gsl_sf_lnchoose (n, k); P = ln_Cnk + k * log (p) + (n - k) * log1p (-p); P = exp (P); } return P; } }
double calcEIndex(int nX1, int nY1, int nX2, int nY2, int nSplit, int nLenI) { int i = 0, nM = 0, nN = 0, nL = 0, nH = 0, nO = 0; double dLN1 = 0.0, dLN2 = 0.0, dLD = 0.0; if(nX1 <= nX2){ nM = nX1 - nY1; nH = nY1; nN = nX1; nL = nLenI - nSplit - 1; nO = nX1 + nY1; } else{ nM = nX2 - nY2; nH = nY2; nN = nX2; nL = nSplit + 1; nO = nX2 + nY2; } if(nL - nO >= 0 && nH <= nL - nO){ dLN1 = gsl_sf_lnchoose(nL - nO, nH); } else{ dLN1 = 0.0; } dLN2 = gsl_sf_lnchoose(nO, nM); if(nL >= nN){ dLD = gsl_sf_lnchoose(nL, nN); } else{ dLD = 0.0; } return dLD - dLN1 - dLN2; }
/* Calculates the minimum number of inliers as a function of the number of putative correspondences. Based on equation (7) in Chum, O. and Matas, J. Matching with PROSAC -- Progressive Sample Consensus. In <EM>Conference on Computer Vision and Pattern Recognition (CVPR)</EM>, (2005), pp. 220--226. @param n number of putative correspondences @param m min number of correspondences to compute the model in question @param p_badsupp prob. that a bad model is supported by a correspondence @param p_badxform desired prob. that the final transformation returned is bad @return Returns the minimum number of inliers required to guarantee, based on p_badsupp, that the probability that the final transformation returned by RANSAC is less than p_badxform */ int calc_min_inliers( int n, int m, double p_badsupp, double p_badxform ) { double pi, sum; int i, j; for( j = m+1; j <= n; j++ ) { sum = 0; for( i = j; i <= n; i++ ) { pi = ( i - m ) * log( p_badsupp ) + ( n - i + m ) * log( 1.0 - p_badsupp ) + gsl_sf_lnchoose( n - m, i - m ); sum += exp( pi ); } if( sum < p_badxform ) break; } return j; }
double gsl_ran_binomial_pdf (const unsigned int k, const double p, const unsigned int n) { if (k > n) { return 0; } else { double P; double ln_Cnk = gsl_sf_lnchoose (n, k); P = ln_Cnk + k * log (p) + (n - k) * log (1 - p); P = exp (P); return P; } }
static VALUE rb_gsl_sf_lnchoose(VALUE obj, VALUE n, VALUE m) { CHECK_FIXNUM(n); CHECK_FIXNUM(m); return rb_float_new(gsl_sf_lnchoose(FIX2INT(n), FIX2INT(m))); }