Skip to content

Commit

Permalink
Merge pull request #139 from JuliaOpt/jmw/show
Browse files Browse the repository at this point in the history
Print something readable for problems with more than two parameters
  • Loading branch information
johnmyleswhite committed Oct 13, 2015
2 parents 8ad3d9b + ac72bb1 commit b62747e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 22 deletions.
12 changes: 10 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,16 @@ end
function Base.show(io::IO, r::MultivariateOptimizationResults)
@printf io "Results of Optimization Algorithm\n"
@printf io " * Algorithm: %s\n" r.method
@printf io " * Starting Point: [%s]\n" join(r.initial_x, ",")
@printf io " * Minimum: [%s]\n" join(r.minimum, ",")
if length(join(r.initial_x, ",")) < 40
@printf io " * Starting Point: [%s]\n" join(r.initial_x, ",")
else
@printf io " * Starting Point: [%s, ...]\n" join(r.initial_x[1:2], ",")
end
if length(join(r.minimum, ",")) < 40
@printf io " * Minimum: [%s]\n" join(r.minimum, ",")
else
@printf io " * Minimum: [%s, ...]\n" join(r.minimum[1:2], ",")
end
@printf io " * Value of Function at Minimum: %f\n" r.f_minimum
@printf io " * Iterations: %d\n" r.iterations
@printf io " * Convergence: %s\n" converged(r)
Expand Down
42 changes: 22 additions & 20 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@

using Optim

my_tests = ["bfgs.jl",
"gradient_descent.jl",
"momentum_gradient_descent.jl",
"grid_search.jl",
"l_bfgs.jl",
"levenberg_marquardt.jl",
"newton.jl",
"cg.jl",
"nelder_mead.jl",
"optimize.jl",
"simulated_annealing.jl",
"interpolating_line_search.jl",
"api.jl",
"golden_section.jl",
"brent.jl",
"type_stability.jl",
"array.jl",
"constrained.jl",
"callbacks.jl"
]
my_tests = [
"types.jl",
"bfgs.jl",
"gradient_descent.jl",
"momentum_gradient_descent.jl",
"grid_search.jl",
"l_bfgs.jl",
"levenberg_marquardt.jl",
"newton.jl",
"cg.jl",
"nelder_mead.jl",
"optimize.jl",
"simulated_annealing.jl",
"interpolating_line_search.jl",
"api.jl",
"golden_section.jl",
"brent.jl",
"type_stability.jl",
"array.jl",
"constrained.jl",
"callbacks.jl",
]

println("Running tests:")

Expand Down
28 changes: 28 additions & 0 deletions test/types.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module TestTypes
using Base.Test
using Compat
using Optim

prob = Optim.UnconstrainedProblems.examples["Rosenbrock"]
f_prob = prob.f
res = Optim.nelder_mead(f_prob, prob.initial_x)

io = IOBuffer()
show(io, res)
s = takebuf_string(io)

lines = split(s, '\n')
@test lines[1] == "Results of Optimization Algorithm"
@test startswith(lines[2], " * Algorithm: ")
@test startswith(lines[3], " * Starting Point: ")
@test startswith(lines[4], " * Minimum: [")
@test startswith(lines[5], " * Value of Function at Minimum: ")
@test startswith(lines[6], " * Iterations: ")
@test startswith(lines[7], " * Convergence: ")
@test startswith(lines[8], " * |x - x'| < ")
@test startswith(lines[9], " * |f(x) - f(x')| / |f(x)| < ")
@test startswith(lines[10], " * |g(x)| < ")
@test startswith(lines[11], " * Exceeded Maximum Number of Iterations: ")
@test startswith(lines[12], " * Objective Function Calls: ")
@test startswith(lines[13], " * Gradient Call: ")
end

0 comments on commit b62747e

Please sign in to comment.