IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42846 for trunk/psLib


Ignore:
Timestamp:
May 9, 2025, 12:38:05 PM (14 months ago)
Author:
eugene
Message:

fixing an error with psBinomialCoeff due to integerizing a fraction; this function is only used by the 1D vector fitting function (regular and clipped) and only manifests for polynomials of order > 2; I have scanned the code and the only place this happens is in the overscan correction for which the order is set in the recipe; some cameras other than gpc1 and gpc2 have higher order overscan models and would have been affected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psBinomialCoeff.c

    r36222 r42846  
    2222  if (k == 0) { return (b); }
    2323
     24  psS64 num = 1;
     25  psS64 den = 1;
     26
    2427  for (i = 1; i <= k; i++) {
    25     b *= (N - (k - i))/i;
     28
     29      // old version: b *= (N - (k - i))/i;
     30      // wikipedia recursion version: b *= (N + 1 - i)/i;
     31
     32      // the old version just counts the elements in the opposite order from the wikipedia version:
     33
     34      // numerators would be, e.g., for C(6,4):
     35      // old  version (6 - (4 - 1)), (6 - (4 - 2)), (6 - (4 - 3)), (6 - (4 - 4)) = 3, 4, 5, 6
     36      // wiki version (6 + 1 - 1), (6 + 1 - 2), (6 + 1 - 3), (6 + 1 - 4) = 6, 5, 4, 3
     37
     38      // denominators would be the same: 1, 2, 3, 4.
     39
     40      // since these are multiplied, the order of the numerators is independent of the order of the denominators
     41
     42      // but both of these formulae are bad because the factors can be fractional, but that means we cannot use an
     43      // integer to carry the intermediate result. 
     44
     45      // instead, we need to calculate the integer product of the denominators and the integer
     46      // product of the numerators and divide at the end
     47     
     48      // this causes an error for C(3,2), C(5,2), C(4,3), etc.
     49
     50      num *= (N + 1 - i);
     51      den *= i;
    2652  }
     53
     54  b = num / den;
    2755
    2856  return(b);
Note: See TracChangeset for help on using the changeset viewer.