NCRL
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: Particle Filter - non-Gaussian distribution tags: wiki disqus: hackmd --- Particle Filter - non-Gaussian Distribution === **Author:** Teng-Hu Cheng **email:** tenghu@nycu.edu.tw **Date:** Nov. 2024 **Website:** https://ncrl.lab.nycu.edu.tw/member/ # 目錄 [toc] # Preliminary https://tomohiroliu22.medium.com/機率與貝葉氏機器學習-學習筆記系列-01-貝氏推斷-bayesian-inference-d81b01dc5c89 # Assumptions The following assumtion are made in this article: - The state transition matrix follows Markov property (in Section 2). - Posterior $P(x_k | y_k)$ under Gaussian distribution (in Section 3). # **Scenario** Here’s an example for **robot localization**: - A robot is navigating a 2D environment. - It has a laser rangefinder that measures the distance to walls. - The environment is known (map available). - The robot is uncertain about its position and orientation. ![1696398732497](https://hackmd.io/_uploads/SkT6N-EQke.png) # Architecture Below depicts the architecture of the algorithm ![architect](https://hackmd.io/_uploads/B1RUYUVmke.png=400x) # **1. Initial Setup** - **Particles**: Each particle represents a possible robot pose, $x$, $y$, $\theta$. - **Map**: The map provides the positions of walls. - **Sensor Model**: The laser sensor provides distance measurements to the nearest obstacle. # 2. **Prediction (State Transition Probability)** Below is a commonly used state transition models. For a 2D motion system with position $\mathbf{x}_k$: $$\mathbf{x}_{k} = \begin{bmatrix} x_{1k} \\ x_{2k} \\ \end{bmatrix} $$ The updated state becomes: $$\mathbf{x}_k = \mathbf{F} \mathbf{x}_{k-1} $$ where the state transition matrix $\mathbf{F}$ is defined as $$ \mathbf{F} = \begin{bmatrix} 0.7 & 0.8 \\ 0.3 & 0.2 \end{bmatrix}. \quad$$ Note that the elements in $\mathbf{F}$ can be transition matrix following Markov property. # 3. Update Now assume that the robot's laser rangefinder reports a distance of ==3 meters**== to the nearest wall. ## **3.1 Compute Weights** ### 3.1.1 non-Gaussian Observation Model Use a Gaussian likelihood function to compare the predicted sensor reading with the actual reading ($\mathbf{y}_k$=3 from Step 3.) and the state $\mathbf{x}_k$ (i.e., from the state transition in Step 2.): $$P(y_k | x_k) = \kappa - \frac{1}{2} ( y_k - \mathbf{C} \mathbf{x}_k)^{T} \mathbf{R}^{-1} (y_k-\mathbf{C} \mathbf{x}_k) $$ where: - $\kappa$ is some positive constant to make $P(y_k | x_k)$ positive. - $y$: Actual sensor reading (3.0 meters). - $y_{\text{pred}}=\mathbf{C} \mathbf{x}_k$: Predicted sensor reading for the particle. - $\mathbf{R}$: The covariance of the observation noise. **Note: [You can check out "normpdf" function in Matlab for details.](https://www.mathworks.com/help/stats/normpdf.html#d126e857153)** ### 3.1.2 Weights By using the observed output $\mathbf{y}_k$, and the weight $w_{k-1}^{(i)}$ computed at the previous time step $k-1$, calculate the intermediate weight update, denoted by $\hat{w}_k^{(i)}$, by using the density function of the measurement probability. $$ \hat{w}_k^{(i)} = p(\mathbf{y}_k \mid \mathbf{x}_k^{(i)}) \cdot w_{k-1}^{(i)}, \quad i = 1, 2, 3, \dots, N$$ where $i$ denotes the $i^{th}$ particles, and computing the Gaussian likelihood $p(\mathbf{y}_k \mid \mathbf{x}_k^{(i)})$ can be found in Section [3.1.1](#5.1-compute-weights). After all the intermediate weights $\hat{w}_k^{(i)}, i = 1, 2, 3, \dots, N$ are computed, compute the normalized weights $w_k^{(i)}$ as follows: $$ w_k^{(i)} = \frac{1}{\bar{w}} \hat{w}_k^{(i)}$$ where $\bar{w} = \sum_{i=1}^{N} \hat{w}_k^{(i)}.$ ### Multiple sensor fusion for State Estimation - [Sensor Fusion and Probabilistic Methods using Force and Vision](/mZi-r7LMTL2qflO7b9W0dw) ### 3.1.3 Find Pairs After finding weights in Section [3.1.2](#5.2-weights), we computed the set of particles for the time step $k$: $$\{(\mathbf{x}_k^{(i)}, w_k^{(i)}) \mid i = 1, 2, 3, \dots, N\}$$ # 4. Resample ## 4.1 Check the Conditions for Resample This is a resampling step that is performed only if the condition given below is **satisfied**. Calculate the constant $N_\text{eff}$: $$N_\text{eff} = \frac{1}{\sum_{i=1}^{N} \left( w_k^{(i)} \right)^2} $$ - ==If $N_\text{eff} < \frac{N}{3}$, then generate a new set of $N$ particles from the computed set of particles==: $$ \{ (\mathbf{x}_k^{(i)}, w_k^{(i)}) \mid i = 1, 2, 3, \dots, N \}^\text{NEW} = \text{RESAMPLE} \left( \{ (\mathbf{x}_k^{(i)}, w_k^{(i)}) \mid i = 1, 2, 3, \dots, N \}^\text{OLD} \right)$$ - ==If $N_\text{eff} > \frac{N}{3}$, the result is accepted.== Resample particles based on their weights: - High-weight particles are likely to be duplicated. - Low-weight particles are likely to be discarded. ### 4.2 Resample - Resampling is done based on the normalized weights ${w}_k^{(i)}$. - Particles with higher weights are more likely to be selected multiple times, while particles with very low weights are likely to be discarded. - [Example of resampling](/LEKChqMrR-qBh2vERVyDBg) ### 4.3 Generate the New Particle Set - Replace the old set of particles with the new set drawn during resampling. - Assign equal weights to all particles in the new set (e.g., $\tilde{w}_i = 1/N$). # **5. Results** After the sensor update, the particle filter is more confident about the robot’s pose, as particles now concentrate around states consistent with the sensor measurement. # References 1. [Particle Filter](https://aleksandarhaber.com/clear-and-concise-particle-filter-tutorial-with-python-implementation-part-2-derivation-of-particle-filter-algorithm-from-scratch) 2. [Joint Probability](https://www.youtube.com/watch?v=CQS4xxz-2s4) 3. [J. V. Candy, "Bootstrap Particle Filtering," in IEEE Signal Processing Magazine, vol. 24, no. 4, pp. 73-85, July 2007, doi: 10.1109/MSP.2007.4286566.](https://ieeexplore.ieee.org/document/4286566) 4. [Resampling Methods for Particle Filtering](https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=7079001) # Example 1 ## 1. Initial Setup Given a set of particles $\{(\mathbf{x}_0^{(i)}, w_0^{(i)}) \mid i = 1, 2, 3, \dots, N\}$, where the position of each particle represents a possible robot pose $\mathbf{x}_0^{(i)}$=($x$, $y$,$v_x$, $v_y$), where the state is defined as $$\mathbf{x}_k = \begin{bmatrix} x_k \\ y_k \\ v_{x_k} \\ v_{y_k} \end{bmatrix} $$ and the weight are equal, $w_0^{(i)}=1/N$. ## 2. Prediction By using the dynamics model, the predicted (a priori) state estimation becomes: $$\hat {\mathbf{x}}_k = \mathbf{F} \mathbf{x}_{k-1} + \mathbf{B} \mathbf{u}_{k-1} + \mathbf{w}_{k-1}$$ where the state transition matrix $\mathbf{F}$ and control input matrix $\mathbf{B}$ are defined as $$ \mathbf{F} = \begin{bmatrix} 1 & 0 & \Delta t & 0 \\ 0 & 1 & 0 & \Delta t \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}, \quad \mathbf{B} = \begin{bmatrix} 0.5 \Delta t^2 & 0 \\ 0 & 0.5 \Delta t^2 \\ \Delta t & 0 \\ 0 & \Delta t \end{bmatrix}$$ where $\mathbf{u}_{k-1}$ is the control input (i.e., acceleration) at the previous time step $k-1$, and $\mathbf{w}_{k-1} \sim \mathcal{N}(0, \mathbf{Q}$), where $\mathbf{Q}$ is the process noise covariance matrix. ## 3. Update ### 3.1 **Measurement Model** - linear model Defined the measurement model $\mathbf{y}_k=\mathbf{C} \mathbf{x}_k$ (linear model), where $$\mathbf{C}=\begin{bmatrix} 1 & 0 & 0 & 0 \end{bmatrix}$$ ### 3.2 **Intermediate Weights** By using the following relation between the predicted measurement in [3.1 Measurement Model]() and ==the observed output $\mathbf{y}_k=3$==, and the weight $w_{k-1}^{(i)}$ computed at the previous time step $k-1$, the intermediate weight update is calculated. $$p(\mathbf{y}_k \mid \mathbf{x}_k) = (2\pi)^{-\frac{1}{2}} \det(\mathbf{R})^{-\frac{1}{2}} e^{-\frac{1}{2} (\mathbf{y}_k - \mathbf{C} \hat {\mathbf{x}}_k)^\top \mathbf{R}^{-1} (\mathbf{y}_k - \mathbf{C} \hat {\mathbf{x}}_k)},$$ the likelihood can be computed, so that the intermediate weight $\hat{w}_k^{(i)}$ can be calculated as follows: $$ \hat{w}_k^{(i)} = p(\mathbf{y}_k \mid \mathbf{x}_k^{(i)}) \cdot w_{k-1}^{(i)}, \quad i = 1, 2, 3, \dots, N$$ ### 3.3 **Normalization** After all the intermediate weights $\hat{w}_k^{(i)}, i = 1, 2, 3, \dots, N$ are computed, compute the normalized weights $w_k^{(i)}$ as follows: $$ w_k^{(i)} = \frac{1}{\bar{w}} \hat{w}_k^{(i)}$$ where $\bar{w} = \sum_{i=1}^{N} \hat{w}_k^{(i)}.$ Then use [3.2.3 Find Pairs]() to find the new pairs $$\{(\mathbf{x}_k^{(i)}, w_k^{(i)}) \mid i = 1, 2, 3, \dots, N\}.$$ ## 4. Resample ### 4.1 Check conditions for resample Follows are the conditions to determine resample or accept. - If $N_\text{eff} < \frac{N}{3}$, then generate a new set of $N$ particles from the computed set of particles: $$\{ (\mathbf{x}_k^{(i)}, w_k^{(i)}) \mid i = 1, 2, 3, \dots, N \}^\text{NEW} = \text{RESAMPLE} \left( \{ (\mathbf{x}_k^{(i)}, w_k^{(i)}) \mid i = 1, 2, 3, \dots, N \}^\text{OLD} \right)$$ - If $N_\text{eff} > \frac{N}{3}$, the result is accepted. ### 4.2 Resample - Resampling is done based on the normalized weights ${w}_k^{(i)}$. - Particles with higher weights are more likely to be selected multiple times, while particles with very low weights are likely to be discarded. ### 4.3 Generate the New Particle Set - Replace the old set of particles with the new set drawn during resampling. - Assign equal weights to all particles in the new set (e.g., $\tilde{w}_i = 1/N$).

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully