Skip to content

Commit

Permalink
added obs_weight
Browse files Browse the repository at this point in the history
  • Loading branch information
zsunberg committed Apr 26, 2017
1 parent 1b1fe6b commit 693fd21
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/obs_weight.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@generated function obs_weight(p, s, a, sp, o)
if implemented(obs_weight, Tuple{p, a, sp, o})
return :(obs_weight(p, a, sp, o))
elseif implemented(observation, Tuple{p, s, a, sp})
return :(pdf(observation(p, s, a, sp), o))
else
return :(throw(MethodError(obs_weight, (p,s,a,sp,o))))
end
end

@generated function obs_weight(p, a, sp, o)
if implemented(obs_weight, Tuple{p, sp, o})
return :(obs_weight(p, sp, o))
elseif implemented(observation, Tuple{p, a, sp})
return :(pdf(observation(p, a, sp), o))
else
return :(throw(MethodError(obs_weight, (p, a, sp, o))))
end
end

@generated function obs_weight(p, sp, o)
if implemented(observation, Tuple{p, sp})
return :(pdf(observation(p, sp), o))
else
return :(throw(MethodError(obs_weight, (p, sp, o))))
end
end

function implemented(f::typeof(obs_weight), TT::Type)
m = which(f, TT)
if length(TT.parameters) == 5
P, S, A, _, O = TT.parameters
reqs_met = implemented(observation, Tuple{P,S,A,S}) || implemented(obs_weight, Tuple{P,A,S,O})
elseif length(TT.parameters) == 4
P, A, S, O = TT.parameters
reqs_met = implemented(observation, Tuple{P,A,S}) || implemented(obs_weight, Tuple{P,S,O})
elseif length(TT.parameters) == 3
P, S, O = TT.parameters
reqs_met = implemented(observation, Tuple{P,S})
else
return method_exists(f, TT)
end
if m.module == ParticleFilters && !reqs_met
return false
else
true
end
end

0 comments on commit 693fd21

Please sign in to comment.