Skip to content

Commit

Permalink
deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Creel committed Jan 21, 2024
1 parent 0c9a2b5 commit ad1eefb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
54 changes: 30 additions & 24 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
version = "0.4.7"

[[deps.BSON]]
git-tree-sha1 = "2208958832d6e1b59e49f53697483a84ca8d664e"
git-tree-sha1 = "5fa6520e45c7b839ef9af18be94313971f9f2ff9"
uuid = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
version = "0.3.7"
version = "0.3.8"

[[deps.BangBang]]
deps = ["Compat", "ConstructionBase", "InitialValues", "LinearAlgebra", "Requires", "Setfield", "Tables"]
Expand Down Expand Up @@ -334,9 +334,9 @@ version = "0.3.2"

[[deps.Clustering]]
deps = ["Distances", "LinearAlgebra", "NearestNeighbors", "Printf", "Random", "SparseArrays", "Statistics", "StatsBase"]
git-tree-sha1 = "407f38961ac11a6e14b2df7095a2577f7cb7cb1b"
git-tree-sha1 = "9ebb045901e9bbf58767a9f34ff89831ed711aae"
uuid = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
version = "0.15.6"
version = "0.15.7"

[[deps.CodeTracking]]
deps = ["InteractiveUtils", "UUIDs"]
Expand Down Expand Up @@ -675,9 +675,9 @@ version = "4.4.4+1"

[[deps.FFTW]]
deps = ["AbstractFFTs", "FFTW_jll", "LinearAlgebra", "MKL_jll", "Preferences", "Reexport"]
git-tree-sha1 = "ec22cbbcd01cba8f41eecd7d44aac1f23ee985e3"
git-tree-sha1 = "4820348781ae578893311153d69049a93d05f39d"
uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
version = "1.7.2"
version = "1.8.0"

[[deps.FFTW_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
Expand Down Expand Up @@ -1375,10 +1375,10 @@ deps = ["Libdl", "OpenBLAS_jll", "libblastrampoline_jll"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[deps.LinearAlgebraX]]
deps = ["LinearAlgebra", "Mods", "Permutations", "Primes", "SimplePolynomials"]
git-tree-sha1 = "1cb349a6a7656c2cbe2d288baabe863a208e46e3"
deps = ["LinearAlgebra", "Mods", "Primes", "SimplePolynomials"]
git-tree-sha1 = "d76cec8007ec123c2b681269d40f94b053473fcf"
uuid = "9b3f67b0-2d00-526e-9884-9e4938f8fb88"
version = "0.2.6"
version = "0.2.7"

[[deps.LogDensityProblems]]
deps = ["ArgCheck", "DocStringExtensions", "Random"]
Expand Down Expand Up @@ -1806,15 +1806,21 @@ version = "2.8.1"

[[deps.Permutations]]
deps = ["Combinatorics", "LinearAlgebra", "Random"]
git-tree-sha1 = "c7745750b8a829bc6039b7f1f0981bcda526a946"
git-tree-sha1 = "eb3f9df2457819bf0a9019bd93cc451697a0751e"
uuid = "2ae35dd2-176d-5d53-8349-f30d82d94d4f"
version = "0.4.19"
version = "0.4.20"

[[deps.PiecewiseLinearApprox]]
git-tree-sha1 = "1238a253b8577b9482239eb4efdd07161cc77685"
uuid = "fcfa6960-8e2e-11e9-2cde-29dd09221fb3"
version = "0.1.10"

[[deps.PikaParser]]
deps = ["DocStringExtensions"]
git-tree-sha1 = "d6ff87de27ff3082131f31a714d25ab6d0a88abf"
uuid = "3bbf5609-3e7b-44cd-8549-7c69f321e792"
version = "0.6.1"

[[deps.Pipe]]
git-tree-sha1 = "6842804e7867b115ca9de748a0cf6b364523c16d"
uuid = "b98c9c47-44ae-5843-9183-064241ee97a0"
Expand Down Expand Up @@ -2022,9 +2028,9 @@ version = "0.6.12"

[[deps.RecursiveArrayTools]]
deps = ["Adapt", "ArrayInterface", "DocStringExtensions", "GPUArraysCore", "IteratorInterfaceExtensions", "LinearAlgebra", "RecipesBase", "SparseArrays", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables"]
git-tree-sha1 = "720e17f568661f7c1d9ce8df20c75b544b22e249"
git-tree-sha1 = "dd7fc1923fde0cc6cdff451352d17924b0704ca1"
uuid = "731186ca-8d62-57ce-b412-fbd966d074cd"
version = "3.5.3"
version = "3.5.4"

[deps.RecursiveArrayTools.extensions]
RecursiveArrayToolsFastBroadcastExt = "FastBroadcast"
Expand Down Expand Up @@ -2116,9 +2122,9 @@ version = "0.7.0"

[[deps.SciMLBase]]
deps = ["ADTypes", "ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "EnumX", "FillArrays", "FunctionWrappersWrappers", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "Markdown", "PrecompileTools", "Preferences", "Printf", "RecipesBase", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLOperators", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables", "TruncatedStacktraces"]
git-tree-sha1 = "ad711463cb386572f33f6209464d8dca5a081247"
git-tree-sha1 = "de41474ac529bf81598e064587421cc5ebc28fa0"
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
version = "2.19.0"
version = "2.20.0"

[deps.SciMLBase.extensions]
SciMLBaseChainRulesCoreExt = "ChainRulesCore"
Expand Down Expand Up @@ -2302,10 +2308,10 @@ uuid = "171d559e-b47b-412a-8079-5efa626c420e"
version = "0.1.15"

[[deps.StableHashTraits]]
deps = ["Compat", "SHA", "Tables", "TupleTools"]
git-tree-sha1 = "6fc838a7713795681907a7e749d72d12a81a43ea"
deps = ["Compat", "PikaParser", "SHA", "Tables", "TupleTools"]
git-tree-sha1 = "662f56ffe22b3985f3be7474f0aecbaf214ecf0f"
uuid = "c5dd0088-6c3f-4803-b00e-f31a60c170fa"
version = "1.1.4"
version = "1.1.6"

[[deps.StackViews]]
deps = ["OffsetArrays"]
Expand Down Expand Up @@ -2383,9 +2389,9 @@ version = "0.3.4"

[[deps.StructArrays]]
deps = ["Adapt", "ConstructionBase", "DataAPI", "GPUArraysCore", "StaticArraysCore", "Tables"]
git-tree-sha1 = "0a3db38e4cce3c54fe7a71f831cd7b6194a54213"
git-tree-sha1 = "1b0b1205a56dc288b71b1961d48e351520702e24"
uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
version = "0.6.16"
version = "0.6.17"

[[deps.SuiteSparse]]
deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"]
Expand Down Expand Up @@ -2537,9 +2543,9 @@ version = "1.4.3"

[[deps.Turing]]
deps = ["ADTypes", "AbstractMCMC", "AdvancedHMC", "AdvancedMH", "AdvancedPS", "AdvancedVI", "BangBang", "Bijectors", "DataStructures", "Distributions", "DistributionsAD", "DocStringExtensions", "DynamicPPL", "EllipticalSliceSampling", "ForwardDiff", "Libtask", "LinearAlgebra", "LogDensityProblems", "LogDensityProblemsAD", "MCMCChains", "NamedArrays", "Printf", "Random", "Reexport", "Requires", "SciMLBase", "Setfield", "SpecialFunctions", "Statistics", "StatsAPI", "StatsBase", "StatsFuns"]
git-tree-sha1 = "e0aa30e8db582b302e6bf448ab417f43b5188418"
git-tree-sha1 = "e236871c3efed84b17187ea517183b408eaaf807"
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
version = "0.30.1"
version = "0.30.2"

[deps.Turing.extensions]
TuringDynamicHMCExt = "DynamicHMC"
Expand Down Expand Up @@ -2827,9 +2833,9 @@ version = "1.5.5+0"

[[deps.Zygote]]
deps = ["AbstractFFTs", "ChainRules", "ChainRulesCore", "DiffRules", "Distributed", "FillArrays", "ForwardDiff", "GPUArrays", "GPUArraysCore", "IRTools", "InteractiveUtils", "LinearAlgebra", "LogExpFunctions", "MacroTools", "NaNMath", "PrecompileTools", "Random", "Requires", "SparseArrays", "SpecialFunctions", "Statistics", "ZygoteRules"]
git-tree-sha1 = "30c1b8bfc2b3c7c5d8bba7cd32e8b6d5f968e7c3"
git-tree-sha1 = "4ddb4470e47b0094c93055a3bcae799165cc68f1"
uuid = "e88e6eb3-aa80-5325-afca-941959d7151f"
version = "0.6.68"
version = "0.6.69"
weakdeps = ["Colors", "Distances", "Tracker"]

[deps.Zygote.extensions]
Expand Down
32 changes: 19 additions & 13 deletions PracticalSummaries/12-Optimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ f(x,y) = -(3*(1-x)^2 * exp(-(x^2) - (y+1)^2)

##
# let's explore it:
using GLMake
using GLMakie, Plots
x = range(-4, step=0.1, stop=4)
y = x
#surface(x, y, (x,y)->f(x,y),c=:viridis)
surface(x, y, (x,y)->f(x,y))
xlabel!("x")
ylabel!("y")
Makie.surface(x, y, (x,y)->f(x,y))
##
contour(x,y,(x,y)->f(x,y),c=:viridis)
Plots.contour(x,y,(x,y)->f(x,y), c=:viridis)
Plots.xlabel!("x")
Plots.ylabel!("y")

##
# This function has 3 local min, and 3 local max.
Expand Down Expand Up @@ -113,7 +112,10 @@ using Econometrics, Plots, Optim
gr() # using the GR backend
x = range(-4, step=0.1, stop=4)
y = x
contour(x,y,f,c=:viridis)
Plots.contour(x,y,f,c=:viridis)
Plots.xlabel!("x")
Plots.ylabel!("y")

θstart = 8.0 .* rand(2) .-4.0
tol = 1e-08
results = Optim.optimize(f, θstart, LBFGS(),
Expand All @@ -123,7 +125,7 @@ results = Optim.optimize(f, θstart, LBFGS(),
f_tol=tol); autodiff=:forward)

θhat = results.minimizer
scatter!([θhat[1]],[θhat[2]],legend=false, markersize=10, c = :viridis)
Plots.scatter!([θhat[1]],[θhat[2]],legend=false, markersize=10, c = :viridis)

##
# A more robust algorithm is to use the known domain to define
Expand All @@ -133,7 +135,10 @@ using Econometrics, Plots, Optim
gr() # using the GR backend
x = range(-4, step=0.1, stop=4)
y = x
contour(x,y,f, c=:viridis)
Plots.contour(x,y,f, c=:viridis)
Plots.xlabel!("x")
Plots.ylabel!("y")

lower = [-4., -4.]
upper = -lower
θstart = 8.0 .* rand(2) .-4.0
Expand All @@ -144,7 +149,7 @@ results = Optim.optimize(f, lower, upper, θstart, Fminbox(LBFGS()),
x_tol=tol,
f_tol=tol); autodiff=:forward)
θhat = results.minimizer
scatter!([θhat[1]],[θhat[2]],legend=false, markersize=10)
Plots.scatter!([θhat[1]],[θhat[2]],legend=false, markersize=10)

##
#
Expand All @@ -153,22 +158,23 @@ scatter!([θhat[1]],[θhat[2]],legend=false, markersize=10)
# Another option is to use a global optimizer. An example is the
# simulated annealing algorithm. This one should find the global
# min every time, provided the cooling schedule is slow enough
using Econometrics
using Econometrics, Plots
# try setting rt=0.05, it will fail sometimes, because the
# search region is shrunk too quickly
# rt=0.9 has worked every time I've tried it
gr() # using the GR backend
x = range(-4, step=0.1, stop=4)
y = x
contour(x,y,f, c=:viridis)
Plots.contour(x,y,f, c=:viridis)

rt = 0.9
lower = [-4., -4.]
upper = -lower
θstart = [2.0, -3.9] # a pretty bad starting point
trace = (samin(f, θstart, lower, upper, rt=rt)[4])[:,4:5]
# plot the path take to the solution (run several times to see examples)
for i = 1:size(trace,1)-1
display(scatter!([trace[i,1]], [trace[i,2]], labels=:none, color=:red, markersize=3))
display(Plots.scatter!([trace[i,1]], [trace[i,2]], labels=:none, color=:red, markersize=3))
sleep(0.05)
end
θhat = round.(trace[end,:], digits=5)
Expand Down

0 comments on commit ad1eefb

Please sign in to comment.