Conjugate gradients for the normal equation#
- class EarlyStopping.ConjugateGradients(design, response, critical_value=None, starting_value=None, true_signal=None, true_noise_level=None, interpolation=False, computation_threshold=1e-08)#
[Source] Conjugate gradients algorithm applied to the normal equation of a linear model
Parameters
design:
array
. nxp design matrix of the linear model.response:
array
. n-dim vector of the observed data in the linear model.true_signal:
array or None, default = None
. p-dim vector. For simulation purposes only. For simulated data the true signal can be included to compute additional quantities.true_noise_level:
float or None, default = None
. For simulation purposes only. Corresponds to the standard deviation of normally distributed noise contributing to the response variable.critical_value:
array or None, default = None
. Critical value for the early stopping rule.starting_value:
array or None, default = None
. Determines the zeroth step of the iterative procedure. Defaults to the zero vector.interpolation:
boolean, default = False
. If interpolation is set toTrue
, the early stopping iteration index can be noninteger valued.computation_threshold:
float, default = 10 ** (-8)
. Threshold used to terminate the conjugate gradients algorithm.Attributes
sample_size:
int
. Sample size of the linear model.parameter_size:
int
. Parameter size of the linear model.iter:
int
. Current conjugate gradient iteration of the algorithm.conjugate_gradient_estimate:
array
. Conjugate gradient estimate at the current iteration for the data given in design and response.early_stopping_index:
int or float or None
. Early Stopping iteration index. Is set toNone
if no early stopping is performed.residuals:
array
. Lists the sequence of the squared residuals between the observed data and the conjugate gradient estimator.strong_empirical_errors:
array
. Only exists if true_signal was given. Lists the values of the strong empirical error between the conjugate gradient estimator and the true signal up to the current conjugate gradient iteration.weak_empirical_errors:
array
. Only exists if true_signal was given. Lists the values of the weak empirical error between the conjugate gradient estimator and the true signal up to the current conjugate gradient iteration.Methods
iterate(
number_of_iterations = 1
)Performs number_of_iterations of the conjugate gradients algorithm.
discrepancy_stop(
max_iter
)Stops the conjugate gradients algorithm based on the discrepancy principle.
gather_all(
max_iter
)Gathers all relevant simulation data.
calculate_interpolated_residual(
index
)Calculates the interpolated squared residual(s) at a(n array of) noninteger index (indices).
calculate_interpolated_strong_empirical_error(
index
)Calculates the interpolated strong empirical error(s) at a(n array of) noninteger index (indices).
calculate_interpolated_weak_empirical_error(
index
)Calculates the interpolated weak empirical error(s) at a(n array of) noninteger index (indices).
calculate_empirical_oracles(
max_iter
)Calculates the strong and weak empirical oracle indices and errors.
- ConjugateGradients.iterate(number_of_iterations=1)#
Performs number_of_iterations of the conjugate gradients algorithm.
Parameters
number_of_iterations:
int, default = 1
. Number of conjugate gradients iterations to be performed.
- ConjugateGradients.discrepancy_stop(max_iter)#
Early stopping for the conjugate gradient procedure based on the discrepancy principle. Procedure is stopped when the squared residuals go below critical_value or iteration max_iter is reached.
Parameters
max_iter:
int
. The maximum number of iterations to be performed.
- ConjugateGradients.gather_all(max_iter)#
Gathers all relevant simulation data (runs the algorithm till max_iter) but tracks the early stopping index and the associated conjugate gradient estimate.
Parameters
max_iter:
int
. The maximum number of iterations to be performed.
- ConjugateGradients.calculate_interpolated_residual(index)#
Calculates the interpolated squared residual at a possibly noninteger iteration index. The function is vectorized such that arrays of indices can be inserted.
Parameters
index:
array or float
. Index or array of indices where the interpolated squared residual(s) should be calculated.
- ConjugateGradients.calculate_interpolated_strong_empirical_error(index)#
Calculates the interpolated strong empirical error at a possibly noninteger iteration index. The function is vectorized such that arrays of indices can be inserted.
Parameters
index:
array or float
. Index or array of indices where the interpolated error(s) should be calculated.
- ConjugateGradients.calculate_interpolated_weak_empirical_error(index)#
Calculates the interpolated weak empirical error at a possibly noninteger iteration index. The function is vectorized such that arrays of indices can be inserted.
Parameters
index:
array or float
. Index or array of indices where the interpolated error(s) should be calculated.
- ConjugateGradients.calculate_empirical_oracles(max_iter)#
Calculates the strong and weak empirical oracles. Returns a vector, where the first (third) entry is the strong (weak) empirical oracle and the second (fourth) entry is the corresponding strong (weak) empirical error.
Parameters
max_iter:
int
. The maximum number of iterations to be performed.