Comparing REK to QR
REK v. QR¶
In [83]:
using JLD
using PyPlot
using LinearAlgebra, Statistics
rek = include("../../../../Kaczmarz/Kaczmarz.jl")
util = include("../../../Tools/Utils.jl")
mrl = include("../../../Tools/WFMR_LS.jl")
mrk = include("../../../Tools/WFMR_kac.jl")
at = include("../../../Tools/AnalysisToolbox.jl")
Out[83]:
In [84]:
# Load Data
#This is writen to allow for loading any of 5 different runs of the KSE solution
N = 499999
geni = 1
gen = "lin1e5_r$geni" # this is just a reference designation it shows up in the
# output file. I think of generatrion.
savefile_pred = "../../../../data/KSE_Data/ks_pred_$gen.jld"
println("Sol load location: " * savefile_pred)
Pred = load(savefile_pred,"pred");
Sig = load(savefile_pred,"sig")
sig = Sig[1:1,1:N]
pred = Pred[1:1,1:N]
Out[84]:
In [85]:
M_out = 20
verb = true
vew = 1000:2000
# Form design matrix
O = @timed mrl.get_hash(pred; M_out)
Xh = O.value
verb && println("Design matrix formed. It took $(O.time) sec")
# Extract and reshape signal
Y = Array(transpose(sig[:,M_out:end]));
In [86]:
h_bs = Xh[1:5000,:] \ Y[1:5000]
Y_hat = Xh * h_bs
res = util.TakeLook(Y,Y_hat; vew)
println("MSE: ",var(res))
In [87]:
h_rek = rek.solve(Xh[1:5000,:], Y[1:5000], eps = 1e-14, maxcount = 1000, reportperiod = 60, verbose = verb).sol
Y_hat_rek = Xh * h_rek
res = util.TakeLook(Y,Y_hat_rek; vew)
println("MSE: ",var(res))
Preconditioning (Cholesky factor)¶
In [118]:
function precond(Xh,pcond;verb = true, eps = 1e-6)
M = M_out
w = I
for i = 1:pcond
σ = eps^2*var(Xh[:,M])
A = Xh'Xh/size(Xh,1) + σ*I
verb && println("preconditioning $i original condition number: ",cond(A))
L = cholesky(A).L
verb && println("preconditioning $i Cholesky condition number: ",cond(L))
W = inv(conj(L))
w = W*w
Xh = Xh*transpose(W)
verb && println("preconditioning $i new condition number: ",cond(Xh))
end
Xh, w
end
Out[118]:
In [138]:
Xhw, w = precond(Xh, 1)
h_rek, outercount, innercount = rek.solve(Xhw[1:5000,:], Y[1:5000],
eps = 1e-14, maxcount = 1000, reportperiod = 60, verbose = verb)
@show outercount
@show innercount
h_rek = transpose(w)*h_rek
Y_hat_rek = Xh * h_rek
res = util.TakeLook(Y,Y_hat_rek; vew)
println("MSE: ",var(res))
In [136]:
Xhw, w = precond(Xh, 2)
h_rek, outercount, innercount = rek.solve(Xhw[1:5000,:], Y[1:5000],
eps = 1e-14, maxcount = 10000, reportperiod = 60, verbose = verb)
@show outercount
@show innercount
h_rek = transpose(w)*h_rek
Y_hat_rek = Xh * h_rek
res = util.TakeLook(Y,Y_hat_rek; vew)
println("MSE: ",var(res))
In [139]:
Xhw, w = precond(Xh, 3)
h_rek, outercount, innercount = rek.solve(Xhw[1:5000,:], Y[1:5000],
eps = 1e-14, maxcount = 10000, reportperiod = 60, verbose = verb)
@show outercount
@show innercount
h_rek = transpose(w)*h_rek
Y_hat_rek = Xh * h_rek
res = util.TakeLook(Y,Y_hat_rek; vew)
println("MSE: ",var(res))
In [141]:
Xhw, w = precond(Xh, 3)
h_rek, outercount, innercount = rek.solve(Xhw[1:5000,:], Y[1:5000],
eps = 1e-16, maxcount = 10000, reportperiod = 60, verbose = verb)
@show outercount
@show innercount
h_rek = transpose(w)*h_rek
Y_hat_rek = Xh * h_rek
res = util.TakeLook(Y,Y_hat_rek; vew)
println("MSE: ",var(res))
In [145]:
Xhw, w = precond(Xh, 3)
h_rek, outercount, innercount = rek.solve(Xhw[1:5000,:], Y[1:5000],
eps = 1e-18, maxcount = 20000, reportperiod = 60, verbose = verb)
@show outercount
@show innercount
h_rek = transpose(w)*h_rek
Y_hat_rek = Xh * h_rek
res = util.TakeLook(Y,Y_hat_rek; vew)
println("MSE: ",var(res))
In [147]:
Xhw, w = precond(Xh, 3)
h_rek, outercount, innercount = rek.solve(Xhw[1:5000,:], Y[1:5000],
eps = 1e-20, maxcount = 200000, reportperiod = 60, verbose = verb)
@show outercount
@show innercount
h_rek = transpose(w)*h_rek
Y_hat_rek = Xh * h_rek
res = util.TakeLook(Y,Y_hat_rek; vew)
println("MSE: ",var(res))
In [ ]: