MRPT / mrpt

:zap: The Mobile Robot Programming Toolkit (MRPT)
https://docs.mrpt.org/reference/latest/
BSD 3-Clause "New" or "Revised" License
1.95k stars 631 forks source link

Discussion on strategies towards multi-threading particle filter algorithms #610

Open jlblancoc opened 6 years ago

jlblancoc commented 6 years ago

(Follow-up from mrpt-users mailing list here)

Things to bear in mind:


virtual void | prediction_and_update_pfStandardProposal (const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, const bayes::CParticleFilter::TParticleFilterOptions &PF_options)
-- | --
  | Performs the particle filter prediction/update stages for the algorithm "pfStandardProposal" (if not implemented in heritated class, it will raise a 'non-implemented' exception). More...
 
virtual void | prediction_and_update_pfAuxiliaryPFStandard (const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, const bayes::CParticleFilter::TParticleFilterOptions &PF_options)
  | Performs the particle filter prediction/update stages for the algorithm "pfAuxiliaryPFStandard" (if not implemented in heritated class, it will raise a 'non-implemented' exception). More...
 
virtual void | prediction_and_update_pfOptimalProposal (const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, const bayes::CParticleFilter::TParticleFilterOptions &PF_options)
  | Performs the particle filter prediction/update stages for the algorithm "pfOptimalProposal" (if not implemented in heritated class, it will raise a 'non-implemented' exception). More...
 
virtual void | prediction_and_update_pfAuxiliaryPFOptimal (const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, const bayes::CParticleFilter::TParticleFilterOptions &PF_options)
  | Performs the particle filter prediction/update stages for the algorithm "pfAuxiliaryPFOptimal" (if not implemented in heritated class, it will raise a 'non-implemented' exception). More...

Let's use this thread to further discuss possible strategies on how to address this feature.

jolting commented 6 years ago

I think to start with the particle filter algorithms could be a little bit more generalized and the particle filter algorithms need to be separated into their own classes.

Here's a start of some of my ideas: https://github.com/jolting/mrpt/tree/refactorPF

jlblancoc commented 6 years ago

Great! I'll merge in an experimental branch to continue testing there, ok?

Here it is: https://github.com/MRPT/mrpt/tree/dev-PF-refactor

jolting commented 6 years ago

Ok. I broke the python bindings. I can fix them later if you like those changes.

jlblancoc commented 6 years ago

No problem for the bindings. I'll take a closer look at the changes (the entire set of classes for PF is really intertwined and a bit intricate, honestly...) and come back. Will not be today or tomorrow! ;-)

jlblancoc commented 6 years ago

Hmm... after a first "in depth" (not enough, tough) look at the changes, I have some comments:

https://github.com/MRPT/mrpt/blob/dev-PF-refactor/libs/base/include/mrpt/bayes/CParticleFilter.h#L208-L218

https://github.com/MRPT/mrpt/blob/dev-PF-refactor/libs/base/include/mrpt/bayes/CParticleFilter.h#L214-L218

I couldn't build it for testing, so perhaps I'm wrong. Anyhow, allowing such a signature without PF_ALGORITHM is mandatory if algorithms are to be selected dynamically via a configuration file, etc. I imagine writing the impl. of this version of executeOn<> with a switch inside, calling executeOn<PFCapable,PF_Algorithm>() for each PF_Algorithm... or does exist any alternative?

jolting commented 6 years ago

I probably should have called those two separate things executeOn picks the one set by PF_options and which calls a specific executeOn<PARTICLEFILTERCAPABLE, PF_ALGORITHM>.

The one template version needs to be pushed down into the individual classes and called something else executeOn

I realized too late that template instantiation is probably overkill for this. I was jumbling things around trying to get things to compile and I went a little crazy.

https://github.com/MRPT/mrpt/blob/7c68726716dcfa0f333693046e5d51c71c367dbc/libs/slam/src/slam/CMonteCarloLocalization2D.cpp#L243 https://github.com/MRPT/mrpt/blob/7c68726716dcfa0f333693046e5d51c71c367dbc/libs/slam/src/slam/CMonteCarloLocalization3D.cpp#L198

I think also about a factory pattern to fix this.

The two template version seems powerful though. You can use your own version of the algorithm. If you made processActionObservation templated as well you could have as many variations of particle filters as you want and the algorithms would be fairly loosely coupled. Hopefully this can improve reuse. https://github.com/MRPT/mrpt/blob/c7ed37ff72972e48fbb253d7410e8d9740effc13/libs/slam/src/slam/CMetricMapBuilderRBPF.cpp#L108