sp-monte-carlo
    • 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 New
    • 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 Note Insights Versions and GitHub Sync 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags: `sampling` `em` `vi` `monte carlo` `one-offs` # Interacting Particle Systems for Expectation-Maximisation **Overview**: In this note, I will describe the problem of parameter estimation in latent variable models, and its resolution via the EM algorithm. I will then describe some particular implementations of the EM idea involving Monte Carlo approximations, particle methods, and other variations. ## Latent Variable Models Classical statistical models are often 'fully-observed': there is some parameter of interest $\theta$, an associated generative model $P ( x | \theta )$ which generates data $\{ x_i \}_{i = 1}^N$, and we are tasked with finding an estimate of the $\theta$ which generated our data. This is often handled via the principle of *maximum likelihood*, wherein one estimates \begin{align} \theta \approx \hat{\theta} = \arg\max_\theta \sum_{i = 1}^N \log P(x_i | \theta). \end{align} When we can write down $P(x | \theta)$ in closed form, one can then apply standard methods of numerical optimisation to compute $\hat{\theta}$. However, there are a number of statistical models for which this is *not* the case, due to the presence of unobserved *latent* (also 'hidden') variables. That is, for each observation $x_i$, there is some unobserved quantity $z_i$ such that the joint probability $P(x_i, z_i | \theta)$ is available, even though the marginal probability $P(x_i | \theta)$ may not be. Some standard examples include Mixture Models, Topic Models, Matrix Factorisation problems, and Hidden Markov (Chain) Models. From a modeling point of view, latent variable models of this form are often desirable, as they allow for richer descriptions of the data-generating process, accounting for heterogeneity, heavy tails, and other phenomena. However, this comes at a cost, in the sense that parameter estimation becomes more challenging. One could attempt a principle of 'maximum joint likelihood'. i.e. \begin{align} \left( \hat{\theta}, \hat{z}_{1:N} \right) = \arg\max_{\theta, z_{1:N}} \sum_{i = 1}^N \log P(x_i, z_i | \theta), \end{align} but this is typically a bad idea, as the freedom to optimise over the $z_i$ can lead to overfitting - the flexibility of including these additional variables in the model is essentially over-exploited. As such, it is more common to persist with the original principle of maximum (marginal) likelihood, and to focus on alternative strategies for solving the MLE problem. ## Surrogate Approaches to Maximum Likelihood Estimation A useful strategy in optimisation is to replace the direct optimisation of a hard function by the indirect optimisation of an easier function which admits the same optimisers. For instance, suppose that we are interested in maximising a complicated function $f : \mathcal{X} \to \mathbf{R}$, but we have access to the representation \begin{align} f(x) = \max_{y \in \mathcal{Y}} F(x, y), \end{align} where $F$ is a simpler function. One can then attempt to instead solve the problem of maximising $F$, and recover the solution to the original problem as a byproduct. This principle is useful in the context of latent variable models. Consider our likelihood function \begin{align} \log P(x|\theta) = \log \left( \int P(x, z| \theta) dz \right). \end{align} Using a change of measure, we can equally write this as \begin{align} \log P(x|\theta) = \log \left( \int Q(z) \cdot \frac{P(x, z| \theta)}{Q(z)} dz \right), \end{align} and using the concavity of $\log$ to apply Jensen's inequality demonstrates that \begin{align} \log P(x|\theta) &= \log \left( \int Q(z) \cdot \frac{P(x, z| \theta)}{Q(z)} dz \right) \\ &\geqslant \int Q(z) \log \left( \frac{P(x, z| \theta)}{Q(z)} \right) dz. \end{align} In fact, this expression can be written as \begin{align} \int Q(z) \log \left( \frac{P(x, z| \theta)}{Q(z)} \right) dz &= \log P (x | \theta) - \text{KL} \left( Q(z), P(z | x, \theta) \right), \end{align} from which the inequality follows immediately. Moreover, it furnishes us with the representation \begin{align} \log P (x | \theta) &= \max_Q \int Q(z) \log \left( \frac{P(x, z| \theta)}{Q(z)} \right) dz \\ &= \max_Q \,\mathbf{E}_Q \left[ \log \left( \frac{P(x, z| \theta)}{Q(z)} \right) \right], \end{align} which might be useful, in accordance with our earlier construction. Crucially, for many statistical problems of interest, the expectation $\mathbf{E}_Q \left[ \log P(x, z| \theta) \right]$ can be computed easily (as a function of $\theta$). With this in mind, one can then rewrite the MLE problem as \begin{align} \max_\theta \sum_{i = 1}^N \log P(x_i | \theta) &= \max_\theta \sum_{i = 1}^N \max_{Q_i} \mathbf{E}_{Q_i (z_i)} \left[ \log \left( \frac{P(x_i, z_i| \theta)}{Q_i (z_i)} \right) \right], \end{align} and so by defining \begin{align} \mathcal{F} \left( \theta, \{ Q_i \}_{i = 1}^N \right) &= \sum_{i = 1}^N \mathbf{E}_{Q_i (z_i)} \left[ \log \left( \frac{P(x_i, z_i| \theta)}{Q_i (z_i)} \right) \right], \end{align} one arrives at a joint maximisation problem which is often tractable, at least in the sense of being able to write down many of the terms in closed form. ## Algorithms for Maximising $\mathcal{F}$ ### Standard EM Algorithm Given the task of maximising $\mathcal{F}$, a fruitful strategy is that of alternating maximisation, i.e. iterating 1. Fixing $\{ Q_i \}_{i = 1}^N$, solve \begin{align} \max_\theta \sum_{i = 1}^N \mathbf{E}_{Q_i (z_i)} \left[ \log P(x_i, z_i| \theta) \right], \end{align} either in closed form or numerically. 2. Fixing $\theta$, solve \begin{align} \max_{\{ Q_i \}_{i = 1}^N} \sum_{i = 1}^N \mathbf{E}_{Q_i (z_i)} \left[ \log \left( \frac{P(x_i, z_i| \theta)}{Q_i (z_i)} \right) \right], \end{align} by setting $Q_i (z_i) = P(z_i | x_i, \theta)$. This scheme is known as the *Expectation-Maximisation* (EM) Algorithm, and has been highly influential since its inception in 1977. ### Monte Carlo EM A drawback of the standard EM algorithm is that it presupposes that $\mathbf{E}_{Q_i (z_i)} \left[ \log P(x_i, z_i| \theta) \right]$ can be evaluated easily as a function of $\theta$. In practice, this need not be the case, and so one might instead draw some samples from $Q_i$, and then maximise the resulting empirical approximation with respect to $\theta$. A slight weakness of this approach is that it requires the user to choose the number of samples to draw from $Q_i$. There are also strategies wherein one draws only a small number of samples from $Q_i$ at each step, but carries out the maximisation step with respect to a weighted sum of all such past samples; this is essentially the *stochastic approximation EM algorithm*. There are also variations in which one only samples from the $Q_i$ approximately, using e.g. Markov chain Monte Carlo methods. ### Variational EM An alternative approach is to restrict a priori to using classes of $Q_i$ such that the expectation $\mathbf{E}_{Q_i (z_i)} \left[ \log P(x_i, z_i| \theta) \right]$ can be handled easily. The first step of the EM algorithm then remains the same, but the second step is replaced by solving \begin{align} Q_i^* &= \arg\min_{Q_i \in \mathcal{Q}} \text{KL} \left( Q_i (z_i), P(z_i | x_i, \theta) \right), \end{align} where $\mathcal{Q}$ is some sufficiently nice class of approximating measures. One can also imagine fusing this method with Monte Carlo EM, for situations in which the expectation remains intractable, but sampling from $Q_i \in \mathcal{Q}$ is much easier than sampling from the globally-optimal $Q_i$. Equally, one can imagine deploying such a variational approximation within a Monte Carlo EM strategy which uses importance sampling. ### Gradient EM When the first step of the EM algorithm is not available in closed form, one may simply take a gradient step with respect to $\theta$, i.e. move in the direction of \begin{align} \nabla_\theta \left( \sum_{i = 1}^N \mathbf{E}_{Q_i (z_i)} \left[ \log P(x_i, z_i| \theta) \right] \right) &= \sum_{i = 1}^N \mathbf{E}_{Q_i (z_i)} \left[ \nabla_\theta \log P(x_i, z_i| \theta) \right], \end{align} either analytically, or by constructing an unbiased stochastic gradient estimate. There are also many other variants of EM which I will not address here. ## Expectation-Maximisation with Particle Systems Return now to our objective function: \begin{align} \mathcal{F} \left( \theta, \{ Q_i \}_{i = 1}^N \right) &= \sum_{i = 1}^N \mathbf{E}_{Q_i (z_i)} \left[ \log \left( \frac{P(x_i, z_i| \theta)}{Q_i (z_i)} \right) \right]. \end{align} Instead of optimising $Q_i$ analytically in an alternating fashion, one can consider approximating $Q_i$ with a particle system \begin{align} Q_i (dz_i) \approx Q_t^i (dz_i) = \frac{1}{M} \sum_{a = 1}^M \delta (z_t^{i, a}, dz_i) \end{align} and then optimising $\mathcal{F}$ nonparametrically, using ideas from Wasserstein gradient flows. Indeed, for fixed $\theta$, one can write that \begin{align} \mathcal{F} \left( \theta, \{ Q_i \}_{i = 1}^N \right) &= \sum_{i = 1}^N \text{KL} \left( Q_i (z_i), P(z_i | x_i, \theta) \right), \end{align} and so under the evolution of the appropriate Wasserstein gradient flow (with respect to the $Q_i$), the particles corresponding to $Q_i$ could be taken to follow the motion of an overdamped Langevin diffusion with invariant measure $P(z_i | x_i, \theta)$, i.e. \begin{align} \text{for}\, a \in [M], \quad dz_t^{i, a} = \nabla_z \log P \left( z_t^{i, a} | x_i, \theta \right) dt + \sqrt{2} dW_t^{i, a}. \end{align} Note that strictly speaking, from the WGF point of view, one could simulate using only a single particle, as there are no interactions in the above. However, when it comes to optimising $\mathcal{F}$ with respect to $\theta$, the presence of multiple particles should be helpful. In this direction, assume that $\theta$ follows an (ascending) gradient flow with respect to $\mathcal{F}$, i.e. \begin{align} \frac{d \theta_t}{dt} &= \frac{\partial \mathcal{F}}{\partial \theta} \left( \theta_t, \{ Q_t^i \}_{i = 1}^N\right) \\ &= \sum_{i = 1}^N \mathbf{E}_{Q_t^i (z_i)} \left[ \nabla_\theta \log P(x_i, z_i| \theta_t ) \right] \\ &= \frac{1}{M} \sum_{i = 1}^N \sum_{a = 1}^M \nabla_\theta \log P(x_i, z_t^{i, a}| \theta_t ). \end{align} One can then hope that $\theta_t$ will converge to a local maximum of $\log P (x_{1:N} | \theta)$, and that the $z_t^i$ will converge in distribution to the measure $P(z_i | x_i, \theta)$. Some of these results may hold at finite $M$, others only asymptotically. There are of course also many questions of implementation: how to discretise these dynamics, whether interactions between the particles may be beneficial, whether information-geometric preconditioning could improve convergence, and so on. These could collectively amount to a large difference in practical performance. While this approach is presented as nominally being distinct to the preceding EM approaches, there are of course key similarities. The evolution of the $\theta$ is based on gradient information, as in gradient EM, but also on an ensemble approximation to the objective function, as in Monte Carlo EM. ## Conclusion In this note, I have provided a brief derivation of the EM algorithm, outlined some of its conventional implementations, and sketched out a separate conceptual implementation based on gradient flows and particle methods. The extent to which one would expect the modifications included in this new method to provide practical benefits remains to be seen.

    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