Created
July 17, 2018 19:46
-
-
Save antoine-levitt/95c84c3e75965913a63c9f11cef0368a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Optim | |
struct Box <: Optim.Manifold | |
min | |
max | |
end | |
import Optim.retract! | |
import Optim.project_tangent! | |
retract!(B::Box, x) = (x .= min.(B.max,max.(B.min, x))) | |
function project_tangent!(B::Box,g,x) | |
for i in eachindex(x) | |
if x[i] == B.min[i] || x[i] == B.max[i] | |
g[i] = 0 | |
end | |
end | |
end | |
n = 10 | |
f(x) = -sum(abs2,x) | |
g(x) = -2x | |
g!(stor,x) = copy!(stor,g(x)) | |
x0 = randn(n) | |
manif = Box(fill(-1.0, (n,)),fill(1.0, (n,))) | |
res = Optim.optimize(f, g!, x0, Optim.GradientDescent(manifold=manif)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment