diff --git a/test/dynare-solvers/test-2.jl b/test/dynare-solvers/test-2.jl index b90f4ad6232b6e06a7bf46046527949712f7e3aa..f6980282128702109f94fdee9faf7d8328f5adc9 100644 --- a/test/dynare-solvers/test-2.jl +++ b/test/dynare-solvers/test-2.jl @@ -1,7 +1,7 @@ #= -** This script performs tests for the trust region nonlinear solver. +** This script performs tests for the trust region nonlinear solver. ** -** Copyright (C) 2018 Dynare Team +** Copyright © 2018, 2019 Dynare Team ** ** This file is part of Dynare. ** @@ -30,62 +30,135 @@ using TestFunctions cd("$(rootdir)") -@testset "test trust-region-solver" begin - @test begin - x, info = trustregion(rosenbrock!, rosenbrock!, rosenbrock(), 1.0e-6, 1.0e-6, 50) - info==1 +ntries = 1 +n = 10 + +@time @testset "test trust-region-solver" begin + factor = 1.0 + xguess = rosenbrock() + for i=ntries + @test begin + x, info = trustregion(rosenbrock!, rosenbrock!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(powell1!, powell1!, powell1(), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = powell1() + for i=ntries + @test begin + x, info = trustregion(powell1!, powell1!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(powell2!, powell2!, powell2(), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = powell2() + for i=1:ntries + @test begin + x, info = trustregion(powell2!, powell2!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(wood!, wood!, wood(), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = wood() + for i=1:ntries + @test begin + x, info = trustregion(wood!, wood!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(helicalvalley!, helicalvalley!, helicalvalley(), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = helicalvalley() + for i=1:ntries + @test begin + x, info = trustregion(helicalvalley!, helicalvalley!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(watson!, watson!, watson(10), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = watson(n) + for i=1:ntries + @test begin + x, info = trustregion(watson!, watson!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(chebyquad!, chebyquad!, chebyquad(10), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = chebyquad(n) + for i=1:ntries + @test begin + x, info = trustregion(chebyquad!, chebyquad!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(brown!, brown!, brown(10), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = brown(n) + for i=1:ntries + @test begin + x, info = trustregion(brown!, brown!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(discreteboundaryvalue!, discreteboundaryvalue!, discreteboundaryvalue(10), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = discreteboundaryvalue(n) + for i=1:ntries + @test begin + x, info = trustregion(discreteboundaryvalue!, discreteboundaryvalue!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(discreteintegralequation!, discreteintegralequation!, discreteintegralequation(10), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = discreteintegralequation(n) + for i=1:ntries + @test begin + x, info = trustregion(discreteintegralequation!, discreteintegralequation!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(trigonometric!, trigonometric!, trigonometric(10), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = trigonometric(n) + for i=1:ntries + @test begin + x, info = trustregion(trigonometric!, trigonometric!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(variablydimensioned!, variablydimensioned!, variablydimensioned(10), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = variablydimensioned(n) + for i=1:ntries + @test begin + x, info = trustregion(variablydimensioned!, variablydimensioned!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(broydentridiagonal!, broydentridiagonal!, broydentridiagonal(10), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = broydentridiagonal(n) + for i=1:ntries + @test begin + x, info = trustregion(broydentridiagonal!, broydentridiagonal!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end - @test begin - x, info = trustregion(broydenbanded!, broydenbanded!, broydenbanded(10), 1.0e-6, 1.0e-6, 50) - info==1 + factor = 1.0 + xguess = broydenbanded(n) + for i=1:ntries + @test begin + x, info = trustregion(broydenbanded!, broydenbanded!, factor*xguess, 1.0e-6, 1.0e-6, 50*n) + info==1 + end + factor *= 2.0 end end