Giter VIP home page Giter VIP logo

pf's Introduction

PF: a library for fast particle filtering!

DOI DOI

This is a template library for particle filtering. Templated abstract base classes for different particle filters are provided (e.g. the Bootstrap Filter, the SISR filter, the Auxiliary Particle Filter, the Rao-Blackwellized particle filter), as well as non-abstract (but indeed templated) base classes for closed-form filtering algorithms (e.g. Kalman Filter, Hidden Markov Model filter, etc.).

Once you have a certain model in mind, all you have to do is make it into a class that inherits from the filter you want to use.

Dependencies

This code makes use of the following libraries:

Also, your compiler must enable C++17.

Installation

Option 1: Install with CMake

git clone this Github repostory, cd into the directory where everything is saved, then run the following commands:

mkdir build && cd build/
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr/local
sudo cmake --build . --config Release --target install --parallel

You may subsitute another directory for /usr/local, if you wish. This will also build unit tests that can be run with the following command (assuming you're still in build/):

./test/pf_test

Note: for this to method work, you will need to install Catch2 "system wide" so that its *.cmake files are installed as well. To do this, click here.

Option 2: Drag-and-drop .h files

This is a header-only library, so there will be no extra building necessary. If you just want to copy the desired header files from include/pf into your own project, and build that project by itself, that's totally fine. There is no linking necessary, either. If you go this route, though, make sure to compile with C++17 enabled. Note, also, that this code all makes use of Eigen v3.3 and Boost v1.65.1. Unit tests use the Catch2 library.

Examples

Don't know how to use this? No problem. Check out the examples sub-directory. This is a stand-alone cmake project, so you can just copy this sub-directory anywhere you like, and start editing.

For example, copy to Desktop and have at it:

cp -r ~/pf/examples/ ~/Desktop/
cd Desktop/examples/
mkdir build && cd build
cmake ..
make

If there are no error messages, you will have an executable named pf_example in that same directory. Running it without command line arguments will prompt you for arguments and tell you how it can be used.

Contributing

Want to contribute to this project? Great! Click here for details on how to do that. We also have an "ideas list" you can check out here.

Paper

A full-length tutorial paper is available here, and a shorter introduction paper is available here.

Citation

Click the "DOI" link above. Or, if you're impatient, click 'here' for a Bibtex citation.

pf's People

Contributors

ghostvaibhav avatar noahzhoutianyuan avatar tbrown122387 avatar trb5me avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pf's Issues

C++17 or C++11 ?

The paper says C++11 but the README says C++17 - which one is it?

Conflicting pure virtual methods

a lot of the abstract base classes have conflicting pure virtual methods. All particle filter classes and FutureSimulator and ForwardMod templates might need to be organized to gel better with each other. Ideally the methods would be defined once, and would support inheriting from multiple classes.

the weight update formulas are not generic

The weight update formulas for many of the particle filters might be assuming that the resampling is beign conducted at every time point. For instance, the weights are usually updated from $1$ to $fg/q$. But if they don't start at $1$, then you can't just set the weight equal to $fg/q$, you have to multiply by it. And of course we do this in the log space...

switch tests to catch2

Instead of UnitTest++, might want to switch unit testing to catch2. At the very least, the new unit testing framework should support testing explicit function template specializations. Right now, unittest++ doens't seem to like those with their macros.

Add more compile time checks

Closed form filters might benefit from some compile-time checks to optimize filtering for special-cases. Also, the template parameter debug could allow more testing for more conditions (e.g. things that trigger NaNs) in the non-closed-form filters.

[question] Where and what is the "example related to tracking" mentionned in the ideas List

Hi ! first of all, thank you for the work put in developing this repository.

In the Ideas List it is mentioned that : "... there is another example related to tracking ...".

  1. However, in the "examples" directory I can't find this tracking example. They are all about stochastic volatility. Am I missing something?
  2. Also what is the state-space model used in this tracking example ? (state dynamic and observation model)

Thanks !

(btw it seems i can't add a label to the issue myself, therefore i added it in the title)

overload filter()

overload filter() with a version that takes only one argument, so that it doesn't constructor empty std::vectors at every time point.

write deterministic resamplers and samplers

If we had (nontrivial) deterministic resamplers and samplers, we could check every particle throughout every step of the filtering process in unit tests.

For an example of resamplers, always pick the current index, always pick the first, always pick the last. For an example of samplers, always increment by 1.0.

Easier way to interface with catch2?

The instructions in the README ask the user to install a few libraries (boost, eigen3, catch2). However, the requirement on catch2 is not explained well:

  1. Catch2's homepage explains that the package can be installed by just copying only the header file;
  2. People running any Ubuntu-based distribution will likely install it using sudo apt install catch;
  3. OTOH, the CMakeLists.txt provided by this package expects a few *.cmake files from the Catch2 distribution, which means that it requires Catch2 to be installed using a non-standard procedure. (No, apt install does not install these files where cmake can find them`.)

I see a few possible solutions:

  1. Include a copy of the Catch2 header file in the source (possible if Catch2's license is compatible with this one: IANAL, so I cannot give advice here). This would be the easiest and cleanest solution;

  2. Enable cmake to detect the presence of the Catch2 header file when the *.cmake files are not found

  3. Explain in the README the expected way to install Catch2.

(This issue was raised while carrying on the review for JOSS: openjournals/joss-reviews#2599.)

underflow problem

hmms should request log densities. working on a problem right now where all p(yt|xt) are zero and it messes everything up.

Split filter() into two functions

Consider rewriting filter() so that it makes use of two public functions: one to perform mutation and rewrighting, and the other to perform resampling. This added level of control would be useful for latency-sensitive applications that only need to make use of the results from the first stage. After that, resampling could be performed while there is plenty of downtime.

A challenge would be to ensure that a.) one cannot use both schemes simultaneously, and that if one opted for the more involved scheme, that errors would be thrown when the ordering was broken.

Or perhaps this would best be done with two separate class templates.

log probabilities in filtering for HMMs

In a HMM model, with the filtering updates, should the log-probabilities be retained instead of probabilities? We're not exponentiating anything, but should I still be worried about numerical underflow?

pf/include/pf/cf_filters.h

Lines 451 to 467 in 6f4fdfa

template<size_t dimstate, size_t dimobs, typename float_t>
void hmm<dimstate,dimobs,float_t>::update(const ssv &condDensVec)
{
if (m_fresh) // hasn't seen data before and so filtVec is just time 1 state prior
{
m_filtVec = m_filtVec.cwiseProduct( condDensVec ); // now it's p(x_1, y_1)
m_lastCondLike = m_filtVec.sum();
m_filtVec /= m_lastCondLike;
m_fresh = false;
} else { // has seen data before
m_filtVec = m_transMatTranspose * m_filtVec; // now p(x_t |y_{1:t-1})
m_filtVec = m_filtVec.cwiseProduct( condDensVec ); // now p(y_t,x_t|y_{1:t-1})
m_lastCondLike = m_filtVec.sum();
m_filtVec /= m_lastCondLike; // now p(x_t|y_{1:t})
}
}

reorder prior update and posterior updates for kalman

in the Kalman filter, you can change the order of the prior update and posterior update, so that the state priors will be available for forecasting. Right now, there are redundant, double computations if you're calling the forecast updates

get rid of unused argument warning

not sure how to do this...

statistically, these pure virtual methods need to allow for the requested arguments. The compiler warnings do get annoying though.

How can we override pure virtual functions? It would request that only one "version" of the function be defined?

Division by zero errors

I tried to build "pf" in VisualStudio and met "division by zero" errors due to the following line:
float_t maxOldLogUnNormWts(-1.0/0.0);
which can be found in bootstrap_filter.h and sisr_filter.h.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.