-
Notifications
You must be signed in to change notification settings - Fork 1
/
vec_row_prop_to_norm_replace.jl
54 lines (42 loc) · 1.57 KB
/
vec_row_prop_to_norm_replace.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# This file is pat of RLinearAlgebra.jl
# 1. Specifies type
# 2. Implements sample function
# 3. Exports Type
# using Random, Distributions
"""
LinSysVecRowPropToNormSampler{T} <: LinSysVecRowSampler where T <: Categorical
A parametric mutable structure that specifies sampling from the rows of the equation where
the probability of selecting a given equation is proportional to the sum of squares of the
coefficients of the given equation. The solver will appropriately initialize the
distribution.
See Strohmer, T., Vershynin, R. A Randomized Kaczmarz Algorithm with Exponential
Convergence. J Fourier Anal Appl 15, 262 (2009). https://doi.org/10.1007/s00041-008-9030-4
# Aliases
- `LinSysVecRowSVSampler`
# Fields
- `dist::T`, a categorical probability distribution.
Calling `LinSysVecRowPropToNormSampler()` or `LinSysVecRowSVSampler()` defaults `dist` to
`Categorical(1.0)`.
"""
mutable struct LinSysVecRowPropToNormSampler{T} <: LinSysVecRowSampler where T <:
Categorical
dist::T
end
LinSysVecRowSVSampler = LinSysVecRowPropToNormSampler
LinSysVecRowPropToNormSampler() = LinSysVecRowPropToNormSampler(Categorical(1.0))
# Common sample interface for linear systems
function sample(
type::LinSysVecRowSVSampler{T} where T <: Categorical,
A::AbstractArray,
b::AbstractVector,
x::AbstractVector,
iter::Int64
)
if iter == 1
prob = sum(A.^2, dims=2)[:,1]
type.dist = Categorical(prob ./ sum(prob))
end
eqn_ind = rand(type.dist)
return A[eqn_ind, :], b[eqn_ind]
end
#export LinSysVecRowPropToNormSampler, LinSysVecRowSVSampler