Skip to content

Commit

Permalink
ccw comments, found huge bug evalPotSpec dupl
Browse files Browse the repository at this point in the history
  • Loading branch information
dehann committed Dec 29, 2022
1 parent 86fe2dc commit d516322
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
11 changes: 7 additions & 4 deletions src/entities/FactorOperationalMemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ mutable struct CommonConvWrapper{
""" dummy cache value to be deep copied later for each of the CalcFactor instances """
dummyCache::CT
# derived config parameters for this factor
""" common usage manifold definition for this factor """
""" Factor manifold definition for frequent use (not the variables manifolds) """
manifold::AM
""" Which dimensions does this factor influence. Sensitive (mutable) to both which 'solvefor index' variable and whether the factor is partial dimension """
partialDims::Vector{<:Integer}
""" is this a partial constraint as defined by the existance of factor field `.partial::Tuple` """
partial::Bool
""" general setup of factor dimensions"""
""" coordinate dimension size of current target variable (see .fullvariables[.varidx]), TODO remove once only use under AbstractRelativeRoots is deprecated or resolved """
xDim::Int
""" coordinate dimension size of factor, same as manifold_dimension(.manifold) """
zDim::Int
""" probability that this factor is wholly incorrect and should be ignored during solving """
nullhypo::Float64
""" inflationSpread particular to this factor """
""" inflationSpread particular to this factor (by how much to dispurse the belief initial values before numerical optimization is run). Analogous to stochastic search """
inflation::Float64
# multihypo specific field containers for recipe of hypotheses to compute
""" multi hypothesis settings #NOTE no need for a parameter as type is known from `parseusermultihypo` """
Expand All @@ -125,7 +127,8 @@ mutable struct CommonConvWrapper{
# buffers and indices to point numerical computations to specific memory locations
""" user defined measurement values for each approxConv operation
FIXME make type stable, JT should now be type stable if rest works.
SUPER IMPORTANT, if prior=>point or relative=>tangent, see #1661 """
SUPER IMPORTANT, if prior=>point or relative=>tangent, see #1661
can be a Vector{<:Tuple} or more direct Vector{<: pointortangenttype} """
measurement::Vector{MT}
""" which index is being solved for in params? """
varidx::Int
Expand Down
7 changes: 6 additions & 1 deletion src/services/CalcFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ function _setCCWDecisionDimsConv!(
ccwl.partialDims = if ccwl.partial
Int[ccwl.usrfnc!.partial...]
else
# NOTE this is the target variable dimension (not factor manifold dimension)
Int[1:(ccwl.xDim)...]
end

Expand Down Expand Up @@ -442,7 +443,7 @@ function _prepCCW(
measurement = Vector{elT}()

# partialDims are sensitive to both which solvefor variable index and whether the factor is partial
partial = hasfield(T, :partial)
partial = hasfield(T, :partial) # FIXME, use isPartial function instead
partialDims = if partial
Int[usrfnc.partial...]
else
Expand Down Expand Up @@ -503,6 +504,7 @@ function _updateCCW!(
Xi::AbstractVector{<:DFGVariable},
solvefor::Symbol,
N::Integer;
measurement = [],
needFreshMeasurements::Bool = true,
solveKey::Symbol = :default,
) where {F <: AbstractFactor}
Expand All @@ -522,6 +524,7 @@ function _updateCCW!(
# some better consolidate is needed
# ccwl.vartypes = varTypes
# FIXME ON FIRE, what happens if this is a partial dimension factor? See #1246
# FIXME, confirm this is hypo sensitive selection from Xi, better to use double indexing for clarity getDimension(ccw.fullvariables[hypoidx[sfidx]])
ccwl.xDim = getDimension(getVariableType(Xi[sfidx]))
# TODO maybe refactor new type higher up?

Expand All @@ -546,6 +549,8 @@ function _updateCCW!(
if needFreshMeasurements
# TODO refactor
ccwl.measurement = sampleFactor(cf, maxlen)
elseif 0 < length(measurement)
ccwl.measurement = measurement
end

# set each CPT
Expand Down
27 changes: 12 additions & 15 deletions src/services/EvalFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,10 @@ function evalPotentialSpecific(
ccwl::CommonConvWrapper{T},
solvefor::Symbol,
T_::Type{<:AbstractRelative},
measurement::AbstractVector = Tuple[];
needFreshMeasurements::Bool = true,
measurement::AbstractVector = Tuple[]; # TODO make this a concrete type
needFreshMeasurements::Bool = true, # superceeds over measurement
solveKey::Symbol = :default,
N::Int = if 0 < length(measurement)
length(measurement)
else
maximum(Npts.(getBelief.(Xi, solveKey)))
end,
N::Int = 0 < length(measurement) ? length(measurement) : maximum(Npts.(getBelief.(Xi, solveKey))),
spreadNH::Real = 3.0,
inflateCycles::Int = 3,
nullSurplus::Real = 0,
Expand All @@ -353,12 +349,12 @@ function evalPotentialSpecific(

# Prep computation variables
# NOTE #1025, should FMD be built here...
sfidx, maxlen = _updateCCW!(ccwl, Xi, solvefor, N; needFreshMeasurements, solveKey)
# check for user desired measurement values
if 0 < length(measurement)
# @info "HERE" typeof(ccwl.measurement) typeof(measurement)
ccwl.measurement = measurement
end
# add user desired measurement values if 0 < length
sfidx, maxlen = _updateCCW!(ccwl, Xi, solvefor, N; solveKey, needFreshMeasurements, measurement)
# if 0 < length(measurement)
# # @info "HERE" typeof(ccwl.measurement) typeof(measurement)
# ccwl.measurement = measurement
# end

# Check which variables have been initialized
isinit = map(x -> isInitialized(x), Xi)
Expand Down Expand Up @@ -394,6 +390,7 @@ function evalPotentialSpecific(
ipc = ones(getDimension(Xi[sfidx]))
if isPartial(ccwl)
# FIXME this is a workaround until better _calcIPCRelative can be used
# TODO consolidate to common usage e.g. getPartialDims(ccwl)
msk_ = setdiff(1:length(ipc), ccwl.usrfnc!.partial)
for _i in msk_
ipc[_i] = 0.0
Expand All @@ -414,11 +411,11 @@ function evalPotentialSpecific(
measurement::AbstractVector = Tuple[];
needFreshMeasurements::Bool = true,
solveKey::Symbol = :default,
N::Int = length(measurement),
dbg::Bool = false,
N::Int = 0 < length(measurement) ? length(measurement) : maximum(Npts.(getBelief.(Xi, solveKey))),
spreadNH::Real = 3.0,
inflateCycles::Int = 3,
nullSurplus::Real = 0,
dbg::Bool = false,
skipSolve::Bool = false,
_slack = nothing,
) where {T <: AbstractFactor}
Expand Down
1 change: 1 addition & 0 deletions src/services/NumericalCalculations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function _checkErrorCCWNumerics(
testshuffle::Bool = false,
) where {N_, F <: AbstractRelativeRoots, S, T}
#
# error("<:AbstractRelativeRoots is obsolete, use one of the other <:AbstractRelative types instead.")
# @info "ccwl zDim and xDim" ccwl.zDim ccwl.xDim
if testshuffle || ccwl.partial || (!ccwl.partial && ccwl.zDim < ccwl.xDim)
error(
Expand Down

0 comments on commit d516322

Please sign in to comment.