Skip to content

Instantly share code, notes, and snippets.

@AndyGreenwell
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndyGreenwell/5be0cd5fa67d79990e36 to your computer and use it in GitHub Desktop.
Save AndyGreenwell/5be0cd5fa67d79990e36 to your computer and use it in GitHub Desktop.
Test case for triggering "ERROR: UndefVarError: Error not defined" in secant2! of hz_linesearch.jl
module OptimTest
using Optim, Hadamard
function symcond(n,κ)
Q = hadamard(n)
D = diagm(exp(linspace(0,-log(κ),n)));
Q*D*Q'/n
end
A = symcond(12,1e14)
temp = 1.0 + 1e-14*rand()
function c(x)
c = dot(x,A*x)/2
#println("No op")
end
function g!(x,grad::Vector)
grad[:] = (A*x).*temp
#println("No op")
end
function cg!(x,grad::Vector)
#A = symcond(12,1e14)
c = dot(x,A*x)/2 # cost function
#temp = 1.0 + 1e-14*rand()
#println("temp = $temp")
grad[:] = (A*x).*temp # gradient
return c
end
function driver()
df = DifferentiableFunction(c,g!,cg!)
inputvec = randn(12)
println("inputvec = $inputvec")
@time optim_output = Optim.optimize(df, inputvec, method = :l_bfgs, iterations = 10000, ftol=1e-6, grtol=1e-12, show_trace = false)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment