Skip to content

Commit 4bcc7b4

Browse files
authored
Restore _slack in mumerical calcs (#1790)
1 parent 0757330 commit 4bcc7b4

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/Factors/Mixture.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ function sampleFactor(cf::CalcFactor{<:Mixture}, N::Int = 1)
127127
cf.fullvariables,
128128
cf.solvefor,
129129
cf.manifold,
130-
cf.measurement
130+
cf.measurement,
131+
nothing,
131132
)
132133
smpls = [getSample(cf_) for _ = 1:N]
133134
# smpls = Array{Float64,2}(undef,s.dims,N)

src/entities/CalcFactor.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ struct CalcFactorNormSq{
3636
C,
3737
VT <: Tuple,
3838
M <: AbstractManifold,
39-
MEAS
39+
MEAS,
40+
S
4041
} <: CalcFactor{FT}
4142
""" the interface compliant user object functor containing the data and logic """
4243
factor::FT
@@ -58,6 +59,7 @@ struct CalcFactorNormSq{
5859
solvefor::Int
5960
manifold::M
6061
measurement::MEAS
62+
slack::S
6163
end
6264

6365
#TODO deprecate after CalcFactor is updated to CalcFactorNormSq

src/services/CalcFactor.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ function CalcFactorNormSq(
3131
cache = ccwl.dummyCache,
3232
fullvariables = ccwl.fullvariables,
3333
solvefor = ccwl.varidx[],
34-
manifold = getManifold(ccwl)
34+
manifold = getManifold(ccwl),
35+
slack=nothing,
3536
)
3637
#
3738
# FIXME using ccwl.dummyCache is not thread-safe
@@ -45,6 +46,7 @@ function CalcFactorNormSq(
4546
solvefor,
4647
manifold,
4748
ccwl.measurement,
49+
slack
4850
)
4951
end
5052

@@ -407,6 +409,7 @@ function _createCCW(
407409
solvefor,
408410
manifold,
409411
nothing,
412+
nothing,
410413
)
411414

412415
# get a measurement sample
@@ -426,6 +429,7 @@ function _createCCW(
426429
solvefor,
427430
manifold,
428431
measurement,
432+
nothing,
429433
)
430434

431435

src/services/NumericalCalculations.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ function _buildCalcFactor(
192192
smpid,
193193
varParams,
194194
activehypo,
195+
_slack = nothing,
195196
)
196197
#
197198
# FIXME, make thread safe (cache)
@@ -210,6 +211,7 @@ function _buildCalcFactor(
210211
solveforidx, #solvefor
211212
getManifold(ccwl), #manifold
212213
ccwl.measurement,
214+
_slack,
213215
)
214216
end
215217

@@ -391,10 +393,11 @@ function (cf::CalcFactorNormSq)(::Type{CalcConv}, x)
391393
varValsHypo[cf.solvefor][sampleIdx] = x
392394

393395
res = cf(cf.measurement[sampleIdx], map(vvh -> _getindex_anyn(vvh, sampleIdx), varValsHypo)...)
396+
res = isnothing(cf.slack) ? res : res .- cf.slack
394397
return sum(x->x^2, res)
395398
end
396399

397-
function _buildHypoCalcFactor(ccwl::CommonConvWrapper, smpid::Integer)
400+
function _buildHypoCalcFactor(ccwl::CommonConvWrapper, smpid::Integer, _slack)
398401
# build a view to the decision variable memory
399402
varValsHypo = ccwl.varValsAll[][ccwl.hyporecipe.activehypo]
400403
# create calc factor selected hypo and samples
@@ -403,7 +406,8 @@ function _buildHypoCalcFactor(ccwl::CommonConvWrapper, smpid::Integer)
403406
ccwl, #
404407
smpid, # ends in _sampleIdx
405408
varValsHypo, # ends in _legacyParams
406-
ccwl.hyporecipe.activehypo # ends in solvefor::Int
409+
ccwl.hyporecipe.activehypo, # ends in solvefor::Int
410+
_slack,
407411
)
408412
return cf
409413
end
@@ -427,7 +431,7 @@ function _solveCCWNumeric!(
427431
# target = view(ccwl.varValsAll[][ccwl.varidx[]], smpid)
428432

429433
# SUPER IMPORTANT ON PARTIALS, RESIDUAL FUNCTION MUST DEAL WITH PARTIAL AND WILL GET FULL VARIABLE POINTS REGARDLESS
430-
_hypoCalcFactor = _buildHypoCalcFactor(ccwl, smpid)
434+
_hypoCalcFactor = _buildHypoCalcFactor(ccwl, smpid, _slack)
431435

432436
# do the parameter search over defined decision variables using Minimization
433437
sfidx = ccwl.varidx[]

0 commit comments

Comments
 (0)