K X Au
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Save as template
    • 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 Create Help
Create Create new note Create a note from template
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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    $\newcommand{\E}{\mathbb{E}} \newcommand{\var}{\text{var}} \newcommand{\summation}[2]{\sum_{ #1 }^{ #2 } } \newcommand{\sumtoinf}[1]{\sum_{ #1 }^\infty } \newcommand{\texp}{\tau_{\exp}} \newcommand{\tint}{\tau_\text{int}}$ # Thinning vs Sampling Efficiency Consider a stationary process $\Psi \equiv \{\psi_t\} \equiv \{\psi(x_t)\}_{x_t \in X}$ with stationary distribution $\pi$ and let $\psi :X \to \mathbb{R}$ and $\psi \in L^2(\pi)$, i.e. the process has finite variance. The normalized autocorrelation at lag $t \geq 0$ is defined as $$\rho(t) \equiv \frac{C(t)}{C(0)} \propto \exp(-|t|/\texp) > 0, $$ where $C(t) \equiv \E_\pi[(\psi_s-\E_\pi[\psi_t])(\psi_{s+t} -\E_\pi[\psi_{s+t}])$ and $\texp$ is the exponential autocorrelation time. Then, the integrated autocorrelation time is defined as $$\tint \equiv \frac{1}{2} + \sumtoinf{t=1} \rho(t).$$ In MCMC, $\texp$ measures the time taken to reach stationarity. If we know it, Sokal advise to burn-in for about $20 \, \texp$. On the other hand, $\tint$ controls the Monte Carlo error of the estimates once stationarity has been achieved. Thinning a process by $k \geq 1$ (taking only every $k$-th value) is equivalent to $\rho(t)$ decaying with rate $\texp/k$, i.e. the process is sped up by a factor of $k$. The resulting integrated autocorrelation time then reads $$\begin{align} \tint(k, \texp) &= \frac{1}{2}+ \sumtoinf{t=1} \rho(k\,t) \\ &= \frac{1}{2} + \sumtoinf{t=1} K \exp(-k|t|/\texp) \\ &= \frac{1}{2} + \frac{K \exp(-k/\texp) }{1-\exp(-k/\texp)}\\ &= \frac{1}{2} + \frac{K}{\exp(k/\texp) - 1}.\\ %&\to \frac{1}{2} \quad \text{as} \quad k \to \infty. \label{tint}\\ \end{align}$$ $K$ is a constant of propotionality. The infinite sum is a (convergent) geometric series with ratio $\exp(-k/\texp) < 1$. In the $k \to \infty$ limit, $\exp(k/\texp) \to \infty$ so the infinite sum vanishes which implies $\rho(k\,t) \to 0$ for all $t \geq 0$, i.e. the thinned process becomes uncorrelated in the limit. ## MCMC Consider a chain of $N$ samples of variable $x \in X$ and a functional $\psi : X \to \mathbb{R}$. Throughout this text, we assume $k$ divides $N$ and define the effective sample size (ESS) of the chain $\Psi = \{ \psi(x_i), \cdots, \psi(x_N)\}$ as $$\text{ESS}(k, \texp) = \frac{\lfloor N/k \rfloor}{2 \, \tint(k, \texp)} \times k = \frac{N}{2 \, \tint(k, \texp)}.$$ The multiplication by $k$ compensates for the loss of samples due to thinning. In other words, we are interested of the effects of thinning on ESS due to $\tint$. For an independent sampler, i.e. $\texp =0$, we have $\tint(k, 0) = 1/2$ for all $k$, therefore it is unaffected by thinning and delivers a constant ESS of $N$ using our definition. #### One chain, thinned two ways Considering the same chain $\Psi$ as above and let us thin it in two ways, with $k_1$ and $k_2$ where $k_1 > k_2$. It follows from the definitions of $\tint$ and ESS that the more thinning, the higher the chain efficiency $$\frac{\texp}{k_1} < \frac{\texp}{k_2} \implies \tint(k_1, \texp) < \tint(k_2, \texp) \implies \text{ESS}(k_1, \texp) > \text{ESS}(k_2, \texp).$$ In practice, a correlated chain that is thinned with a sufficiently large $k$ is indistinguishable to a chain of independent samples,, where both will give an ESS of $N$. #### Two chains with distinct $\texp$ values, thinned the same Let us consider two chains $\Psi$ and $\Psi'$ with exponential autocorrelation times ${\texp}_{\Psi'} > {\texp}_\Psi$ and constants $K' > K$. If we thin them by $k$, and we have that $$\begin{align} {\texp}_{\Psi'} &> {\texp}_\Psi\\ \implies {\tint}(k, {\texp}_{\Psi'}) &> {\tint}(k,{\texp}_{\Psi}) \\ \implies \text{ESS}(k, {\texp}_{\Psi'}) &< \text{ESS}(k, {\texp}_{\Psi})\end{align}$$ for all $1 \leq k \leq N.$ In other words, a less efficient chain cannot surpass the ESS of a more efficient chain by thinning. ![](https://i.imgur.com/bOunOWu.png =350x220) ## What about cost? ![](https://i.imgur.com/fs0bK51.png =400x300) An ESS estimate is not meaningful without accounting for the associated cost. Let the cost to compute one sample be $c$ and the cost to evaluate $\psi$ be $c_\psi$. Then, in general a chain of $N$ samples thinned by $k$ costs $$\text{cost}(k, c) = Nc + \left \lfloor \frac{N}{k}\right \rfloor c_\psi.$$ We consider $c_\psi$ and $N$ as constants for simplicity. Naturally, when thinning by $k$, we evaluate $\psi$ fewer times but compute $N$ samples all the same. The ESS normalized by cost then reads $$ \begin{align} \text{E}(k, \texp, c) &\equiv \text{ESS}(k, \texp)/\text{cost}(k, c) \\ &= \frac{N/ 2 \, \tint(k, \texp)} {Nc + \left \lfloor \frac{N}{k}\right \rfloor c_\psi}\\ &= \frac{N/ 2 \, \tint(k, \texp)} {Nc + \frac{N}{k} c_\psi} \quad \text{(assume $k$ divides $N$)}\\ &= \frac{1 } {2 \, \tint(k, \texp) \times (c + c_\psi/k)}.\\ \end{align} $$ Let two chains $\Psi$ and $\Psi'$ have exponential autocorrelation times $\texp=\tau$ and $\texp'= z \, \tau$ and $z > 1$, constants $K' > K$, and cost per sample $C > 1$ and $1$ respectively. We assume $c_\psi = 0$ here, describing situations where cost of $c_\psi$ is negligible compared to cost of computing a sample ($c_\psi \ll C$ ) and/or $\psi$ is already evaluated during sampling. We are keen to find out if we can find some cost $C$ and thinning $k$ such that $\Psi$ is more efficient than $\Psi'$ before thinning but less efficient than $\Psi'$ after thinning. To describe the former case, we form the inequality $$\begin{align} \label{eq1} \text{E}(k=1, c=C, \texp=\tau) &> \text{E}(k=1, c=1, \texp=z\, \tau)\\ \left( 1 + \frac{2K}{\exp(1/\tau) - 1} \right) \times C &< \left( 1 + \frac{2K'}{\exp(1/z\, \tau) - 1}\right).\\ \end{align}$$ To describe the latter case, we form the inequality $$\begin{align} \text{E}(k=k, c=C, \texp=\tau) &< \text{E}(k=k, c=1, \texp=z\, \tau)\\ \left( 1 + \frac{2K}{\exp(k/\tau) - 1} \right) \times C &> \left( 1 + \frac{2K'}{\exp(k/z\, \tau) - 1}\right).\\ \end{align}$$ The first inequality says that $C$ must not be so high that $\Psi$'s cost dominates its faster autocorrelation decay causing it to be less efficient than $\Psi'$. The second inequality says that $C$ must not be so low that $\Psi'$ cannot catch up to $\Psi$'s efficiency by means of thinning. In all, as long as $C$ fulfils the first inequality, we can find out what $k^*$ is such that $\Psi'$ is more efficient than $\Psi$ after thinning by any $k \geq k^*$. Example: Let $\tau=10, z = 15$, $K = K' = 1$. Then the first inequality (former case) yields $1 < C < 14.9875679888.$ Indeed when $\tau$ is large, $\exp(1/\tau) \approx 1 + 1/\tau$ is a reasonable approximation and we need to fulfil $1 < C < z$. If $C < 1$, which means $\Psi$ is cheaper to run than $\Psi'$ to begin with, then $\Psi$ will forever be more efficient no matter the thinning (left figure). If $C > 15$, then $\Psi'$ will have been more efficient even without thinning and remain so for all $k$ (right figure). ![](https://i.imgur.com/eyp4cJ4.png =230x160) ![](https://i.imgur.com/Esh3Pt5.png =230x160) This means we need to keep the ratio of the costs to produce one sample must not exceed the ratio of the exponential autocorrelation times. If we take $C=10$, the second inequality gives $k^* = 25.86$. This means in order for $\Psi'$ to be more efficient than $\Psi$, we need to thin by $k \geq 26$. Specifically, at low values of $k$, $\text{E}_\Psi > \text{E}_{\Psi'}$ (left). When $k \geq 26$, $\Psi'$ overtakes $\Psi$ in terms of ESS per cost $\text{E}_\Psi < \text{E}_{\Psi'}$ (center). Both values saturate eventually (right). ![](https://i.imgur.com/Gvbk5lV.png =230x160)![](https://i.imgur.com/cK7Sgwz.png =230x160)![](https://i.imgur.com/eGh4uOd.png =230x160) ## Conclusion For estimation purposes, thinning does not bring any gain other than saving storage space. For the purpose of evaluating sampler performance, thinning should be avoided as it may give the false impression that a cheap but 'weak' sampler (e.g. Random walk Metropolis) performs better than an expensive but 'strong' sampler (e.g. Hamiltonian Monte Carlo) when thinned by a sufficiently large $k$. The intuition is that if we only look at samples that are far apart, it gives the weaker sampler time to decorrelate while many of the stronger sampler's already-decorrelated samples are ignored. However, the total costs are kept the same, therefore the strong sampler may end up performing worse when normalizing ESS by cost.

    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