6

我需要在 Julia 中找到多变量函数的不动点。

考虑以下最小示例:

function example(p::Array{Float64,1})
    q = -p
    return q
end

理想情况下,我会使用像 Roots.jl 和 call 这样的包find_zeros(p -> p - example(p)),但我找不到用于多变量函数的类似包。我找到了一个叫IntervalRootFinding,但奇怪的是它需要 unicode 字符并且文档很少,所以我不知道如何使用它。

4

2 回答 2

8

有很多选择。最好的选择取决于example功能的性质(您必须了解example功能的性质并检查特定包的文档是否支持它)。

例如。您可以fixedpoint从 NLsolve.jl 使用:

julia> using NLsolve

julia> function example!(q, p::Array{Float64,1})
           q .= -p
       end
example! (generic function with 1 method)

julia> fixedpoint(example!, ones(1))
Results of Nonlinear Solver Algorithm
 * Algorithm: Anderson m=1 beta=1 aa_start=1 droptol=0
 * Starting Point: [1.0]
 * Zero: [0.0]
 * Inf-norm of residuals: 0.000000
 * Iterations: 3
 * Convergence: true
   * |x - x'| < 0.0e+00: true
   * |f(x)| < 1.0e-08: true
 * Function Calls (f): 3
 * Jacobian Calls (df/dx): 0

julia> fixedpoint(example!, ones(3))
Results of Nonlinear Solver Algorithm
 * Algorithm: Anderson m=3 beta=1 aa_start=1 droptol=0
 * Starting Point: [1.0, 1.0, 1.0]
 * Zero: [-2.220446049250313e-16, -2.220446049250313e-16, -2.220446049250313e-16]
 * Inf-norm of residuals: 0.000000
 * Iterations: 3
 * Convergence: true
   * |x - x'| < 0.0e+00: false
   * |f(x)| < 1.0e-08: true
 * Function Calls (f): 3
 * Jacobian Calls (df/dx): 0

julia> fixedpoint(example!, ones(5))
Results of Nonlinear Solver Algorithm
 * Algorithm: Anderson m=5 beta=1 aa_start=1 droptol=0
 * Starting Point: [1.0, 1.0, 1.0, 1.0, 1.0]
 * Zero: [0.0, 0.0, 0.0, 0.0, 0.0]
 * Inf-norm of residuals: 0.000000
 * Iterations: 3
 * Convergence: true
   * |x - x'| < 0.0e+00: true
   * |f(x)| < 1.0e-08: true
 * Function Calls (f): 3
 * Jacobian Calls (df/dx): 0

如果您的函数需要全局优化工具来找到一个固定点,那么您可以使用 BlackBoxOptim.jlnorm(f(x) .-x)作为目标:

julia> using LinearAlgebra

julia> using BlackBoxOptim

julia> function example(p::Array{Float64,1})
           q = -p
           return q
       end
example (generic function with 1 method)

julia> f(x) = norm(example(x) .- x)
f (generic function with 1 method)

julia> bboptimize(f; SearchRange = (-5.0, 5.0), NumDimensions = 1)
Starting optimization with optimizer DiffEvoOpt{FitPopulation{Float64},RadiusLimitedSelector,BlackBoxOptim.AdaptiveDiffEvoRandBin{3},RandomBound{ContinuousRectSearchSpace}}
0.00 secs, 0 evals, 0 steps

Optimization stopped after 10001 steps and 0.15 seconds
Termination reason: Max number of steps (10000) reached
Steps per second = 68972.31
Function evals per second = 69717.14
Improvements/step = 0.35090
Total function evaluations = 10109


Best candidate found: [-8.76093e-40]

Fitness: 0.000000000

julia> bboptimize(f; SearchRange = (-5.0, 5.0), NumDimensions = 3);
Starting optimization with optimizer DiffEvoOpt{FitPopulation{Float64},RadiusLimitedSelector,BlackBoxOptim.AdaptiveDiffEvoRandBin{3},RandomBound{ContinuousRectSearchSpace}}
0.00 secs, 0 evals, 0 steps

Optimization stopped after 10001 steps and 0.02 seconds
Termination reason: Max number of steps (10000) reached
Steps per second = 625061.23
Function evals per second = 631498.72
Improvements/step = 0.32330
Total function evaluations = 10104


Best candidate found: [-3.00106e-12, -5.33545e-12, 5.39072e-13]

Fitness: 0.000000000


julia> bboptimize(f; SearchRange = (-5.0, 5.0), NumDimensions = 5);
Starting optimization with optimizer DiffEvoOpt{FitPopulation{Float64},RadiusLimitedSelector,BlackBoxOptim.AdaptiveDiffEvoRandBin{3},RandomBound{ContinuousRectSearchSpace}}
0.00 secs, 0 evals, 0 steps

Optimization stopped after 10001 steps and 0.02 seconds
Termination reason: Max number of steps (10000) reached
Steps per second = 526366.94
Function evals per second = 530945.88
Improvements/step = 0.29900
Total function evaluations = 10088


Best candidate found: [-9.23635e-8, -2.6889e-8, -2.93044e-8, -1.62639e-7, 3.99672e-8]

Fitness: 0.000000391
于 2019-10-11T21:12:13.243 回答
1

我是 IntervalRootFinding.jl 的作者。我很高兴地说,文档最近改进了很多,不需要 unicode 字符。我建议使用主分支。

以下是如何使用包解决您的示例。请注意,这个包应该能够找到一个盒子中的所有根,并保证它已经找到了所有的根。你的只有1个:

julia> using IntervalArithmetic, IntervalRootFinding

julia> function example(p)
           q = -p
           return q
       end
example (generic function with 2 methods)

julia> X = IntervalBox(-2..2, 2)
[-2, 2] × [-2, 2]

julia> roots(x -> example(x) - x, X, Krawczyk)
1-element Array{Root{IntervalBox{2,Float64}},1}:
 Root([0, 0] × [0, 0], :unique)

有关更多信息,我建议查看https://discourse.julialang.org/t/ann-intervalrootfinding-jl-for-finding-all-roots-of-a-multivariate-function/9515

于 2019-10-15T01:07:52.870 回答