@@ -94,22 +94,27 @@ function _solveLambdaNumeric( fcttype::Union{F,<:Mixture{N_,F,S,T}},
9494 # norm(M, p, X) == distance(M, p, X)
9595 # TODO fix closure for performance
9696 fM = getManifold (fcttype)
97- function cost (Xc)
98- p = exp (M, ϵ, hat (M, ϵ, Xc))
97+ function cost (p, X, Xc)
98+ hat! (M, X, ϵ, Xc)
99+ exp! (M, p, ϵ, X)
99100 # X = objResX(p)
100101 # return norm(fM, p, X)^2 #TODO the manifold of p and X are not always the same
101102 # options getPointIdentity or leave it to factor
102103 residual = objResX (p)
103104 return sum (residual.^ 2 )
104105 end
105106
106- # separate statements to try improve type-stability
107- r = if islen1
108- Optim. optimize (cost, X0c, Optim. BFGS ())
109- else
110- Optim. optimize (cost, X0c, Optim. NelderMead ())
111- end
112-
107+ # # separate statements to try improve type-stability
108+ # r = if islen1
109+ # Optim.optimize(cost, X0c, Optim.BFGS())
110+ # else
111+ # Optim.optimize(cost, X0c, Optim.NelderMead())
112+ # end
113+ alg = islen1 ? Optim. BFGS () : Optim. NelderMead ()
114+ X0 = hat (M, ϵ, X0c)
115+ p0 = exp (M, ϵ, X0)
116+ r = Optim. optimize (Xc-> cost (p0, X0, Xc), X0c, alg)
117+
113118 return exp (M, ϵ, hat (M, ϵ, r. minimizer))
114119
115120end
0 commit comments