ConvexFit.Cache
— MethodCache(A::AbstractMatrix)
Allocate arrays for the solver based on the size of A
.
ConvexFit.GridSearch
— TypeGridSearch{TF<:AbstractFloat} <: ModelSelection
Exhaustively assess all parameters on a specified grid. See also grid
.
ConvexFit.GridSearchResult
— TypeGridSearchResult{TF<:AbstractFloat} <: ModelSelectionResult
Results from GridSearch
, including estimates calculated for each parameter on the grid.
Fields
iopt::Int
: index of the optimal parameter.loocv::Vector{TF}
: leave-one-out cross validation errors.
ConvexFit.ModelSelection
— TypeModelSelection
Supertype for all methods used for generating alternative models.
ConvexFit.ModelSelectionResult
— TypeModelSelectionResult
Supertype for all results from model selection.
ConvexFit.OptimSearch
— TypeOptimSearch <: ModelSelection
Search the optimal regularization parameter with a user-specified function. See also optim
.
ConvexFit.convexfit
— Functionconvexfit(A::AbstractMatrix, B::AbstractVecOrMat, λ=0; multithreads=false, kwargs...)
A wrapper method of convexfit
that accepts multiple b
s in a matrix B
and fits each column in B
with a convex combination of the columns in matrix A
. The actual problems to be solved depend on the type of λ
. Results are collected in an array in the order of the columns of B
.
Problems across different columns can be solved simultaneously by setting multithreads=true
. See also convexfit(::Matrix,::Vector,::Real)
.
Setting multithreads=true
requires at least Julia 1.2.
ConvexFit.convexfit
— Functionconvexfit(A::AbstractMatrix, λ=0; loo=true, multithreads=false, kwargs...)
A wrapper method of convexfit
for fitting each column in matrix A
with a convex combination of the other columns in matrix A
. The actual problems to be solved depend on the type of λ
. Results are collected in an array in the order of the columns of B
.
By default, with loo=true
the fitted column is not involved in the convex combination. This can be altered by setting loo=false
. Problems across different columns can be solved simultaneously by setting multithreads=true
. See also convexfit(::Matrix,::Vector,::Real)
.
Setting multithreads=true
requires at least Julia 1.2.
ConvexFit.convexfit
— Methodconvexfit(A::Matrix, b::Vector, λs::ModelSelection; looargs, kwargs...)
Select the optimal regularization parameter λ
based on leave-one-out cross validation with the method specified with λs
and fit vector b
with a convex combination of the columns in matrix A
. Return a tuple of two objects, the result of fitting b
and the result of selecting λ
. See also grid
, optim
and loocv
.
All keyword arguments for convexfit(::Matrix,::Vector,::Real)
are accepted. Additionally, keyword arguments for loocv
can be specified with the keyword looargs
and a NamedTuple
or Dict
.
ConvexFit.convexfit
— Methodconvexfit(A::Matrix, b::Vector, λ::Real=0; kwargs...)
Fit vector b
with a convex combination of the columns in matrix A
and an optional regularization parameter λ
.
The associated constrained optimization problem can be expressed as follows:
\[\min_x \|Ax - b\|_2^2 + λ\|x\|_2^2 \\ st. x_i ≥ 0 \forall i, \, \sum_i x_i = 1\]
where x
is the vector of coefficients to be solved.
Keywords
x0::AbstractVector{<:Real}=fill(1/size(A,2),1/size(A,2))
: initial value ofx
.ftol::Real=1e-6
: convergence criterion based on the change in the objective function.xtol::Real=1e-6
: convergence criterion based on the inf-norm change inx
.maxiter::Integer=1000
: maximum number of iterations.store_trace::Bool=false
: save the solver state in each iteration.show_trace::Bool=false
: print the solver state in each iteration tostdout
.show_thread::Bool=false
: show the thread ID when printing solver states.cache::Cache=Cache(A)
:Cache
that stores intermediate results.
ConvexFit.grid
— Methodgrid([v])
Specify the grid vector v
used for GridSearch
. If v
is not provided, a default grid is used.
ConvexFit.loocv
— Methodloocv(A::Matrix, b::Vector, λ::Real; kwargs...)
Return the leave-one-out cross validation error for fitting vector b
with a convex combination of columns in matrix A
when the regularization parameter is set to be λ
.
The same set of keyword arguments for convexfit(::Matrix,::Vector,::Real)
are accepted.
ConvexFit.optim
— Methodoptim(f::Function)
Specify the function used for searching the optimal regularization parameter. See also OptimSearch
.
Function f
accepts a univariate objective function associated with the minimization problem to be solved and returns a tuple of two objects, the solver result and the minimizer of the problem. The objective function will be generated by convexfit
and passed to f
for selecting the optimal regularization parameter.
ConvexFit.@fieldequal
— Macro@fieldequal Supertype
Define a method of ==
for all subtypes of Supertype
such that ==
returns true if each pair of the field values from two instances are equal by ==
.