Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bzhangcw committed Apr 16, 2024
1 parent fdfd3dc commit 01b4b50
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CUTEst = "1b53aba6-35b6-5f92-a507-53c67d53f819"
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
DRSOM = "d175e27a-564a-485c-86b6-52e0284acaa2"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
33 changes: 24 additions & 9 deletions test/convex/test_hilbert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ using LIBSVMFileIO
using DataFrames
using CSV
using SpecialMatrices
using CategoricalArrays

Base.@kwdef mutable struct KrylovInfo
normres::Float64
numops::Float64
Expand All @@ -52,7 +54,7 @@ for δ in [1e-5, 1e-7, 1e-9, 1e-10]

r = Dict()
#
r["GHM (Lanczos)"] = KrylovInfo(normres=0.0, numops=0)
r["Lanczos (GHM)"] = KrylovInfo(normres=0.0, numops=0)
r["CG"] = KrylovInfo(normres=0.0, numops=0)
r["GMRES"] = KrylovInfo(normres=0.0, numops=0)
r["rGMRES"] = KrylovInfo(normres=0.0, numops=0)
Expand All @@ -77,8 +79,8 @@ for δ in [1e-5, 1e-7, 1e-9, 1e-10]
λ₁ = rl[1]
ξ₁ = rl[2][1]

r["GHM (Lanczos)"].normres += (Fc(ξ₁) - λ₁ .* ξ₁) |> norm
r["GHM (Lanczos)"].numops += rl[end].numops
r["Lanczos (GHM)"].normres += (Fc(ξ₁) - λ₁ .* ξ₁) |> norm
r["Lanczos (GHM)"].numops += rl[end].numops

rl = KrylovKit.linsolve(
Hc, -g, w₀, CG(; tol=εₙ, maxiter=max_iteration, verbosity=3);
Expand Down Expand Up @@ -108,7 +110,7 @@ kappa = [@sprintf "%0.1e" k for k in tmat[2, :]]

df = DataFrame(
delta=[L"$\delta=$%$k" for k in delta],
kappa=[L"$\kappa_H=$%$k" for k in kappa],
kappa=["$k" for k in kappa],
method=tmat[3, :],
k=tmat[4, :],
ϵ=tmat[5, :]
Expand All @@ -123,20 +125,33 @@ print(df.set_index(["delta", "kappa", "method"]).to_latex(multirow=True, longtab
"""

using StatsPlots


function Base.unique(ctg::CategoricalArray)
l = levels(ctg)
newctg = CategoricalArray(l)
levels!(newctg, l)
end

ctg = CategoricalArray(df.method)
levels!(ctg, ["Lanczos (GHM)", "GMRES", "rGMRES", "CG"])


pgfplotsx()
fig = groupedbar(
df.method,
ctg,
convert(Vector{Float64}, df.k),
bar_position=:dodge,
group=df.kappa,
palette=:Paired_8,
# xlabel="Method",
leg=:topright,
leg=:topleft,
legendfontsize=14,
labelfontsize=14,
ylabel=L"Krylov Iterations: $K$"
ylabel=L"$K$: Krylov Iterations",
ytickfont=font(12),
xtickfont=font(12),
)

savefig(fig, "/tmp/hilbert.tex")
savefig(fig, "/tmp/hilbert.pdf")
savefig(fig, "/tmp/hilbert.png")
# savefig(fig, "/tmp/hilbert.png")

0 comments on commit 01b4b50

Please sign in to comment.