lts_linear_regression#
- ctapipe.fitting.lts_linear_regression(x, y, samples=20, relative_sample_size=0.85, max_iterations=20, eps=1e-12, rng=Generator(PCG64) at 0x7C0B4AE62500)[source]#
Perform a Least Trimmed Squares regression.
This is based on algorithm (2) described in [RVD06]
We start from randomly sampled two points of the dataset and then iteratively choose the
relative_sample_sizefraction of points with the smallest residuals to redo the fit until it convergtes.This is done for
samplesinitial samples and the solution with the lowest residual sum of squares is returned along with that error.- Parameters:
- x: np.array
x values for the linear regression
- y: np.array
y values for the linear regression
- samples: int
How many initial samples to generate. For each sample, the C-step optimization is performed and the result with the lowest sum of squares is returned.
- relative_sample_size: float
Portion of points to be used for the fit, should be > 0.5
- max_iterations: int
maximum number of C-Steps performed for each sample. The fit should converge much faster (normally after < 10 iterations)
- eps: float
differences in residual sum of squares at which the iteration will be stopped
- rng: numpy.random.Generator
Random generator for drawing fit samples
- Returns:
- beta: np.array
Parameter vector of the linear regression
- error: float
Residual sum of squares of the best fit