Skip to content
3 changes: 3 additions & 0 deletions docs/src/api/solver_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ FullResidual

FullResidualRecipe

LSgradient

LSgradientRecipe
```

## Exported Functions
Expand Down
8 changes: 8 additions & 0 deletions docs/src/api/solvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ SolverRecipe

## Solver Structures
```@docs
col_projection

col_projectionRecipe

Kaczmarz

KaczmarzRecipe
Expand All @@ -26,6 +30,10 @@ rsolve!

## Internal Functions
```@docs
RLinearAlgebra.col_proj_update!

RLinearAlgebra.col_proj_update_block!

RLinearAlgebra.kaczmarz_update!

RLinearAlgebra.kaczmarz_update_block!
Expand Down
2 changes: 2 additions & 0 deletions src/RLinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export Uniform, UniformRecipe
export Solver, SolverRecipe
export Kaczmarz, KaczmarzRecipe
export complete_solver, update_solver!, rsolve!
export col_projection, col_projectionRecipe

# Export Logger types and functions
export Logger, LoggerRecipe
Expand All @@ -54,6 +55,7 @@ export QRSolver, QRSolverRecipe
export SolverError, SolverErrorRecipe
export complete_error, compute_error
export FullResidual, FullResidualRecipe
export LSgradient, LSgradientRecipe

# Export ApproximatorError types and functions
export ApproximatorError, ApproximatorErrorRecipe
Expand Down
1 change: 1 addition & 0 deletions src/Solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ include("Solvers/ErrorMethods.jl")
#############################
# The Solver Routine Files
############################
include("Solvers/col_projection.jl")
include("Solvers/kaczmarz.jl")
############################
# Helper functions
Expand Down
1 change: 1 addition & 0 deletions src/Solvers/ErrorMethods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ end

# Include error method files
include("ErrorMethods/full_residual.jl")
include("ErrorMethods/LSgradient.jl")
41 changes: 41 additions & 0 deletions src/Solvers/ErrorMethods/LSgradient.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
LSgradient <: SolverError

A `SolverError` structure for computing the least-squares gradient,
``\\nabla f(x) = A' (A x - b)``

# Fields
- None
"""
struct LSgradient <: SolverError end

"""
LSgradientRecipe <: SolverErrorRecipe
A `SolverErrorRecipe` structure for computing the gradient of least-squares objective.

# Fields
- `gradient::AbstractVector`, `A'r`.
"""
mutable struct LSgradientRecipe{V<:AbstractVector} <: SolverErrorRecipe
gradient::V
end

function complete_error(
error::LSgradient,
solver::Solver,
A::AbstractMatrix,
b::AbstractVector
)
gradient = zeros(size(A,2))
return LSgradientRecipe{typeof(b)}(gradient)
end

function compute_error(
error::LSgradientRecipe,
solver::SolverRecipe,
A::AbstractMatrix,
b::AbstractVector
)::Float64
mul!(error.gradient, A', solver.residual_vec, 1.0, 0.0) # grad = A'r
return norm(error.gradient)
end
Loading
Loading