pydvl.influence.torch.pre_conditioner
¶
PreConditioner
¶
Bases: ABC
Abstract base class for implementing pre-conditioners for improving the convergence of CG for systems of the form
i.e. a matrix \(M\) such that \(M^{-1}(A + \lambda \operatorname{I})\) has a better condition number than \(A + \lambda \operatorname{I}\).
fit
abstractmethod
¶
fit(
mat_mat_prod: Callable[[Tensor], Tensor],
size: int,
dtype: dtype,
device: device,
regularization: float = 0.0,
)
Implement this to fit the pre-conditioner to the matrix represented by the
mat_mat_prod
Args:
mat_mat_prod: a callable that computes the matrix-matrix product
size: size of the matrix represented by mat_mat_prod
dtype: data type of the matrix represented by mat_mat_prod
device: device of the matrix represented by mat_mat_prod
regularization: regularization parameter \(\lambda\) in the equation
$ ( A + \lambda \operatorname{I})x = \operatorname{rhs} $
Returns:
self
Source code in src/pydvl/influence/torch/pre_conditioner.py
solve
¶
solve(rhs: Tensor)
Solve the equation \(M@Z = \operatorname{rhs}\) Args: rhs: right hand side of the equation, corresponds to the residuum vector (or matrix) in the conjugate gradient method
RETURNS | DESCRIPTION |
---|---|
solution \(M^{-1}\operatorname{rhs}\) |
Source code in src/pydvl/influence/torch/pre_conditioner.py
to
abstractmethod
¶
to(device: device) -> PreConditioner
Implement this to move the (potentially fitted) preconditioner to a specific device
JacobiPreConditioner
¶
JacobiPreConditioner(num_samples_estimator: int = 1)
Bases: PreConditioner
Pre-conditioner for improving the convergence of CG for systems of the form
The JacobiPreConditioner uses the diagonal information of the matrix \(A\). The diagonal elements are not computed directly but estimated via Hutchinson's estimator.
where \(u_i\) are i.i.d. Gaussian random vectors. Works well in the case the matrix \(A + \lambda \operatorname{I}\) is diagonal dominant. For more information, see the documentation of Conjugate Gradient Args: num_samples_estimator: number of samples to use in computation of Hutchinson's estimator
Source code in src/pydvl/influence/torch/pre_conditioner.py
solve
¶
solve(rhs: Tensor)
Solve the equation \(M@Z = \operatorname{rhs}\) Args: rhs: right hand side of the equation, corresponds to the residuum vector (or matrix) in the conjugate gradient method
RETURNS | DESCRIPTION |
---|---|
solution \(M^{-1}\operatorname{rhs}\) |
Source code in src/pydvl/influence/torch/pre_conditioner.py
fit
¶
fit(
mat_mat_prod: Callable[[Tensor], Tensor],
size: int,
dtype: dtype,
device: device,
regularization: float = 0.0,
)
Fits by computing an estimate of the diagonal of the matrix represented by
mat_mat_prod
via Hutchinson's estimator
PARAMETER | DESCRIPTION |
---|---|
mat_mat_prod |
a callable representing the matrix-matrix product |
size |
size of the square matrix
TYPE:
|
dtype |
needed data type of inputs for the mat_mat_prod
TYPE:
|
device |
needed device for inputs of mat_mat_prod
TYPE:
|
regularization |
regularization parameter \(\lambda\) in \((A+\lambda I)x=b\)
TYPE:
|
Source code in src/pydvl/influence/torch/pre_conditioner.py
NystroemPreConditioner
¶
NystroemPreConditioner(rank: int)
Bases: PreConditioner
Pre-conditioner for improving the convergence of CG for systems of the form
The NystroemPreConditioner computes a low-rank approximation
where \((\cdot)^{\dagger}\) denotes the Moore-Penrose inverse, and uses the matrix
for pre-conditioning, where \( \sigma_{\text{rank}} \) is the smallest eigenvalue of the low-rank approximation.
Source code in src/pydvl/influence/torch/pre_conditioner.py
solve
¶
solve(rhs: Tensor)
Solve the equation \(M@Z = \operatorname{rhs}\) Args: rhs: right hand side of the equation, corresponds to the residuum vector (or matrix) in the conjugate gradient method
RETURNS | DESCRIPTION |
---|---|
solution \(M^{-1}\operatorname{rhs}\) |
Source code in src/pydvl/influence/torch/pre_conditioner.py
fit
¶
fit(
mat_mat_prod: Callable[[Tensor], Tensor],
size: int,
dtype: dtype,
device: device,
regularization: float = 0.0,
)
Fits by computing a low-rank approximation of the matrix represented by
mat_mat_prod
via Nystroem approximation
PARAMETER | DESCRIPTION |
---|---|
mat_mat_prod |
a callable representing the matrix-matrix product |
size |
size of the square matrix
TYPE:
|
dtype |
needed data type of inputs for the mat_mat_prod
TYPE:
|
device |
needed device for inputs of mat_mat_prod
TYPE:
|
regularization |
regularization parameter \(\lambda\) in \((A+\lambda I)x=b\)
TYPE:
|