Skip to content

Commit 04c492f

Browse files
committed
wip adding nullhypo
1 parent 59592f6 commit 04c492f

File tree

2 files changed

+50
-20
lines changed

2 files changed

+50
-20
lines changed

src/ApproxConv.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ function computeAcrossHypothesis!(ccwl::CommonConvWrapper{T},
189189
count += 1
190190
if sfidx in certainidx || hypoidx in certainidx || hypoidx == sfidx
191191
# hypo case hypoidx, sfidx = $hypoidx, $sfidx
192+
@show hypoidx, vars
192193
for i in 1:Threads.nthreads() ccwl.cpt[i].activehypo = vars; end
193194
approxConvOnElements!(ccwl, allelements[count])
194195
# elseif hypoidx == sfidx
@@ -277,14 +278,14 @@ function evalPotentialSpecific(Xi::Vector{DFGVariable},
277278
# Check which variables have been initialized
278279
isinit = map(x->isInitialized(x), Xi)
279280

280-
# assemble how hypotheses should be computed
281-
_, allelements, activehypo, mhidx = assembleHypothesesElements!(ccwl.hypotheses, maxlen, sfidx, length(Xi), isinit )
282-
certainidx = ccwl.certainhypo
283-
284281
# get manifold add operations
285282
# TODO, make better use of dispatch, see JuliaRobotics/RoME.jl#244
286283
addOps, d1, d2, d3 = buildHybridManifoldCallbacks(manis)
287284

285+
# assemble how hypotheses should be computed
286+
_, allelements, activehypo, mhidx = assembleHypothesesElements!(ccwl.hypotheses, maxlen, sfidx, length(Xi), isinit )
287+
certainidx = ccwl.certainhypo
288+
288289
# perform the numeric solutions on the indicated elements
289290
# error("ccwl.xDim=$(ccwl.xDim)")
290291
computeAcrossHypothesis!(ccwl, allelements, activehypo, certainidx, sfidx, maxlen, addOps, spreadNH=spreadNH)

src/ExplicitDiscreteMarginalizations.jl

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ sfidx=4, mhidx=2: 4 should take a value from 2
9898
sfidx=4, mhidx=3: 4 should take a value from 3
9999
sfidx=4, mhidx=4: ah = [1;4]
100100
```
101+
102+
Also keeping the default case documented:
103+
```
104+
# the default case where mh==nothing
105+
# equivalent to mh=[1;1;1] # assuming 3 variables
106+
sfidx=1, allelements=allidx[nhidx.==0], activehypo=(0,[1;])
107+
sfidx=2, allelements=allidx[nhidx.==0], activehypo=(0,[2;])
108+
sfidx=3, allelements=allidx[nhidx.==0], activehypo=(0,[3;])
109+
```
110+
111+
TODO still need to compensate multihypo case for user nullhypo addition.
101112
"""
102113
function assembleHypothesesElements!(mh::Categorical,
103114
maxlen::Int,
@@ -111,14 +122,10 @@ function assembleHypothesesElements!(mh::Categorical,
111122

112123
allidx = 1:maxlen
113124
allmhp, certainidx, uncertnidx = getHypothesesVectors(mh.p)
114-
# allmhp = 1:length(mh.p)
115-
# certainidx = allmhp[mh.p .== 0.0] # TODO remove after gwp removed
116-
# uncertnidx = allmhp[0.0 .< mh.p]
117125

118126
# select only hypotheses that can be used (ie variables have been initialized)
119127
@assert !(sum(isinit) == 0 && sfidx == certainidx) # cannot init from nothing for any hypothesis
120128

121-
122129
mhh = if sum(isinit) < lenXi - 1
123130
@assert isLeastOneHypoAvailable(sfidx, certainidx, uncertnidx, isinit)
124131
@info "not all hypotheses initialized, but at least one available -- see #427"
@@ -142,7 +149,7 @@ function assembleHypothesesElements!(mh::Categorical,
142149
mhh
143150
end
144151

145-
# prep mmultihypothesis selection values
152+
# prep mm-nultihypothesis selection values
146153
mhidx = rand(mhh, maxlen) # selection of which hypothesis is correct
147154
pidx = 0
148155
if sfidx in uncertnidx
@@ -152,7 +159,7 @@ function assembleHypothesesElements!(mh::Categorical,
152159
end
153160

154161
sfincer = sfidx in certainidx
155-
for pval in mhh.p # mh.p
162+
for pval in mhh.p
156163
pidx += 1
157164
pidxincer = pidx in certainidx # ??
158165
# permutation vectors for later computation
@@ -181,7 +188,7 @@ function assembleHypothesesElements!(mh::Categorical,
181188
push!(activehypo, (pidx,iterah))
182189
end
183190

184-
# # retroactively add nullhypo compensation for bad-init case (the 0 case)
191+
# # retroactively add nullhypo case (the 0 case)
185192
# if sfidx in uncertnidx
186193
# #
187194
# end
@@ -192,29 +199,51 @@ function assembleHypothesesElements!(mh::Nothing,
192199
maxlen::Int,
193200
sfidx::Int,
194201
lenXi::Int,
195-
isinit::Vector{Bool}=ones(Bool, lenXi) )
202+
isinit::Vector{Bool}=ones(Bool, lenXi),
203+
nullhypo::Real=0 )
204+
#
205+
# the default case where mh==nothing
206+
# equivalent to mh=[1;1;1] # assuming 3 variables
207+
# sfidx=1, allelements=allidx[nhidx.==0], activehypo=(0,[1;])
208+
196209
#
197210
allelements = []
198211
activehypo = []
199-
mhidx = Int[]
212+
213+
# TODO add cases where nullhypo occurs, see DFG #536, and IIF #237
214+
nmhw = [nullhypo; (1-nullhypo)]
215+
nhh = Categorical(nmhw)
216+
217+
# prep mmultihypothesis selection values
218+
# mhidx = Int[]
219+
# NOTE, must do something special to get around Categorical([0;10]) error
220+
# selection of which hypothesis is correct
221+
mhidx = nullhypo == 0 ? ones(Int, maxlen) : (rand(nhh, maxlen) .- 1)
200222

201223
allidx = 1:maxlen
202224
certainidx = 1:lenXi
203-
doneall = false
204-
for i in certainidx
205-
if !doneall
206-
push!(allelements, allidx)
225+
# zero is nullhypo case, 1 is first sfidx variable
226+
nullarr = allidx[mhidx .== 0]
227+
# mhidx == 1 case is regular -- this will be all elements if nullhypo=0.0
228+
reguarr = allidx[mhidx .!= 0]
229+
for i in [0;certainidx]
230+
if i == 0
231+
# elements that occur during nullhypo active
232+
push!(allelements, nullarr)
233+
push!(activehypo, (i,sfidx))
234+
elseif i == 1
235+
# elements that occur during regular hypothesis true
236+
push!(allelements, reguarr)
207237
push!(activehypo, (i,certainidx))
208-
doneall = true
209238
else
239+
# all remaining collections are empty (part of multihypo support)
210240
push!(allelements, Int[])
211241
push!(activehypo, (i,Int[]))
212242
end
213243
end
214244

215-
# TODO add cases where nullhypo occurs, see DFG #536, and IIF #237
216245

217-
return certainidx, allelements, activehypo, mhidx # certainidx = allhp
246+
return certainidx, allelements, activehypo, mhidx
218247
end
219248

220249

0 commit comments

Comments
 (0)