stretch_correction

sofia_redux.toolkit.resampling.stretch_correction(rchi2, density, variance_offset)[source]

A sigmoid function used by the “shaped” adaptive resampling algorithm.

This sigmoid function is applied when determining the severity of stretch (\(s\)) applied to principle axes of a rotated weighting kernel. The correction term (\(\gamma\)) is applied as:

\[s_{corrected} = s^\gamma\]

Since the stretch values are determined from the singular values of a normalized Hermitian matrix \(A\) (see shaped_adaptive_weight_matrix()), where \(|A| \equiv 1\), then:

\[\prod_{k=1}^{K}{s_k} = \prod_{k=1}^{K}{s_{corrected, k}} = 1\]

in \(K\) dimensions. In other words, this does not affect the overall size (or volume) of the weighting kernel.

The correction factor is calculated using half_max_sigmoid() using \(c=1\), lower and upper asymptotes as -1 and 1, such that the midpoint is fixed at zero when \(x=0\). After making the necessary substitutions, the correction factor is given as:

\[\gamma = \frac{2} {\left( {1 + (2^{\nu} - 1)e^{B(1 - x)}} \right)^{1/\nu}} - 1\]

We then set the rate as \(B = \rho\) where \(\rho\) is the density as determined by relative_density(), and the point of inflection as \(exp(\sigma)\) where \(\sigma^2\) is the variance_offset as determined by offset_variance(). Finally, setting \(x = \chi_r^2\) we arrive at:

\[\gamma = \frac{2} {\left( {1 + (2^{exp(\sigma)} - 1)e^{\rho (1 - \chi_r^2)}} \right)^{1/exp(\sigma)}} - 1\]

As \(\gamma \rightarrow 0\), the resulting shape becomes more symmetrical. This will be the case when the fitting point is away from the center of the sample distribution (high \(\sigma^2\)), the fit occurs in a low density area (low \(\beta\)), or \(\chi_r^2 \rightarrow 1\).

It should be noted that \(s_{corrected} \rightarrow s\) as \(\chi_r^2 \rightarrow \infty\). However, in the range \(0 < \chi_r^2 < 1\), the correction factor is actually negative, with \(\gamma \rightarrow -1\) as \(\chi_r^2 \rightarrow 0\). This has the effect of effectively rotating the shape so that its major axis is perpendicular to the mean sample gradient rather than parallel.

Parameters:
rchi2int or float or numpy.ndarray (shape)

The reduced chi-squared statistic of the initial fit.

densityint or float or numpy.ndarray (shape)

The local relative density at the fitting point (see relative_density()).

variance_offsetint or float or numpy.ndarray (shape)

The variance at the fitting with respect to the coordinate distribution of the sample used in the fit. Please see offset_variance() for further information.

Returns:
correctionnumpy.ndarray

The correction factor.

Notes

For high valued inflection points, numpy will set values in the denominator of the above equation to infinity, or 1, resulting in a misleading correction factor of \(\pm 1\). In order to counter this, half_max_sigmoid() could not be used, and the calculation is done “by hand” with spurious values resulting in a correction factor of zero. This also requires some numba hackery resulting in the final output value being a numpy.ndarray in all cases. When single valued inputs are supplied, the output will be a single-valued array of zero dimensions which should be suitable for subsequent calculations.