@@ -87,15 +87,6 @@ function (hypoCalcFactor::CalcFactorNormSq)(::Type{ManoptCalcConv}, M::AbstractM
8787 return hypoCalcFactor (CalcConv, p)
8888end
8989
90- # TODO untested and unused
91- # for deconv with the measurement a tangent vector
92- # function (hypoCalcFactor::CalcFactorNormSq)(M::AbstractManifold, Xc::AbstractVector)
93- # # M = hypoCalcFactor.manifold # calc factor has factor manifold in not variable that is needed here
94- # ϵ = getPointIdentity(M)
95- # X = get_vector(M, ϵ, Xc, DefaultOrthogonalBasis())
96- # return hypoCalcFactor(CalcDeconv, X)
97- # end
98-
9990function _solveLambdaNumeric (
10091 fcttype:: Union{F, <:Mixture{N_, F, S, T}} ,
10192 hypoCalcFactor,
@@ -109,7 +100,6 @@ function _solveLambdaNumeric(
109100 # the variable is a manifold point, we are working on the tangent plane in optim for now.
110101 #
111102 # TODO this is not general to all manifolds, should work for lie groups.
112- # ϵ = identity_element(M, u0)
113103 ϵ = getPointIdentity (variableType)
114104
115105 X0c = zero (MVector{getDimension (M),Float64})
@@ -142,34 +132,43 @@ function _solveLambdaNumeric(
142132 return exp (M, ϵ, hat (M, ϵ, r. minimizer))
143133end
144134
135+ # # deconvolution with calcfactor wip
136+ struct CalcDeconv end
137+
138+ function (cf:: CalcFactorNormSq )(:: Type{CalcDeconv} , meas)
139+ res = cf (meas, map (vvh -> _getindex_anyn (vvh, cf. _sampleIdx), cf. _legacyParams)... )
140+ return sum (x-> x^ 2 , res)
141+ end
142+
143+ # for deconv with the measurement a tangent vector, can dispatch for other measurement types.
144+ function (hypoCalcFactor:: CalcFactorNormSq )(:: Type{CalcDeconv} , M:: AbstractManifold , Xc:: AbstractVector )
145+ ϵ = getPointIdentity (M)
146+ X = get_vector (M, ϵ, Xc, DefaultOrthogonalBasis ())
147+ return hypoCalcFactor (CalcDeconv, X)
148+ end
145149
146- # TODO Consolidate with _solveLambdaNumeric, see #1374
147- # TODO _solveLambdaNumericMeas assumes a measurement is always a tangent vector, confirm.
150+ # NOTE Optim.jl version that assumes measurement is on the tangent
151+ # TODO test / dev for n-ary factor deconv
152+ # TODO Consolidate with _solveLambdaNumeric, see #1374
148153function _solveLambdaNumericMeas (
149154 fcttype:: Union{F, <:Mixture{N_, F, S, T}} ,
150- objResX:: Function ,
151- residual:: AbstractVector{<:Real} ,
155+ hypoCalcFactor,
152156 X0,# ::AbstractVector{<:Real},
153- variableType:: InferenceVariable ,
154157 islen1:: Bool = false ,
155158) where {N_, F <: AbstractManifoldMinimize , S, T}
156159 #
157- # Assume measurement is on the tangent
158160 M = getManifold (fcttype)
159- # the variable is a manifold point, we are working on the tangent plane in optim for now.
160161 ϵ = getPointIdentity (M)
161162 X0c = zeros (manifold_dimension (M))
162163 X0c .= vee (M, ϵ, X0)
163164
164- function cost (Xc)
165- X = hat (M, ϵ, Xc)
166- residual = objResX (X)
167- return sum (residual .^ 2 )
168- end
169-
170165 alg = islen1 ? Optim. BFGS () : Optim. NelderMead ()
171166
172- r = Optim. optimize (cost, X0c, alg)
167+ r = Optim. optimize (
168+ x-> hypoCalcFactor (CalcDeconv, M, x),
169+ X0c,
170+ alg
171+ )
173172 if ! Optim. converged (r)
174173 @debug " Optim did not converge:" r
175174 end
374373#
375374
376375struct CalcConv end
377- struct CalcDeconv end
378376
379377_getindex_anyn (vec, n) = begin
380378 len = length (vec)
@@ -397,7 +395,7 @@ function (cf::CalcFactorNormSq)(::Type{CalcConv}, x)
397395 return sum (x-> x^ 2 , res)
398396end
399397
400- function _buildHypoCalcFactor (ccwl:: CommonConvWrapper , smpid:: Integer , _slack)
398+ function _buildHypoCalcFactor (ccwl:: CommonConvWrapper , smpid:: Integer , _slack= nothing )
401399 # build a view to the decision variable memory
402400 varValsHypo = ccwl. varValsAll[][ccwl. hyporecipe. activehypo]
403401 # create calc factor selected hypo and samples
0 commit comments