Skip to content

remove the unused argument df #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

remove the unused argument df #137

wants to merge 2 commits into from

Conversation

baggepinnen
Copy link
Owner

@baggepinnen baggepinnen commented Jun 3, 2024

df for APF is only used in smoothing, where it is used in the call

 logpdf(df, xb[m,t+1], f(xf[n,t],u[t],p,t), t)

to the custom method

@inline Distributions.logpdf(d::Distribution,x,xp,t) = logpdf(d,x-xp)

This PR thus has to

  1. Not remove the argument from the docs completely
  2. Require that a custom distribution or a custom logpdf function is supplied instead
  3. Update the beetle tutorial to show how this is done

@baggepinnen baggepinnen requested a review from Copilot May 27, 2025 09:26
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes the unused argument “df” from AdvancedParticleFilter and updates the code and documentation accordingly. Key changes include:

  • Removing the “df” argument from test and documentation examples.
  • Introducing the MissingDistribution type and updating constructors to default to it.
  • Adding an error check in the smoothing function to enforce that a proper noise density is provided for smoothing.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/runtests.jl Removed the unused “df” argument from AdvancedParticleFilter calls.
src/utils.jl Introduced the MissingDistribution type as a placeholder for a missing noise density.
src/smoothing.jl Added an error check to ensure that smoothing fails with a clear message if MissingDistribution is used.
src/PFtypes.jl Updated the constructor to remove the dynamics_density argument and set its default to MissingDistribution.
docs/src/index.md Updated documentation example to remove the “df” argument.
docs/src/beetle_example.md Modified plotting parameters for consistency in the beetle tutorial example.
Comments suppressed due to low confidence (2)

test/runtests.jl:296

  • There is a typo in the comment ('Simuate' should be 'simulate').
x,u,y = LowLevelParticleFilters.simulate(apf,T,du) # Simuate trajectory using the model in the filter

src/PFtypes.jl:178

  • Update the constructor documentation to clarify that a valid noise density must be supplied for smoothing since the default MissingDistribution() will trigger a runtime error in that context.
AdvancedParticleFilter(N::Integer, dynamics::Function, measurement::Function, measurement_likelihood, initial_density; p = SciMLBase.NullParameters(), threads = false, kwargs...) = AdvancedParticleFilter(N, dynamics, measurement, measurement_likelihood, MissingDistribution(), initial_density; kwargs...)

@@ -43,6 +43,7 @@ function smooth(pf::AbstractParticleFilter, xf, wf, wef, ll, M, u, y, p=paramete
N = num_particles(pf)
f = dynamics(pf)
df = dynamics_density(pf)
df isa MissingDistribution && error("In order to perform smoothing, you must provide a noise density for the dynamics. Use the constructor `AdvancedParticleFilter(N, dynamics, measurement, measurement_likelihood, dynamics_density, initial_density; kwargs...)` to do this")
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider using a more specific custom exception instead of a generic error to allow downstream code to catch and handle this condition in a more controlled manner.

Suggested change
df isa MissingDistribution && error("In order to perform smoothing, you must provide a noise density for the dynamics. Use the constructor `AdvancedParticleFilter(N, dynamics, measurement, measurement_likelihood, dynamics_density, initial_density; kwargs...)` to do this")
df isa MissingDistribution && throw(MissingDynamicsDensityError("In order to perform smoothing, you must provide a noise density for the dynamics. Use the constructor `AdvancedParticleFilter(N, dynamics, measurement, measurement_likelihood, dynamics_density, initial_density; kwargs...)` to do this"))

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant