Guest User

Untitled

a guest
Jul 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. using Optim
  2. struct Box <: Optim.Manifold
  3. min
  4. max
  5. end
  6. import Optim.retract!
  7. import Optim.project_tangent!
  8. retract!(B::Box, x) = (x .= min.(B.max,max.(B.min, x)))
  9. function project_tangent!(B::Box,g,x)
  10. for i in eachindex(x)
  11. if x[i] == B.min[i] || x[i] == B.max[i]
  12. g[i] = 0
  13. end
  14. end
  15. end
  16.  
  17. n = 10
  18. f(x) = -sum(abs2,x)
  19. g(x) = -2x
  20. g!(stor,x) = copy!(stor,g(x))
  21. x0 = randn(n)
  22.  
  23. manif = Box(fill(-1.0, (n,)),fill(1.0, (n,)))
  24. res = Optim.optimize(f, g!, x0, Optim.GradientDescent(manifold=manif))
Add Comment
Please, Sign In to add comment