Skip to content

Commit 6f7878c

Browse files
committed
Fix mixture sampling and deconv for static arrays
1 parent 43dcfa3 commit 6f7878c

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

src/Factors/Mixture.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,19 @@ function sampleFactor(cf::CalcFactor{<:Mixture}, N::Int = 1)
133133
#out memory should be right size first
134134
length(cf.factor.labels) != N ? resize!(cf.factor.labels, N) : nothing
135135
cf.factor.labels .= rand(cf.factor.diversity, N)
136+
M = cf.manifold
137+
138+
# mixture needs to be refactored so let's make it worse :-)
139+
if cf.factor.mechanics isa AbstractPrior
140+
samplef = samplePoint
141+
elseif cf.factor.mechanics isa AbstractRelative
142+
samplef = sampleTangent
143+
end
144+
136145
for i = 1:N
137146
mixComponent = cf.factor.components[cf.factor.labels[i]]
138147
# measurements relate to the factor's manifold (either tangent vector or manifold point)
139-
setPointsMani!(smpls[i], rand(mixComponent, 1))
148+
setPointsMani!(smpls, samplef(M, mixComponent), i)
140149
end
141150

142151
# TODO only does first element of meas::Tuple at this stage, see #1099

src/entities/AliasScalarSampling.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ struct AliasingScalarSampler
4646
end
4747
end
4848

49+
function sampleTangent(
50+
M::AbstractDecoratorManifold,
51+
z::AliasingScalarSampler,
52+
p = getPointIdentity(M),
53+
)
54+
return hat(M, p, SVector{manifold_dimension(M)}(rand(z)))
55+
end
56+
4957
function rand!(ass::AliasingScalarSampler, smpls::Array{Float64})
5058
StatsBase.alias_sample!(ass.domain, ass.weights, smpls)
5159
return nothing

src/services/DeconvUtils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function approxDeconv(
108108
measurement[idx] = ts
109109
else
110110
ts = _solveLambdaNumeric(fcttype, hypoObj, res_, measurement[idx], islen1)
111-
copyto!(target_smpl, ts)
111+
measurement[idx] = ts
112112
end
113113
end
114114

src/services/NumericalCalculations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ function _solveLambdaNumericMeas(
236236
M = getManifold(variableType)#fcttype.M
237237
# the variable is a manifold point, we are working on the tangent plane in optim for now.
238238
ϵ = getPointIdentity(variableType)
239-
X0c = vee(M, ϵ, u0)
239+
X0c = zeros(manifold_dimension(M))
240240

241241
function cost(Xc)
242242
X = hat(M, ϵ, Xc)

test/testSpecialEuclidean2Mani.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ pred, meas = approxDeconv(fg, :x0x1f1)
242242

243243
p_t = map(x->x.x[1], pred)
244244
m_t = map(x->x.x[1], meas)
245-
p_θ = map(x->x.x[2][2], pred)
245+
#TODO why is angle wrapping around? (after SA update?)
246+
p_θ = map(x->Manifolds.sym_rem(x.x[2][2]), pred)
246247
m_θ = map(x->x.x[2][2], meas)
247248

248249
@test isapprox(mean(p_θ), 0.1, atol=0.02)

test/testUseMsgLikelihoods.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ fT = getFactorType(fct)
2424

2525
M = getManifold(fT)
2626
X = sampleTangent(M, fT.Z)
27-
@test X isa Vector{<:Real}
27+
@test X isa AbstractVector{<:Real}
2828

2929
z = sampleFactor(fct)[1]
30-
@test z isa Vector{<:Real}
30+
@test z isa AbstractVector{<:Real}
3131

3232
##
3333

0 commit comments

Comments
 (0)