Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ConsolidateParametricRelatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function solveFactorParameteric(dfg::AbstractDFG,
M = getManifold(fctTyp)
e0 = identity_element(M)
mea_ = hat(M, e0, mea)
measT = [(mea_,)]
measT = [mea_]

# get variable points
function _getParametric(vari::DFGVariable, key=:default)
Expand Down
14 changes: 7 additions & 7 deletions src/DeconvUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Related
function approxDeconv(fcto::DFGFactor,
ccw::CommonConvWrapper = _getCCW(fcto);
N::Int=100,
measurement::AbstractVector{<:Tuple}=sampleFactor(ccw, N),
measurement::AbstractVector=sampleFactor(ccw, N),
retries::Int=3 )
#
# but what if this is a partial factor -- is that important for general cases in deconv?
Expand All @@ -59,7 +59,7 @@ function approxDeconv(fcto::DFGFactor,
fmd = _getFMdThread(ccw)

# TODO assuming vector on only first container in measurement::Tuple
makeTarget = (i) -> measurement[i][1] # TODO does not support copy-primitive types like Float64, only Ref()
makeTarget = (i) -> measurement[i] # TODO does not support copy-primitive types like Float64, only Ref()
# makeTarget = (i) -> view(measurement[1][i],:)
# makeTarget = (i) -> view(measurement[1], :, i)

Expand Down Expand Up @@ -97,17 +97,17 @@ function approxDeconv(fcto::DFGFactor,
# find solution via SubArray view pointing to original memory location
if fcttype isa AbstractManifoldMinimize
sfidx = ccw.varidx
targeti_ .= _solveLambdaNumeric(fcttype, hypoObj, res_, measurement[idx][1], ccw.vartypes[sfidx](), islen1)
targeti_ .= _solveLambdaNumeric(fcttype, hypoObj, res_, measurement[idx], ccw.vartypes[sfidx](), islen1)
else
targeti_ .= _solveLambdaNumeric(fcttype, hypoObj, res_, measurement[idx][1], islen1)
targeti_ .= _solveLambdaNumeric(fcttype, hypoObj, res_, measurement[idx], islen1)
end

end

# return (deconv-prediction-result, independent-measurement)
r_meas = map(m->m[1], measurement)
r_fctSmpls = map(m->m[1], fctSmpls)
return r_meas, r_fctSmpls
# r_meas = map(m->m[1], measurement)
# r_fctSmpls = map(m->m[1], fctSmpls)
return measurement, fctSmpls
end


Expand Down
10 changes: 5 additions & 5 deletions src/FactorGraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,11 @@ function prepgenericconvolution(Xi::Vector{<:DFGVariable},
_cf = CalcFactor( usrfnc, fmd, 0, 1, nothing, varParamsAll) # (Vector{MeasType}(),)

# get a measurement sample
meas_single = sampleFactor(_cf, 1)
meas_single = sampleFactor(_cf, 1)[1]

#TODO preallocate measurement?
measurement = Vector{typeof(meas_single)}()

#TODO preallocate measuerement?
measurement = Vector{eltype(meas_single)}()

# get the measurement dimension
zdim = calcZDim(_cf)
# some hypo resolution
Expand All @@ -628,7 +628,7 @@ function prepgenericconvolution(Xi::Vector{<:DFGVariable},
# FIXME, suppressing nested gradient propagation on GenericMarginals for the time being, see #1010
if (!_blockRecursion) && usrfnc isa AbstractRelative && !(usrfnc isa GenericMarginal)
# take first value from each measurement-tuple-element
measurement_ = meas_single[1]
measurement_ = meas_single
# compensate if no info available during deserialization
# take the first value from each variable param
pts_ = map(x->x[1], varParamsAll)
Expand Down
4 changes: 2 additions & 2 deletions src/Factors/Circular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CircularCircular(::UniformScaling) = CircularCircular(Normal())


function getSample(cf::CalcFactor{<:CircularCircular})
(rand(cf.factor.Z, 1), )
return rand(cf.factor.Z, 1)
end

function (cf::CalcFactor{<:CircularCircular})(meas,
Expand Down Expand Up @@ -61,7 +61,7 @@ PriorCircular(::UniformScaling) = PriorCircular(Normal())


function getSample(cf::CalcFactor{<:PriorCircular})
return (rand(cf.factor.Z, 1), )
return rand(cf.factor.Z, 1)
end


Expand Down
2 changes: 1 addition & 1 deletion src/Factors/DefaultPrior.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Prior{T <: SamplableBelief} <: AbstractPrior
end
Prior(::UniformScaling) = Prior(Normal())

getSample(cf::CalcFactor{<:Prior}) = (rand(cf.factor.Z, 1), )
getSample(cf::CalcFactor{<:Prior}) = rand(cf.factor.Z, 1)


# basic default
Expand Down
2 changes: 1 addition & 1 deletion src/Factors/EuclidDistance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ getDimension(::InstanceType{<:EuclidDistance}) = 1


function getSample(cf::CalcFactor{<:EuclidDistance})
(rand(cf.factor.Z, 1), )
rand(cf.factor.Z, 1)
end

# new and simplified interface for both nonparametric and parametric
Expand Down
4 changes: 2 additions & 2 deletions src/Factors/GenericFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function getSample(cf::CalcFactor{<:ManifoldFactor{M,Z}}) where {M,Z}
ret = rand(cf.factor.Z)
end
#return coordinates as we do not know the point here #TODO separate Lie group
return (ret, )
return ret
end

# function (cf::CalcFactor{<:ManifoldFactor{<:AbstractGroupManifold}})(Xc, p, q)
Expand Down Expand Up @@ -112,7 +112,7 @@ function getSample(cf::CalcFactor{<:ManifoldPrior})

point = samplePoint(M, Z, p, basis, retract_method)

return (point, )
return point
end

#TODO investigate SVector if small dims, this is slower
Expand Down
2 changes: 1 addition & 1 deletion src/Factors/GenericMarginal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mutable struct GenericMarginal <: AbstractRelativeRoots
GenericMarginal(a,b,c) = new(a,b,c)
end

getSample(::CalcFactor{<:GenericMarginal}) = ([0],)
getSample(::CalcFactor{<:GenericMarginal}) = [0]

mutable struct PackedGenericMarginal <: PackedInferenceType
Zij::Array{Float64,1}
Expand Down
2 changes: 1 addition & 1 deletion src/Factors/LinearRelative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ getDimension(::InstanceType{LinearRelative{N}}) where {N} = N
function getSample(cf::CalcFactor{<:LinearRelative})
# _samplemakevec(z::Real) = [z;]
# _samplemakevec(z::AbstractVector{<:Real}) = z
(sampleTangent(getManifold(cf.factor), cf.factor.Z), )
return sampleTangent(getManifold(cf.factor), cf.factor.Z)
end


Expand Down
2 changes: 1 addition & 1 deletion src/Factors/Mixture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function sampleFactor( cf::CalcFactor{<:Mixture}, N::Int=1)
for i in 1:N
mixComponent = cf.factor.components[cf.factor.labels[i]]
# measurements relate to the factor's manifold (either tangent vector or manifold point)
setPointsMani!(smpls[i][1], rand(mixComponent,1))
setPointsMani!(smpls[i], rand(mixComponent,1))
end

# TODO only does first element of meas::Tuple at this stage, see #1099
Expand Down
4 changes: 2 additions & 2 deletions src/Factors/MsgPrior.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ end
# MsgPrior{T}(z, infd)
# end
function getSample(cf::CalcFactor{<:MsgPrior})
(rand(cf.factor.Z, 1), )
return rand(cf.factor.Z, 1)
end

#TODO check these for manifolds, may need updating to samplePoint
# MKD already returns a vector of points
function getSample(cf::CalcFactor{<:MsgPrior{<:ManifoldKernelDensity}})
mkd = cf.factor.Z
(samplePoint(mkd.manifold, mkd), )
return samplePoint(mkd.manifold, mkd)
end

getManifold(mp::MsgPrior{<:ManifoldKernelDensity}) = mp.Z.manifold
Expand Down
2 changes: 1 addition & 1 deletion src/Factors/PartialPrior.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end

getManifold(pp::PartialPrior{<:PackedManifoldKernelDensity}) = pp.Z.manifold

getSample(cf::CalcFactor{<:PartialPrior}) = (samplePoint(cf.factor.Z), )
getSample(cf::CalcFactor{<:PartialPrior}) = samplePoint(cf.factor.Z)


"""
Expand Down
2 changes: 1 addition & 1 deletion src/Factors/PartialPriorPassThrough.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end
getManifold(pppt::PartialPriorPassThrough{<:HeatmapDensityRegular{T,H,<:ManifoldKernelDensity}}) where {T,H} = (pppt.Z.densityFnc.manifold)

# this step is skipped during main inference process
getSample(cf::CalcFactor{<:PartialPriorPassThrough}) = (sampleTangent(getManifold(cf.factor), cf.factor.Z), )
getSample(cf::CalcFactor{<:PartialPriorPassThrough}) = sampleTangent(getManifold(cf.factor), cf.factor.Z)


#
4 changes: 2 additions & 2 deletions src/NumericalCalculations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ function _buildCalcFactorLambdaSample(ccwl::CommonConvWrapper,

# build static lambda
unrollHypo! = if _slack === nothing
() -> cf( measurement_[smpid]..., (getindex.(varParams, smpid))... )
() -> cf( measurement_[smpid], (getindex.(varParams, smpid))... )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why drop the tuple part of a measurement here? Code all over has residual functions follow
(cf)(z1,z2,x1,x2,x3)

seems like you restricting to only z1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it the user must decompose the measurement sample data themselves inside the residual function, z1 here can be anything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why drop the tuple part of a measurement here? Code all over has residual functions follow
(cf)(z1,z2,x1,x2,x3)

Only found DERelative that works this way and updated it.

I take it the user must decompose the measurement sample data themselves inside the residual function, z1 here can be anything.

yes, "one factor = one measurement". Measurement can be any type and it's up to the user to decide how to compose it. This way it's more flexible and we get rid of the tuples for simpler cases, this makes maintenance easier in my opinion.

else
# slack is used to shift the residual away from the natural "zero" tension position of a factor,
# this is useful when calculating factor gradients at a variety of param locations resulting in "non-zero slack" of the residual.
# see `IIF.calcFactorResidualTemporary`
# NOTE this minus operation assumes _slack is either coordinate or tangent vector element (not a manifold or group element)
() -> cf( measurement_[smpid]..., (getindex.(varParams, smpid))... ) .- _slack
() -> cf( measurement_[smpid], (getindex.(varParams, smpid))... ) .- _slack
end

return unrollHypo!, target
Expand Down
8 changes: 4 additions & 4 deletions src/ODE/DERelative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ end


# NOTE see #1025, CalcFactor should fix `multihypo=` in `cf.metadata` fields
function (cf::CalcFactor{<:DERelative})(meas1,
diffOp,
X...)
function (cf::CalcFactor{<:DERelative})(measurement, X...)
#

meas1 = measurement[1]
diffOp = measurement[2]

oderel = cf.factor

# work on-manifold
Expand Down
2 changes: 1 addition & 1 deletion src/entities/FactorGradients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Related

[`calcFactorResidualTemporary`](@ref), [`_buildGraphByFactorAndTypes`](@ref)
"""
mutable struct FactorGradientsCached!{F <: AbstractRelative, S, M <: Tuple, P, G, L}
mutable struct FactorGradientsCached!{F <: AbstractRelative, S, M, P, G, L}
dfgfct::DFGFactor{<:CommonConvWrapper{F}}
# cached jacobian matrix of gradients
cached_gradients::Matrix{Float64}
Expand Down
4 changes: 2 additions & 2 deletions src/entities/FactorOperationalMemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Related

[`CalcFactorMahalanobis`](@ref), [`CommonConvWrapper`](@ref), [`FactorMetadata`](@ref), [`ConvPerThread`](@ref)
"""
struct CalcFactor{T <: AbstractFactor, M, P <: Union{<:Tuple,Nothing,Vector{<:Tuple}}, X}
struct CalcFactor{T <: AbstractFactor, M, P <: Union{<:Tuple,Nothing,AbstractVector}, X}
# the interface compliant user object functor containing the data and logic
factor::T
# the metadata to be passed to the user residual function
Expand Down Expand Up @@ -163,7 +163,7 @@ mutable struct CommonConvWrapper{ T<:FunctorInferenceType,
C<:Union{Nothing, Vector{Int}},
NTP <: NamedTuple,
G,
MT<:Tuple} <: FactorOperationalMemory
MT} <: FactorOperationalMemory
#
### Values consistent across all threads during approx convolution
usrfnc!::T # user factor / function
Expand Down
10 changes: 5 additions & 5 deletions src/services/ApproxConv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export calcFactorResidual
function approxConvBelief(dfg::AbstractDFG,
fc::DFGFactor,
target::Symbol,
measurement::AbstractVector{<:Tuple}=Tuple[];#FIXME
measurement::AbstractVector=Tuple[];
solveKey::Symbol=:default,
N::Int=length(measurement),
skipSolve::Bool=false )
Expand Down Expand Up @@ -62,7 +62,7 @@ Related
function approxConvBelief(dfg::AbstractDFG,
from::Symbol,
target::Symbol,
measurement::AbstractVector{<:Tuple}=Tuple[];#FIXME
measurement::AbstractVector=Tuple[];
solveKey::Symbol=:default,
N::Int = length(measurement),
tfg::AbstractDFG = initfg(),
Expand Down Expand Up @@ -152,7 +152,7 @@ Notes
function calcProposalBelief(dfg::AbstractDFG,
fct::DFGFactor,
target::Symbol,
measurement::AbstractVector{<:Tuple}=Tuple[];#FIXME
measurement::AbstractVector=Tuple[];
N::Int=length(measurement),
solveKey::Symbol=:default,
dbg::Bool=false )
Expand All @@ -168,7 +168,7 @@ end
function calcProposalBelief(dfg::AbstractDFG,
fct::DFGFactor{<:CommonConvWrapper{<:PartialPriorPassThrough}},
target::Symbol,
measurement::AbstractVector{<:Tuple}=Tuple[];#FIXME
measurement::AbstractVector=Tuple[];
N::Int=length(measurement),
solveKey::Symbol=:default,
dbg::Bool=false )
Expand Down Expand Up @@ -207,7 +207,7 @@ function proposalbeliefs!(dfg::AbstractDFG,
destlbl::Symbol,
factors::AbstractVector{<:DFGFactor},
dens::AbstractVector{<:ManifoldKernelDensity},
measurement::AbstractVector{<:Tuple}=Tuple[];#FIXME
measurement::AbstractVector=Tuple[];
solveKey::Symbol=:default,
N::Int=getSolverParams(dfg).N, #maximum([length(getPoints(getBelief(dfg, destlbl, solveKey))); getSolverParams(dfg).N]),
dbg::Bool=false )
Expand Down
8 changes: 4 additions & 4 deletions src/services/CalcFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Related
"""
function calcFactorResidualTemporary( fct::AbstractRelative,
varTypes::Tuple,
measurement::AbstractVector{<:Tuple},
measurement,
pts::Tuple;
tfg::AbstractDFG = initfg(),
_blockRecursion::Bool=false )
Expand All @@ -133,11 +133,11 @@ function calcFactorResidualTemporary( fct::AbstractRelative,
else
# now use the CommonConvWrapper object in `_dfgfct`
cfo = CalcFactor(_getCCW(_dfgfct))
sampleFactor(cfo, 1)
sampleFactor(cfo, 1)[1]
end

# assume a single sample point is being run
return calcFactorResidual(_dfgfct, _measurement[1]..., pts...)
return calcFactorResidual(_dfgfct, _measurement, pts...)
end


Expand Down Expand Up @@ -180,7 +180,7 @@ function CommonConvWrapper( fnc::T,
activehypo= 1:length(params),
nullhypo::Real=0,
varidx::Int=1,
measurement::Vector{<:Tuple}=Vector(Vector{Float64}(),), # FIXME should not be a Matrix
measurement::AbstractVector=Vector(Vector{Float64}(),), # FIXME should not be a Matrix
particleidx::Int=1,
xDim::Int=size(X,1),
partialDims::AbstractVector{<:Integer}=collect(1:size(X,1)), # TODO make this SVector, and name partialDims
Expand Down
Loading