Skip to content

MGroup.LinearAlgebra.Iterative.ConjugateGradient

Dimitris Tsapetis edited this page Apr 17, 2019 · 1 revision

CGAlgorithm

Implements the Conjugate Gradient algorithm for solving linear systems with a positive definite matrix. The implementation is based on the algorithm presented in section B2 of "An Introduction to the Conjugate Gradient Method Without the Agonizing Pain", Jonathan Richard Shewchuk, 1994 Authors: Serafeim Bakalakos

public class MGroup.LinearAlgebra.Iterative.ConjugateGradient.CGAlgorithm

Methods

Type Name Summary
CGStatistics Solve(IMatrixView matrix, IVectorView rhs, IVector solution, Boolean initialGuessIsZero) Solves the linear system A * x = b, where A = and b =. Initially x = `` and then it converges to the solution.
CGStatistics Solve(ILinearTransformation matrix, IVectorView rhs, IVector solution, Boolean initialGuessIsZero) Solves the linear system A * x = b, where A = and b =. Initially x = `` and then it converges to the solution.

CGStatistics

Data Transfer Object that collects information about the execution and convergence when solving a linear system with the Conjugate Gradient algorithm. Authors: Serafeim Bakalakos

public class MGroup.LinearAlgebra.Iterative.ConjugateGradient.CGStatistics

Properties

Type Name Summary
String AlgorithmName The name of the iterative algorithm. E.g CG, PCG, ...
Boolean HasConverged True if the requested tolerance of the residual vector r = b - A * x has been achieved. False if the algorithm has terminated due to other criteria.
Double NormRatio The value of norm2(b-Ax) / norm2(b-Ax0), where x is the solution vector after the final iteration of the algorithm and x0 the intial guess for the same solution vector (usually x0 = 0).
Int32 NumIterationsRequired The number of iterations that were run before the algorithm terminated.

Methods

Type Name Summary
String ToString() Reports the accumulated data of this MGroup.LinearAlgebra.Iterative.ConjugateGradient.CGStatistics instance.

FletcherReevesBeta

Fletcher-Reeves: beta = (rNew * inv(M) * rNew) / (rOld * inv(M) * rOld). This is the simplest formula to calculate PCG's beta parameter and does not require any extra memory or calculations. Authors: Serafeim Bakalakos

public class MGroup.LinearAlgebra.Iterative.ConjugateGradient.FletcherReevesBeta
    : IPcgBetaParameterCalculation

Methods

Type Name Summary
Double CalculateBeta(IVectorView residualNew, IVectorView preconditionedResidualNew, Double dotPreconditionedResidualNew, Double dotPreconditionedResidualOld) See MGroup.LinearAlgebra.Iterative.ConjugateGradient.IPcgBetaParameterCalculation.CalculateBeta(MGroup.LinearAlgebra.Vectors.IVectorView,MGroup.LinearAlgebra.Vectors.IVectorView,System.Double,System.Double).
void Initialize(IVectorView initialResidual) See MGroup.LinearAlgebra.Iterative.ConjugateGradient.IPcgBetaParameterCalculation.Initialize(MGroup.LinearAlgebra.Vectors.IVectorView).

IPcgBetaParameterCalculation

Defines how the beta parameter of PCG, which is used to update the direction vector, will be calculated. There are numerous alternatives, which are equivalent only for linear PCG with a constant preconditioner. Authors: Serafeim Bakalakos

public interface MGroup.LinearAlgebra.Iterative.ConjugateGradient.IPcgBetaParameterCalculation

Methods

Type Name Summary
Double CalculateBeta(IVectorView residualNew, IVectorView preconditionedResidualNew, Double dotPreconditionedResidualNew, Double dotPreconditionedResidualOld) Calculates the beta parameter of PCG β(t+1), which will be used to update the direction vector d(t+1).
void Initialize(IVectorView initialResidual) Initializes the internal state of this MGroup.LinearAlgebra.Iterative.ConjugateGradient.IPcgBetaParameterCalculation instance. Has to be called once per linear system solution.

PcgAlgorithm

Implements the untransformed Preconditioned Conjugate Gradient algorithm for solving linear systems with symmetric positive definite matrices. This implementation is based on the algorithm presented in section B3 of "An Introduction to the Conjugate Gradient Method Without the Agonizing Pain", Jonathan Richard Shewchuk, 1994 Authors: Serafeim Bakalakos

public class MGroup.LinearAlgebra.Iterative.ConjugateGradient.PcgAlgorithm
    : PcgAlgorithmBase

Methods

Type Name Summary
CGStatistics SolveInternal(ILinearTransformation matrix, IPreconditioner preconditioner, IVectorView rhs, IVector solution, IVector residual, Func<IVector> zeroVectorInitializer)

PcgAlgorithmBase

Base abstract class for Preconditioned Conjugate Gradient implementations. Authors: Serafeim Bakalakos

public abstract class MGroup.LinearAlgebra.Iterative.ConjugateGradient.PcgAlgorithmBase

Fields

Type Name Summary
IMaxIterationsProvider maxIterationsProvider
IResidualConvergence residualConvergence
IResidualCorrection residualCorrection
Double residualTolerance

Methods

Type Name Summary
CGStatistics Solve(IMatrixView matrix, IPreconditioner preconditioner, IVectorView rhs, IVector solution, Boolean initialGuessIsZero, Func<IVector> zeroVectorInitializer) Solves the linear system A * x = b by solving the preconditioned system inv(P) * A * inv(P)^T * y = inv(P) * b, where A = , b = , x is the solution, y = P^T * x, P*P^T = . Initially x = and then it converges to the solution.
CGStatistics Solve(ILinearTransformation matrix, IPreconditioner preconditioner, IVectorView rhs, IVector solution, Boolean initialGuessIsZero, Func<IVector> zeroVectorInitializer) Solves the linear system A * x = b by solving the preconditioned system inv(P) * A * inv(P)^T * y = inv(P) * b, where A = , b = , x is the solution, y = P^T * x, P*P^T = . Initially x = and then it converges to the solution.
CGStatistics SolveInternal(ILinearTransformation matrix, IPreconditioner preconditioner, IVectorView rhs, IVector solution, IVector residual, Func<IVector> zeroVectorInitializer)

PcgBuilderBase

public abstract class MGroup.LinearAlgebra.Iterative.ConjugateGradient.PcgBuilderBase

Properties

Type Name Summary
IMaxIterationsProvider MaxIterationsProvider Specifies how to calculate the maximum iterations that the PCG algorithm will run for.
IResidualConvergence ResidualConvergence Specifies how the PCG algorithm will check that convergence has been reached.
IResidualCorrection ResidualCorrection Specifies how often the residual vector will be corrected by an exact (but costly) calculation.
Double ResidualTolerance The PCG algorithm will converge when sqrt(rinv(M)r) / sqrt(r0inv(M)r0) <= ``, where M is the preconditioner, r = Ax is the current residual vector and r0 = Ax0 the initial residual vector.

PcgReorthogonalizationCache

Manages the insertion and removal of PCG direction vectors and related data, that will be used for reorthogonalization. Authors: Serafeim Bakalakos

public class MGroup.LinearAlgebra.Iterative.ConjugateGradient.PcgReorthogonalizationCache

Properties

Type Name Summary
List<IVectorView> Directions The conjugate direction vectors stored so far.
List<Double> DirectionsTimesMatrixTimesDirections The products MGroup.LinearAlgebra.Iterative.ConjugateGradient.PcgReorthogonalizationCache.Directions * systemMatrix * MGroup.LinearAlgebra.Iterative.ConjugateGradient.PcgReorthogonalizationCache.Directions stored so far.
List<IVectorView> MatrixTimesDirections The products systemMatrix * MGroup.LinearAlgebra.Iterative.ConjugateGradient.PcgReorthogonalizationCache.Directions stored so far.

Methods

Type Name Summary
void RemoveNewDirectionVectorData(Int32 numNewVectorsToRemove) Discards the direction vectors and any corresponding data of the newest PCG iterations.
void RemoveOldDirectionVectorData(Int32 numOldVectorsToRemove) Discards the direction vectors and any corresponding data of the oldest PCG iterations.
void StoreDirectionData(IVectorView direction, IVectorView matrixTimesDirection, Double directionTimesMatrixTimesDirection) Stores a new direction vector and other related data. The new entries will be regarded as latest.

PcgWithReorthogonalization

Implements the untransformed Preconditioned Conjugate Gradient algorithm for solving linear systems with symmetric positive definite matrices. The implementation is based on the algorithm presented in pages 51-54 of the PhD dissertation "Seismic soil-structure interaction with finite elements and the method of substructures", George Stavroulakis, 2014 Authors: Serafeim Bakalakos, George Stavroulakis

public class MGroup.LinearAlgebra.Iterative.ConjugateGradient.PcgWithReorthogonalization
    : PcgAlgorithmBase

Methods

Type Name Summary
void CalculateInitialSolutionFromStoredDirections(IVectorView rhsNew, IVector initialSolution, Boolean isSolutionZero) Calculates the initial approximation to the linear system's solution vector, by using a series of conjugate direction vectors that have been stored previously by PCG during the solution of other linear systems with the same matrix. This method should be used to solve linear systems with different right hand side vectors and the same matrix.
CGStatistics SolveInternal(ILinearTransformation matrix, IPreconditioner preconditioner, IVectorView rhs, IVector solution, IVector residual, Func<IVector> zeroVectorInitializer)

PolakRibiereBeta

Polak-Ribiere: beta = max{((rNew-rOld) * inv(M) * rNew) / (rOld * inv(M) * rOld), 0}. This formula usually improves performance for variable preconditioners (changing between iterations). However it requires an extra vector to be copied and stored at each iteration.

public class MGroup.LinearAlgebra.Iterative.ConjugateGradient.PolakRibiereBeta
    : IPcgBetaParameterCalculation

Methods

Type Name Summary
Double CalculateBeta(IVectorView residualNew, IVectorView preconditionedResidualNew, Double dotPreconditionedResidualNew, Double dotPreconditionedResidualOld) See MGroup.LinearAlgebra.Iterative.ConjugateGradient.IPcgBetaParameterCalculation.CalculateBeta(MGroup.LinearAlgebra.Vectors.IVectorView,MGroup.LinearAlgebra.Vectors.IVectorView,System.Double,System.Double).
void Initialize(IVectorView initialResidual) See MGroup.LinearAlgebra.Iterative.ConjugateGradient.IPcgBetaParameterCalculation.Initialize(MGroup.LinearAlgebra.Vectors.IVectorView).
Clone this wiki locally