This section aims to investigate the effect of sample size.
using MonotoneDecomposition
using Plots
using LinearAlgebra
using Random
With Cubic B-splines (fitJ
)
seed = 16
ns = [20, 50, 100, 200, 500]
Err1 = Float64[]
Err2 = Float64[]
μs = 10.0 .^ (-6:0.05:0)
for n in ns
Random.seed!(16)
x, y, x0, y0 = gen_data(n, 0.5, "SE_1");
D, μmin, errs, σerrs = cv_mono_decomp_cs(x, y, ss = μs,
fixJ = true, x0 = x0,
figname = "cvspl_n$n.png",
nfold = 10, nfold_pre = 10);
yhat, yhatnew = cubic_spline(D.workspace.J)(x, y, x0);
yup, ydown = predict(D.workspace, x0, D.γup, D.γdown)
e1 = norm(yup + ydown - y0)^2 / length(y0)
e2 = norm(yhatnew - y0)^2 / length(y0)
append!(Err1, e1)
append!(Err2, e2)
end
[ Info: σ = 0.5, resulting SNR = 0.3504335610557286
[ Info: σ = 0.5, resulting SNR = 6.7227495562901876
[ Info: σ = 0.5, resulting SNR = 0.8134045943613267
[ Info: σ = 0.5, resulting SNR = 0.8841583906720639
[ Info: σ = 0.5, resulting SNR = 1.8059030143989558
Plot the results
plot(ns, Err1, label = "MDCS", markershape = :circle, xlab = "sample size n", ylab = "Err")
plot!(ns, Err2, label = "CS", markershape = :rect)