@@ -13,10 +13,10 @@ Assuming `n` dominates `p`, O(κnp²), dominated by the construction of the
13
13
Hessian at each step with κ the number of Newton steps.
14
14
"""
15
15
function _fit (glr:: GLR{<:Union{LogisticLoss,RobustLoss},<:L2R} ,
16
- solver:: Newton , X, y)
16
+ solver:: Newton , X, y, scratch )
17
17
p = size (X, 2 ) + Int (glr. fit_intercept)
18
18
θ₀ = zeros (p)
19
- _fgh! = fgh! (glr, X, y)
19
+ _fgh! = fgh! (glr, X, y, scratch )
20
20
opt = Optim. only_fgh! (_fgh!)
21
21
res = Optim. optimize (opt, θ₀, Optim. Newton ())
22
22
return Optim. minimizer (res)
@@ -35,12 +35,12 @@ Hessian at each step where κ₁ is the number of Newton steps and κ₂ is the
35
35
average number of CG steps per Newton step (which is at most p).
36
36
"""
37
37
function _fit (glr:: GLR{<:Union{LogisticLoss,RobustLoss},<:L2R} ,
38
- solver:: NewtonCG , X, y)
38
+ solver:: NewtonCG , X, y, scratch )
39
39
p = size (X, 2 ) + Int (glr. fit_intercept)
40
40
θ₀ = zeros (p)
41
41
_f = objective (glr, X, y)
42
- _fg! = (g, θ) -> fgh! (glr, X, y)(0.0 , g, nothing , θ) # Optim.jl/issues /738
43
- _Hv! = Hv! (glr, X, y)
42
+ _fg! = (g, θ) -> fgh! (glr, X, y, scratch )(0.0 , g, nothing , θ) # Optim.jl/738
43
+ _Hv! = Hv! (glr, X, y, scratch )
44
44
opt = Optim. TwiceDifferentiableHV (_f, _fg!, _Hv!, θ₀)
45
45
res = Optim. optimize (opt, θ₀, Optim. KrylovTrustRegion ())
46
46
return Optim. minimizer (res)
@@ -57,10 +57,10 @@ Assuming `n` dominates `p`, O(κnp), dominated by the computation of the
57
57
gradient at each step with κ the number of LBFGS steps.
58
58
"""
59
59
function _fit (glr:: GLR{<:Union{LogisticLoss,RobustLoss},<:L2R} ,
60
- solver:: LBFGS , X, y)
60
+ solver:: LBFGS , X, y, scratch )
61
61
p = size (X, 2 ) + Int (glr. fit_intercept)
62
62
θ₀ = zeros (p)
63
- _fg! = (f, g, θ) -> fgh! (glr, X, y)(f, g, nothing , θ)
63
+ _fg! = (f, g, θ) -> fgh! (glr, X, y, scratch )(f, g, nothing , θ)
64
64
opt = Optim. only_fg! (_fg!)
65
65
res = Optim. optimize (opt, θ₀, Optim. LBFGS ())
66
66
return Optim. minimizer (res)
@@ -82,13 +82,13 @@ computations are dominated by the application of the Hessian at each step with
82
82
κ₁ the number of Newton steps and κ₂ the average number of CG steps per Newton
83
83
step.
84
84
"""
85
- function _fit (glr:: GLR{MultinomialLoss,<:L2R} , solver:: NewtonCG , X, y)
85
+ function _fit (glr:: GLR{MultinomialLoss,<:L2R} , solver:: NewtonCG , X, y, scratch )
86
86
p = size (X, 2 ) + Int (glr. fit_intercept)
87
87
c = maximum (y)
88
88
θ₀ = zeros (p * c)
89
89
_f = objective (glr, X, y; c= c)
90
- _fg! = (g, θ) -> fg! (glr, X, y)(0.0 , g, θ) # XXX : Optim.jl/issues /738
91
- _Hv! = Hv! (glr, X, y)
90
+ _fg! = (g, θ) -> fg! (glr, X, y, scratch )(0.0 , g, θ) # XXX : Optim.jl/738
91
+ _Hv! = Hv! (glr, X, y, scratch )
92
92
opt = Optim. TwiceDifferentiableHV (_f, _fg!, _Hv!, θ₀)
93
93
res = Optim. optimize (opt, θ₀, Optim. KrylovTrustRegion ())
94
94
return Optim. minimizer (res)
@@ -105,11 +105,11 @@ Assuming `n` dominates `p`, O(κnpc), with `c` the number of classes, dominated
105
105
by the computation of the gradient at each step with κ the number of LBFGS
106
106
steps.
107
107
"""
108
- function _fit (glr:: GLR{MultinomialLoss,<:L2R} , solver:: LBFGS , X, y)
108
+ function _fit (glr:: GLR{MultinomialLoss,<:L2R} , solver:: LBFGS , X, y, scratch )
109
109
p = size (X, 2 ) + Int (glr. fit_intercept)
110
110
c = maximum (y)
111
111
θ₀ = zeros (p * c)
112
- _fg! = fg! (glr, X, y)
112
+ _fg! = fg! (glr, X, y, scratch )
113
113
opt = Optim. only_fg! (_fg!)
114
114
res = Optim. optimize (opt, θ₀, Optim. LBFGS ())
115
115
return Optim. minimizer (res)
0 commit comments