@@ -14,7 +14,7 @@ Hessian at each step with κ the number of Newton steps.
14
14
"""
15
15
function _fit (glr:: GLR{<:Union{LogisticLoss,RobustLoss},<:L2R} ,
16
16
solver:: Newton , X, y, scratch)
17
- p = size (X, 2 ) + Int (glr . fit_intercept )
17
+ _,p,_ = npc (scratch )
18
18
θ₀ = zeros (p)
19
19
_fgh! = fgh! (glr, X, y, scratch)
20
20
opt = Optim. only_fgh! (_fgh!)
@@ -36,13 +36,13 @@ 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
38
solver:: NewtonCG , X, y, scratch)
39
- p = size (X, 2 ) + Int (glr . fit_intercept )
40
- θ₀ = zeros (p)
41
- _f = objective (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
- opt = Optim. TwiceDifferentiableHV (_f, _fg!, _Hv!, θ₀)
45
- res = Optim. optimize (opt, θ₀, Optim. KrylovTrustRegion ())
39
+ _,p,_ = npc (scratch )
40
+ θ₀ = zeros (p)
41
+ _f = objective (glr, X, y)
42
+ _fg! = (g, θ) -> fgh! (glr, X, y, scratch)(0.0 , g, nothing , θ) # Optim# 738
43
+ _Hv! = Hv! (glr, X, y, scratch)
44
+ opt = Optim. TwiceDifferentiableHV (_f, _fg!, _Hv!, θ₀)
45
+ res = Optim. optimize (opt, θ₀, Optim. KrylovTrustRegion ())
46
46
return Optim. minimizer (res)
47
47
end
48
48
@@ -58,11 +58,11 @@ gradient at each step with κ the number of LBFGS steps.
58
58
"""
59
59
function _fit (glr:: GLR{<:Union{LogisticLoss,RobustLoss},<:L2R} ,
60
60
solver:: LBFGS , X, y, scratch)
61
- p = size (X, 2 ) + Int (glr . fit_intercept )
62
- θ₀ = zeros (p)
63
- _fg! = (f, g, θ) -> fgh! (glr, X, y, scratch)(f, g, nothing , θ)
64
- opt = Optim. only_fg! (_fg!)
65
- res = Optim. optimize (opt, θ₀, Optim. LBFGS ())
61
+ _,p,_ = npc (scratch )
62
+ θ₀ = zeros (p)
63
+ _fg! = (f, g, θ) -> fgh! (glr, X, y, scratch)(f, g, nothing , θ)
64
+ opt = Optim. only_fg! (_fg!)
65
+ res = Optim. optimize (opt, θ₀, Optim. LBFGS ())
66
66
return Optim. minimizer (res)
67
67
end
68
68
@@ -82,15 +82,15 @@ 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, scratch)
86
- p = size ( X, 2 ) + Int (glr . fit_intercept )
87
- c = maximum (y )
88
- θ₀ = zeros (p * c)
89
- _f = objective (glr, X, y; c= c)
90
- _fg! = (g, θ) -> fg! (glr, X, y, scratch)(0.0 , g, θ) # XXX : Optim.jl/738
91
- _Hv! = Hv! (glr, X, y, scratch)
92
- opt = Optim. TwiceDifferentiableHV (_f, _fg!, _Hv!, θ₀)
93
- res = Optim. optimize (opt, θ₀, Optim. KrylovTrustRegion ())
85
+ function _fit (glr:: GLR{<: MultinomialLoss,<:L2R} , solver:: NewtonCG ,
86
+ X, y, scratch )
87
+ _,p,c = npc (scratch )
88
+ θ₀ = zeros (p * c)
89
+ _f = objective (glr, X, y; c= c)
90
+ _fg! = (g, θ) -> fg! (glr, X, y, scratch)(0.0 , g, θ) # XXX : Optim.jl/738
91
+ _Hv! = Hv! (glr, X, y, scratch)
92
+ opt = Optim. TwiceDifferentiableHV (_f, _fg!, _Hv!, θ₀)
93
+ res = Optim. optimize (opt, θ₀, Optim. KrylovTrustRegion ())
94
94
return Optim. minimizer (res)
95
95
end
96
96
@@ -105,12 +105,12 @@ 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, scratch)
109
- p = size ( X, 2 ) + Int (glr . fit_intercept )
110
- c = maximum (y )
111
- θ₀ = zeros (p * c)
112
- _fg! = fg! (glr, X, y, scratch)
113
- opt = Optim. only_fg! (_fg!)
114
- res = Optim. optimize (opt, θ₀, Optim. LBFGS ())
108
+ function _fit (glr:: GLR{<: MultinomialLoss,<:L2R} , solver:: LBFGS ,
109
+ X, y, scratch )
110
+ _,p,c = npc (scratch )
111
+ θ₀ = zeros (p * c)
112
+ _fg! = fg! (glr, X, y, scratch)
113
+ opt = Optim. only_fg! (_fg!)
114
+ res = Optim. optimize (opt, θ₀, Optim. LBFGS ())
115
115
return Optim. minimizer (res)
116
116
end
0 commit comments