|
| 1 | +""" |
| 2 | + RobustMultiNewton( |
| 3 | + ::Type{T} = Float64; |
| 4 | + concrete_jac = nothing, |
| 5 | + linsolve = nothing, |
| 6 | + autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing |
| 7 | + ) |
| 8 | +
|
| 9 | +A polyalgorithm focused on robustness. It uses a mixture of Newton methods with different |
| 10 | +globalizing techniques (trust region updates, line searches, etc.) in order to find a |
| 11 | +method that is able to adequately solve the minimization problem. |
| 12 | +
|
| 13 | +Basically, if this algorithm fails, then "most" good ways of solving your problem fail and |
| 14 | +you may need to think about reformulating the model (either there is an issue with the model, |
| 15 | +or more precision / more stable linear solver choice is required). |
| 16 | +
|
| 17 | +### Arguments |
| 18 | +
|
| 19 | + - `T`: The eltype of the initial guess. It is only used to check if some of the algorithms |
| 20 | + are compatible with the problem type. Defaults to `Float64`. |
| 21 | +""" |
| 22 | +function RobustMultiNewton( |
| 23 | + ::Type{T} = Float64; |
| 24 | + concrete_jac = nothing, |
| 25 | + linsolve = nothing, |
| 26 | + autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing |
| 27 | +) where {T} |
| 28 | + common_kwargs = (; concrete_jac, linsolve, autodiff, vjp_autodiff, jvp_autodiff) |
| 29 | + if T <: Complex # Let's atleast have something here for complex numbers |
| 30 | + algs = ( |
| 31 | + NewtonRaphson(; common_kwargs...), |
| 32 | + ) |
| 33 | + else |
| 34 | + algs = ( |
| 35 | + TrustRegion(; common_kwargs...), |
| 36 | + TrustRegion(; common_kwargs..., radius_update_scheme = RUS.Bastin), |
| 37 | + NewtonRaphson(; common_kwargs...), |
| 38 | + NewtonRaphson(; common_kwargs..., linesearch = BackTracking()), |
| 39 | + TrustRegion(; common_kwargs..., radius_update_scheme = RUS.NLsolve), |
| 40 | + TrustRegion(; common_kwargs..., radius_update_scheme = RUS.Fan) |
| 41 | + ) |
| 42 | + end |
| 43 | + return NonlinearSolvePolyAlgorithm(algs) |
| 44 | +end |
| 45 | + |
| 46 | +""" |
| 47 | + FastShortcutNonlinearPolyalg( |
| 48 | + ::Type{T} = Float64; |
| 49 | + concrete_jac = nothing, |
| 50 | + linsolve = nothing, |
| 51 | + must_use_jacobian::Val = Val(false), |
| 52 | + prefer_simplenonlinearsolve::Val = Val(false), |
| 53 | + autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing, |
| 54 | + u0_len::Union{Int, Nothing} = nothing |
| 55 | + ) where {T} |
| 56 | +
|
| 57 | +A polyalgorithm focused on balancing speed and robustness. It first tries less robust methods |
| 58 | +for more performance and then tries more robust techniques if the faster ones fail. |
| 59 | +
|
| 60 | +### Arguments |
| 61 | +
|
| 62 | + - `T`: The eltype of the initial guess. It is only used to check if some of the algorithms |
| 63 | + are compatible with the problem type. Defaults to `Float64`. |
| 64 | +
|
| 65 | +### Keyword Arguments |
| 66 | +
|
| 67 | + - `u0_len`: The length of the initial guess. If this is `nothing`, then the length of the |
| 68 | + initial guess is not checked. If this is an integer and it is less than `25`, we use |
| 69 | + jacobian based methods. |
| 70 | +""" |
| 71 | +function FastShortcutNonlinearPolyalg( |
| 72 | + ::Type{T} = Float64; |
| 73 | + concrete_jac = nothing, |
| 74 | + linsolve = nothing, |
| 75 | + must_use_jacobian::Val = Val(false), |
| 76 | + prefer_simplenonlinearsolve::Val = Val(false), |
| 77 | + autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing, |
| 78 | + u0_len::Union{Int, Nothing} = nothing |
| 79 | +) where {T} |
| 80 | + start_index = 1 |
| 81 | + common_kwargs = (; concrete_jac, linsolve, autodiff, vjp_autodiff, jvp_autodiff) |
| 82 | + if must_use_jacobian isa Val{true} |
| 83 | + if T <: Complex |
| 84 | + algs = (NewtonRaphson(; common_kwargs...),) |
| 85 | + else |
| 86 | + algs = ( |
| 87 | + NewtonRaphson(; common_kwargs...), |
| 88 | + NewtonRaphson(; common_kwargs..., linesearch = BackTracking()), |
| 89 | + TrustRegion(; common_kwargs...), |
| 90 | + TrustRegion(; common_kwargs..., radius_update_scheme = RUS.Bastin) |
| 91 | + ) |
| 92 | + end |
| 93 | + else |
| 94 | + # SimpleNewtonRaphson and SimpleTrustRegion are not robust to singular Jacobians |
| 95 | + # and thus are not included in the polyalgorithm |
| 96 | + if prefer_simplenonlinearsolve isa Val{true} |
| 97 | + if T <: Complex |
| 98 | + algs = ( |
| 99 | + SimpleBroyden(), |
| 100 | + Broyden(; init_jacobian = Val(:true_jacobian), autodiff), |
| 101 | + SimpleKlement(), |
| 102 | + NewtonRaphson(; common_kwargs...) |
| 103 | + ) |
| 104 | + else |
| 105 | + start_index = u0_len !== nothing ? (u0_len ≤ 25 ? 4 : 1) : 1 |
| 106 | + algs = ( |
| 107 | + SimpleBroyden(), |
| 108 | + Broyden(; init_jacobian = Val(:true_jacobian), autodiff), |
| 109 | + SimpleKlement(), |
| 110 | + NewtonRaphson(; common_kwargs...), |
| 111 | + NewtonRaphson(; common_kwargs..., linesearch = BackTracking()), |
| 112 | + TrustRegion(; common_kwargs...), |
| 113 | + TrustRegion(; common_kwargs..., radius_update_scheme = RUS.Bastin) |
| 114 | + ) |
| 115 | + end |
| 116 | + else |
| 117 | + if T <: Complex |
| 118 | + algs = ( |
| 119 | + Broyden(; autodiff), |
| 120 | + Broyden(; init_jacobian = Val(:true_jacobian), autodiff), |
| 121 | + Klement(; linsolve, autodiff), |
| 122 | + NewtonRaphson(; common_kwargs...) |
| 123 | + ) |
| 124 | + else |
| 125 | + # TODO: This number requires a bit rigorous testing |
| 126 | + start_index = u0_len !== nothing ? (u0_len ≤ 25 ? 4 : 1) : 1 |
| 127 | + algs = ( |
| 128 | + Broyden(; autodiff), |
| 129 | + Broyden(; init_jacobian = Val(:true_jacobian), autodiff), |
| 130 | + Klement(; linsolve, autodiff), |
| 131 | + NewtonRaphson(; common_kwargs...), |
| 132 | + NewtonRaphson(; common_kwargs..., linesearch = BackTracking()), |
| 133 | + TrustRegion(; common_kwargs...), |
| 134 | + TrustRegion(; common_kwargs..., radius_update_scheme = RUS.Bastin) |
| 135 | + ) |
| 136 | + end |
| 137 | + end |
| 138 | + end |
| 139 | + return NonlinearSolvePolyAlgorithm(algs; start_index) |
| 140 | +end |
| 141 | + |
| 142 | +""" |
| 143 | + FastShortcutNLLSPolyalg( |
| 144 | + ::Type{T} = Float64; |
| 145 | + concrete_jac = nothing, |
| 146 | + linsolve = nothing, |
| 147 | + autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing |
| 148 | + ) |
| 149 | +
|
| 150 | +A polyalgorithm focused on balancing speed and robustness. It first tries less robust methods |
| 151 | +for more performance and then tries more robust techniques if the faster ones fail. |
| 152 | +
|
| 153 | +### Arguments |
| 154 | +
|
| 155 | + - `T`: The eltype of the initial guess. It is only used to check if some of the algorithms |
| 156 | + are compatible with the problem type. Defaults to `Float64`. |
| 157 | +""" |
| 158 | +function FastShortcutNLLSPolyalg( |
| 159 | + ::Type{T} = Float64; |
| 160 | + concrete_jac = nothing, |
| 161 | + linsolve = nothing, |
| 162 | + autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing |
| 163 | +) where {T} |
| 164 | + common_kwargs = (; linsolve, autodiff, vjp_autodiff, jvp_autodiff) |
| 165 | + if T <: Complex |
| 166 | + algs = ( |
| 167 | + GaussNewton(; common_kwargs..., concrete_jac), |
| 168 | + LevenbergMarquardt(; common_kwargs..., disable_geodesic = Val(true)), |
| 169 | + LevenbergMarquardt(; common_kwargs...) |
| 170 | + ) |
| 171 | + else |
| 172 | + algs = ( |
| 173 | + GaussNewton(; common_kwargs..., concrete_jac), |
| 174 | + LevenbergMarquardt(; common_kwargs..., disable_geodesic = Val(true)), |
| 175 | + TrustRegion(; common_kwargs..., concrete_jac), |
| 176 | + GaussNewton(; common_kwargs..., linesearch = BackTracking(), concrete_jac), |
| 177 | + TrustRegion(; |
| 178 | + common_kwargs..., radius_update_scheme = RUS.Bastin, concrete_jac |
| 179 | + ), |
| 180 | + LevenbergMarquardt(; common_kwargs...) |
| 181 | + ) |
| 182 | + end |
| 183 | + return NonlinearSolvePolyAlgorithm(algs) |
| 184 | +end |
0 commit comments