Skip to content

Commit 7c51ccb

Browse files
Removed NonlinearLeastSquaresProblem adapter & its tests
Signed-off-by: AdityaPandeyCN <[email protected]>
1 parent 1c70722 commit 7c51ccb

File tree

2 files changed

+0
-64
lines changed

2 files changed

+0
-64
lines changed

lib/OptimizationSciPy/src/OptimizationSciPy.jl

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,31 +1398,6 @@ function SciMLBase.__solve(cache::OptimizationCache{F,RC,LB,UB,LC,UC,S,O,D,P,C})
13981398
stats = stats)
13991399
end
14001400

1401-
function SciMLBase.__init(prob::SciMLBase.NonlinearLeastSquaresProblem, opt::ScipyLeastSquares; kwargs...)
1402-
obj = ResidualObjective(prob.f)
1403-
optf = Optimization.OptimizationFunction(obj)
1404-
1405-
has_lb = hasproperty(prob, :lb)
1406-
has_ub = hasproperty(prob, :ub)
1407-
1408-
if has_lb || has_ub
1409-
lb_val = has_lb ? getproperty(prob, :lb) : fill(-Inf, length(prob.u0))
1410-
ub_val = has_ub ? getproperty(prob, :ub) : fill( Inf, length(prob.u0))
1411-
optprob = Optimization.OptimizationProblem(optf, prob.u0, prob.p;
1412-
lb = lb_val, ub = ub_val,
1413-
sense = Optimization.MinSense)
1414-
else
1415-
optprob = Optimization.OptimizationProblem(optf, prob.u0, prob.p;
1416-
sense = Optimization.MinSense)
1417-
end
1418-
1419-
return SciMLBase.__init(optprob, opt; kwargs...)
1420-
end
1421-
1422-
function SciMLBase.init(prob::SciMLBase.NonlinearLeastSquaresProblem, opt::ScipyLeastSquares; kwargs...)
1423-
SciMLBase.__init(prob, opt; kwargs...)
1424-
end
1425-
14261401
export ScipyMinimize, ScipyNelderMead, ScipyPowell, ScipyCG, ScipyBFGS, ScipyNewtonCG,
14271402
ScipyLBFGSB, ScipyTNC, ScipyCOBYLA, ScipyCOBYQA, ScipySLSQP, ScipyTrustConstr,
14281403
ScipyDogleg, ScipyTrustNCG, ScipyTrustKrylov, ScipyTrustExact,

lib/OptimizationSciPy/test/runtests.jl

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -163,45 +163,6 @@ end
163163
@test sol.retcode == ReturnCode.Success
164164
end
165165

166-
@testset "ScipyLeastSquares" begin
167-
xdata = collect(0:0.1:1)
168-
ydata = 2.0 * xdata .+ 1.0 .+ 0.1 * randn(length(xdata))
169-
function residuals(params, p=nothing)
170-
a, b = params
171-
return ydata .- (a .* xdata .+ b)
172-
end
173-
x0_ls = [1.0, 0.0]
174-
prob = NonlinearLeastSquaresProblem(residuals, x0_ls)
175-
sol = solve(prob, ScipyLeastSquaresTRF())
176-
@test sol.retcode == ReturnCode.Success
177-
@test sol.u[1] 2.0 atol=0.5
178-
@test sol.u[2] 1.0 atol=0.5
179-
sol = solve(prob, ScipyLeastSquaresDogbox())
180-
@test sol.retcode == ReturnCode.Success
181-
@test sol.u[1] 2.0 atol=0.5
182-
sol = solve(prob, ScipyLeastSquaresLM())
183-
@test sol.retcode == ReturnCode.Success
184-
@test sol.u[1] 2.0 atol=0.5
185-
prob_bounded = NonlinearLeastSquaresProblem(residuals, x0_ls; lb = [0.0, -2.0], ub = [5.0, 3.0])
186-
sol = solve(prob_bounded, ScipyLeastSquaresTRF())
187-
@test sol.retcode == ReturnCode.Success
188-
@test 0.0 <= sol.u[1] <= 5.0
189-
@test -2.0 <= sol.u[2] <= 3.0
190-
for loss in ["linear", "soft_l1", "huber", "cauchy", "arctan"]
191-
sol = solve(prob, ScipyLeastSquares(method="trf", loss=loss))
192-
@test sol.retcode == ReturnCode.Success
193-
end
194-
ydata_outliers = copy(ydata)
195-
ydata_outliers[5] = 10.0
196-
function residuals_outliers(params, p=nothing)
197-
a, b = params
198-
return ydata_outliers .- (a .* xdata .+ b)
199-
end
200-
prob_outliers = NonlinearLeastSquaresProblem(residuals_outliers, x0_ls)
201-
sol_robust = solve(prob_outliers, ScipyLeastSquares(method="trf", loss="huber"))
202-
@test sol_robust.retcode == ReturnCode.Success
203-
end
204-
205166
@testset "ScipyRootScalar" begin
206167
f_root(x, p) = x[1]^3 - 2*x[1] - 5
207168
x0_root = [2.0]

0 commit comments

Comments
 (0)