Skip to content

Binning functions

Pierre Paleo requested to merge binning_functions into 2022.3

About

This MR adds a general-purpose binning function.

At first I thought dedicated binning functions (for each binning factor) would be faster, but it turns out binning_n is faster.
Hopefully this will enable to remove some code.

Close #136 (closed)

To do

  • Implement a general-purpose binning function
  • Unit tests
  • Integrate in pipeline
  • End-to-end reconstruction test

Notes

The general-purpose binning function is tested against an array numpy.arange(n0 * n1).reshape((n0, n1)).
Each entry (i, j) of this array is equal to i * n1 + j.

After binning, the binned array at position (p_j, p_j) is equal to
\dfrac{1}{b_i b_j} \displaystyle\sum_{i=p_i}^{p_i + b_i - 1} \displaystyle\sum_{j=p_j}^{p_j+b_j-1} \left(N_x \cdot i + j\right)

which happens to be equal to
1/2 \cdot \left( N_x b_{i} + 2 N_x p_{i} - N_x + b_{j} + 2 p_{j} - 1 \right)

from sympy import init_session
init_session(quiet=True)
b, p_i, p_j, i, j, Nx, b_i, b_j = symbols("b, p_i, p_j, i, j, Nx, b_i, b_j")
sum_expr = Sum(Sum(Nx*i + j, (j, p_j, p_j+b_i-1)), (i, p_i, p_i+b_j-1))
pretty_print(sum_expr)
sum_result = sum_expr.doit()
sum_result_factorized = factor(sum_result)
pretty_print(sum_result)
bin_result = factor(1/(b_i*b_j) * sum_result)
pretty_print(bin_result)
Edited by Pierre Paleo

Merge request reports

Loading