292 lines
9.1 KiB
Plaintext
Generated
292 lines
9.1 KiB
Plaintext
Generated
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "7b26750c-46f3-4650-aad9-759312cb7486",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"include(\"../../L-BFGS/OracleFunction.jl\")\n",
|
|
"include(\"../../L-BFGS/LBFGS.jl\")\n",
|
|
"include(\"../../utilities/genFunc.jl\")\n",
|
|
"using .LBFGS\n",
|
|
"using .OracleFunction\n",
|
|
"using LinearAlgebra, BenchmarkTools, CSV, DataFrames\n",
|
|
"\n",
|
|
"baseDir = joinpath(\"../\", \"results/LBFGS/3D/\")\n",
|
|
"mkpath(baseDir);"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "468b2db2",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 3D PLOTS"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "f96101fb-0029-48c9-b5f0-4b9b9f45feb6",
|
|
"metadata": {
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"### time with respect to lambda and epsilon\n",
|
|
"\n",
|
|
"# parameters\n",
|
|
"lambdas = 10. .^(-15:6)\n",
|
|
"epss = 10. .^(-15:-6)\n",
|
|
"memsize = 7\n",
|
|
"m = 300\n",
|
|
"n = 20\n",
|
|
"\n",
|
|
"\n",
|
|
"# output csv\n",
|
|
"outputvsc = joinpath(baseDir, \"statisticsLBFGS-lambda-eps-m\" * string(m) * \"n\" * string(n) * \"--time.csv\");\n",
|
|
"accData = Dict(\n",
|
|
" :lambda => Array{Float64}(undef, 0),\n",
|
|
" :epsilon => Array{Float64}(undef, 0),\n",
|
|
" :memsize => Array{Int64}(undef, 0),\n",
|
|
" :meantime => Array{Float64}(undef, 0),\n",
|
|
" :stdtime => Array{Float64}(undef, 0)\n",
|
|
" )\n",
|
|
"\n",
|
|
"# computation\n",
|
|
"for (λ, ϵ) ∈ Iterators.product(lambdas, epss) |> collect\n",
|
|
" ls = genFunc(:exactRandDataset, λ=λ, m=m, n=n) |> LeastSquaresF\n",
|
|
"\n",
|
|
" t = @benchmark begin\n",
|
|
" _ = LimitedMemoryBFGS($ls, ϵ=$ϵ, m=memsize)\n",
|
|
" end samples=10 evals=1\n",
|
|
"\n",
|
|
" push!(accData[:lambda], λ)\n",
|
|
" push!(accData[:epsilon], ϵ)\n",
|
|
" push!(accData[:memsize], memsize)\n",
|
|
" push!(accData[:meantime], mean(t.times))\n",
|
|
" push!(accData[:stdtime], std(t.times))\n",
|
|
" println(\"Done: λ \" * string(λ) * \" - ϵ \" * string(ϵ))\n",
|
|
" flush(stdout)\n",
|
|
"end\n",
|
|
"\n",
|
|
"CSV.write(outputvsc, DataFrame(accData));"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5b36db4f-2659-4591-8640-cd5071788f67",
|
|
"metadata": {
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"### iterations with respect to lambda and epsilon\n",
|
|
"\n",
|
|
"# parameters\n",
|
|
"lambdas = 10. .^(-15:6)\n",
|
|
"epss = 10. .^(-15:-6)\n",
|
|
"memsize = 7\n",
|
|
"maxIter = 10000\n",
|
|
"m = 300\n",
|
|
"n = 20\n",
|
|
"\n",
|
|
"\n",
|
|
"# output csv\n",
|
|
"outputvsc = joinpath(baseDir, \"statisticsLBFGS-lambda-eps-m\" * string(m) * \"n\" * string(n) * \"--iterations.csv\");\n",
|
|
"accData = Dict(\n",
|
|
" :lambda => Array{Float64}(undef, 0),\n",
|
|
" :epsilon => Array{Float64}(undef, 0),\n",
|
|
" :memsize => Array{Int64}(undef, 0),\n",
|
|
" :iterations => Array{Int64}(undef, 0)\n",
|
|
" )\n",
|
|
"\n",
|
|
"# computation\n",
|
|
"for (λ, ϵ) ∈ Iterators.product(lambdas, epss) |> collect\n",
|
|
" ls = genFunc(:exactRandDataset, λ=λ, m=m, n=n) |> LeastSquaresF\n",
|
|
"\n",
|
|
" t = maxIter - LimitedMemoryBFGS(ls, ϵ=ϵ, MaxEvaluations=maxIter, m=memsize)[:RemainingEvaluations]\n",
|
|
"\n",
|
|
" push!(accData[:lambda], λ)\n",
|
|
" push!(accData[:epsilon], ϵ)\n",
|
|
" push!(accData[:memsize], memsize)\n",
|
|
" push!(accData[:iterations], t)\n",
|
|
" println(\"Done: λ \" * string(λ) * \" - ϵ \" * string(ϵ))\n",
|
|
" flush(stdout)\n",
|
|
"end\n",
|
|
"\n",
|
|
"CSV.write(outputvsc, DataFrame(accData));"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "f3bb9382-8e68-49aa-81ac-6e3e3fcdf85b",
|
|
"metadata": {
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"### error with respect to lambda and epsilon\n",
|
|
"\n",
|
|
"# parameters\n",
|
|
"lambdas = 10. .^(-15:6)\n",
|
|
"epss = 10. .^(-15:-6)\n",
|
|
"memsize = 7\n",
|
|
"maxIter = 10000\n",
|
|
"m = 300\n",
|
|
"n = 20\n",
|
|
"\n",
|
|
"\n",
|
|
"# output csv\n",
|
|
"outputvsc = joinpath(baseDir, \"statisticsLBFGS-lambda-eps-m\" * string(m) * \"n\" * string(n) * \"--error.csv\");\n",
|
|
"accData = Dict(\n",
|
|
" :lambda => Array{Float64}(undef, 0),\n",
|
|
" :epsilon => Array{Float64}(undef, 0),\n",
|
|
" :memsize => Array{Int64}(undef, 0),\n",
|
|
" :relative => Array{Float64}(undef, 0),\n",
|
|
" :residual => Array{Float64}(undef, 0)\n",
|
|
" )\n",
|
|
"\n",
|
|
"# computation\n",
|
|
"for (λ, ϵ) ∈ Iterators.product(lambdas, epss) |> collect\n",
|
|
" gf = genFunc(:exactRandDataset, λ=λ, m=m, n=n)\n",
|
|
" ls = LeastSquaresF(gf)\n",
|
|
"\n",
|
|
" t = LimitedMemoryBFGS(ls, ϵ=ϵ, MaxEvaluations=maxIter, m=memsize)\n",
|
|
"\n",
|
|
" relative_error = norm(t[:x] - gf[:w_star]) / norm(gf[:w_star])\n",
|
|
" residual = norm(gf[:X_hat] * t[:x] - gf[:y_hat]) / norm(gf[:y_hat])\n",
|
|
"\n",
|
|
" push!(accData[:lambda], λ)\n",
|
|
" push!(accData[:epsilon], ϵ)\n",
|
|
" push!(accData[:memsize], memsize)\n",
|
|
" push!(accData[:relative], relative_error)\n",
|
|
" push!(accData[:residual], residual)\n",
|
|
" println(\"Done: λ \" * string(λ) * \" - ϵ \" * string(ϵ))\n",
|
|
" flush(stdout)\n",
|
|
"end\n",
|
|
"\n",
|
|
"CSV.write(outputvsc, DataFrame(accData));"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "cff97997-96a4-4223-bed9-00663a9a2a6c",
|
|
"metadata": {
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"### iterations with respect to epsilon and memory size\n",
|
|
"\n",
|
|
"# parameters\n",
|
|
"λ = 10^-3\n",
|
|
"epss = 10. .^(-15:-6)\n",
|
|
"memsizes = [1, 3, 5, 7, 9, 11, 15, 20, 40, 60]\n",
|
|
"maxIter = 10000\n",
|
|
"m = 300\n",
|
|
"n = 20\n",
|
|
"\n",
|
|
"\n",
|
|
"# output csv\n",
|
|
"outputvsc = joinpath(baseDir, \"statisticsLBFGS-eps-mem-m\" * string(m) * \"n\" * string(n) * \"--iterations.csv\");\n",
|
|
"accData = Dict(\n",
|
|
" :lambda => Array{Float64}(undef, 0),\n",
|
|
" :epsilon => Array{Float64}(undef, 0),\n",
|
|
" :memsize => Array{Int64}(undef, 0),\n",
|
|
" :iterations => Array{Int64}(undef, 0)\n",
|
|
" )\n",
|
|
"\n",
|
|
"# computation\n",
|
|
"for (ϵ, memsize) ∈ Iterators.product(epss, memsizes) |> collect\n",
|
|
" gf = genFunc(:exactRandDataset, λ=λ, m=m, n=n)\n",
|
|
" ls = LeastSquaresF(gf)\n",
|
|
"\n",
|
|
" t = maxIter - LimitedMemoryBFGS(ls, ϵ=ϵ, MaxEvaluations=maxIter, m=memsize)[:RemainingEvaluations]\n",
|
|
"\n",
|
|
" push!(accData[:lambda], λ)\n",
|
|
" push!(accData[:epsilon], ϵ)\n",
|
|
" push!(accData[:memsize], memsize)\n",
|
|
" push!(accData[:iterations], t)\n",
|
|
" println(\"Done: mem \" * string(memsize) * \" - ϵ \" * string(ϵ))\n",
|
|
" flush(stdout)\n",
|
|
"end\n",
|
|
"\n",
|
|
"CSV.write(outputvsc, DataFrame(accData));"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "65a5b24b-ad25-4f13-8ebc-433e5e91eb75",
|
|
"metadata": {
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"### error with respect to epsilon and memory size\n",
|
|
"\n",
|
|
"# parameters\n",
|
|
"λ = 10^-3\n",
|
|
"epss = 10. .^(-15:-6)\n",
|
|
"memsizes = [1, 3, 5, 7, 9, 11, 15, 20, 40, 60]\n",
|
|
"maxIter = 10000\n",
|
|
"m = 300\n",
|
|
"n = 20\n",
|
|
"\n",
|
|
"\n",
|
|
"# output csv\n",
|
|
"outputvsc = joinpath(baseDir, \"statisticsLBFGS-eps-mem-m\" * string(m) * \"n\" * string(n) * \"--error.csv\");\n",
|
|
"accData = Dict(\n",
|
|
" :lambda => Array{Float64}(undef, 0),\n",
|
|
" :epsilon => Array{Float64}(undef, 0),\n",
|
|
" :memsize => Array{Int64}(undef, 0),\n",
|
|
" :relative => Array{Float64}(undef, 0),\n",
|
|
" :residual => Array{Float64}(undef, 0)\n",
|
|
" )\n",
|
|
"\n",
|
|
"# computation\n",
|
|
"for (ϵ, memsize) ∈ Iterators.product(epss, memsizes) |> collect\n",
|
|
" gf = genFunc(:exactRandDataset, λ=λ, m=m, n=n)\n",
|
|
" ls = LeastSquaresF(gf)\n",
|
|
"\n",
|
|
" t = LimitedMemoryBFGS(ls, ϵ=ϵ, MaxEvaluations=maxIter, m=memsize)\n",
|
|
"\n",
|
|
" relative_error = norm(t[:x] - gf[:w_star]) / norm(gf[:w_star])\n",
|
|
" residual = norm(gf[:X_hat] * t[:x] - gf[:y_hat]) / norm(gf[:y_hat])\n",
|
|
"\n",
|
|
" push!(accData[:lambda], λ)\n",
|
|
" push!(accData[:epsilon], ϵ)\n",
|
|
" push!(accData[:memsize], memsize)\n",
|
|
" push!(accData[:relative], relative_error)\n",
|
|
" push!(accData[:residual], residual)\n",
|
|
" println(\"Done: mem \" * string(memsize) * \" - ϵ \" * string(ϵ))\n",
|
|
" flush(stdout)\n",
|
|
"end\n",
|
|
"\n",
|
|
"CSV.write(outputvsc, DataFrame(accData));"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Julia 1.9.3",
|
|
"language": "julia",
|
|
"name": "julia-1.9"
|
|
},
|
|
"language_info": {
|
|
"file_extension": ".jl",
|
|
"mimetype": "application/julia",
|
|
"name": "julia",
|
|
"version": "1.9.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|