Prerequisites. Direct starred prerequisites: chapter 174. No later core chapter depends on this route.
Take the model 𝗈𝖻𝗌=𝐻←𝖼𝗈𝗂𝗇(1/2);𝗌𝖼𝗈𝗋𝖾(𝗂𝖿 𝐻 𝗍𝗁𝖾𝗇 3 𝖾𝗅𝗌𝖾 1);𝗋𝖾𝗍𝗎𝗋𝗇 𝐻. Its unnormalized meaning is the finite measure {𝗍𝗍 ↦3/2, 𝖿𝖿 ↦1/2}, of total mass 2, and its posterior is {𝗍𝗍 ↦3/4, 𝖿𝖿 ↦1/4}.
Now run an inference procedure on it. Draw two particles from the prior, weigh them by the score, and resample: with luck both particles are 𝗍𝗍, and the procedure reports 𝗍𝗍 with frequency 1. With other luck it reports 3/4. The output is a random object, and no single run refutes or confirms anything. The question the chapter answers is not whether a run looks plausible but whether the procedure, as a transformation of representations, preserves the measure that the model denotes.
The obstruction is that the object preserved is not the one the procedure manipulates. A procedure manipulates particles, weights, and suspended computations; the model denotes a measure. A correctness statement must therefore say what measure a pile of weighted particles means, and then require every step of the procedure to leave that measure unchanged. Once meaning is a function from representations to measures, correctness becomes an equation that composes, and a large algorithm becomes a composite of small steps each of which satisfies it. This chapter builds the meaning functions, proves the equation for each step of a sequential Monte Carlo algorithm, and assembles them.
From chapter 174 this chapter uses the quasi-Borel category, its cartesian closed structure (proposition 174.8, proposition 174.10), and the probability monad 𝑃 with its laws (theorem 174.16, proposition 174.17); through it, the kernel interface 𝖯𝖬𝖪-bind of convention 172.27. No theorem about SFPC, its operational semantics, or the statistical powerdomain 𝑇 of convention 174.20 is used or transported: the system of this chapter is Ścibior et al.’s inference representations, a separate card, and no statement crosses between the two without a proved translation. The measures manipulated here are unnormalized finite measures, not probability measures, because scoring changes total mass.
Referenced from 2 locations
What a representation must mean
For a countable set 𝑋 let Mass 𝑋 be the set of finitely supported functions 𝑋 →ℝ+, the finite measures with finite support. Its operations are returnMass𝑥=𝛿𝑥,(𝑚≫=Mass𝑓)(𝑦)=∑𝑥𝑚(𝑥)𝑓(𝑥)(𝑦),flipMass={𝖿𝖿↦12,𝗍𝗍↦12},scoreMass(𝑟)=𝑟⋅𝛿∗. The total mass is |𝑚| =∑𝑥𝑚(𝑥).
Referenced from 4 locations
The three monad laws for Mass are the discrete instance of theorem 172.20, with the counting measure in place of a general measure and finite sums in place of integrals; example 172.21 carried out the identification.
Reading 𝗈𝖻𝗌 through definition 175.2, [[𝗈𝖻𝗌]]=flipMass≫=𝜆𝐻.(scoreMass(𝗂𝖿 𝐻 𝗍𝗁𝖾𝗇 3 𝖾𝗅𝗌𝖾 1)≫=𝜆∗.𝛿𝐻)=12⋅3𝛿𝗍𝗍+12⋅1𝛿𝖿𝖿={𝗍𝗍↦32, 𝖿𝖿↦12}. Total mass 2; normalizing gives {𝗍𝗍 ↦3/4, 𝖿𝖿 ↦1/4}. Every claim below about an inference procedure applied to 𝗈𝖻𝗌 is checked against these three exact rationals.
Referenced from 7 locations
A discrete inference representation is a sextuple T =(𝑇,return𝑇, ≫ =𝑇,flip𝑇,score𝑇,𝑚𝑇) consisting of a monadic interface (𝑇,return𝑇, ≫ =𝑇) on sets, elements flip𝑇 ∈𝑇 𝟐 and score𝑇 :ℝ+ →𝑇 𝟏, and a family of meaning functions 𝑚𝑇𝑋 :𝑇 𝑋 →Mass 𝑋 such that for all 𝑥 ∈𝑋, 𝑎 ∈𝑇 𝑋, 𝑟 ∈ℝ+ and 𝑓 :𝑋 →𝑇 𝑌, 𝑚𝑇(return𝑇𝑥)=𝛿𝑥,𝑚𝑇(𝑎≫=𝑇𝑓)=𝑚𝑇(𝑎)≫=Mass𝜆𝑥.𝑚𝑇(𝑓𝑥),𝑚𝑇(flip𝑇)=flipMass,𝑚𝑇(score𝑇𝑟)=𝑟⋅𝛿∗. The monadic interface is not required to satisfy the monad laws, and 𝑚𝑇 is not required to be natural.
Referenced from 6 locations
Let Enum 𝑋 =List(ℝ+ ×𝑋), with return𝑥=[(1,𝑥)],𝑎𝑠≫=𝑓=concat[scale(𝑟,𝑓𝑥)∣(𝑟,𝑥)∈𝑎𝑠],flip=[(12,𝖿𝖿),(12,𝗍𝗍)],score𝑟=[(𝑟,∗)], where scale(𝑟,𝑏𝑠) multiplies every weight in 𝑏𝑠 by 𝑟, and 𝑚Enum(𝑎𝑠)(𝑥) =∑{𝑟 ∣(𝑟,𝑥) ∈𝑎𝑠}. The four laws hold. For return and flip and score read the definitions. For bind, first note 𝑚(scale(𝑟,𝑏𝑠)) =𝑟 ⋅𝑚(𝑏𝑠), by summing the scaled weights, and then 𝑚(𝑎𝑠≫=𝑓)(𝑦)𝑑𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛=∑(𝑟,𝑥)∈𝑎𝑠𝑚(scale(𝑟,𝑓𝑥))(𝑦)𝑠𝑐𝑎𝑙𝑖𝑛𝑔=∑(𝑟,𝑥)∈𝑎𝑠𝑟⋅𝑚(𝑓𝑥)(𝑦)𝑑𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛175.2=(𝑚(𝑎𝑠)≫=Mass𝜆𝑥.𝑚(𝑓𝑥))(𝑦), the last step because the inner sum groups the elements of 𝑎𝑠 by their value component, which is exactly what 𝑚(𝑎𝑠) records.
Referenced from 2 locations
Let Term 𝑋 be the binary trees generated by Return(𝑟,𝑥) with 𝑟 ∈ℝ+ and Flip(𝑡𝖿𝖿,𝑡𝗍𝗍). Put return𝑥=Return(1,𝑥),score𝑟=Return(𝑟,∗),flip=Flip(Return(1,𝖿𝖿),Return(1,𝗍𝗍)), and let 𝑡 ≫ =𝑓 graft scale(𝑟,𝑓 𝑥) at each leaf Return(𝑟,𝑥). The meaning function is 𝑚(Return(𝑟,𝑥))=𝑟⋅𝛿𝑥,𝑚(Flip(𝑡0,𝑡1))=12𝑚(𝑡0)+12𝑚(𝑡1). The bind law is proved by structural induction on 𝑡, using the auxiliary equation 𝑚(scale(𝑟,𝑡)) =𝑟 ⋅𝑚(𝑡), itself an induction: at a leaf it is the definition, and at a node it is the linearity of the half-sum. At a leaf, 𝑚(Return(𝑟,𝑥) ≫ =𝑓) =𝑚(scale(𝑟,𝑓 𝑥)) =𝑟 ⋅𝑚(𝑓 𝑥) =(𝑟𝛿𝑥) ≫ =Mass𝜆𝑥. 𝑚(𝑓 𝑥); at a node, both sides split into halves and the induction hypothesis applies to each.
Referenced from 3 locations
Identities are inference transformations, and if 𝑡 :T →S and 𝑢 :S →U are inference transformations then so is 𝑥 ↦𝑢𝑋(𝑡𝑋(𝑥)).
Referenced from 3 locations
Proof of Lemma 175.8 — Transformations compose
Proof. 𝑚𝑇(𝑎) =𝑚𝑆(𝑡𝑋𝑎) =𝑚𝑈(𝑢𝑋(𝑡𝑋𝑎)). ◻
Let aggr𝑋 merge list entries with equal value components by summing their weights. Then 𝑚Enum(aggr𝑋(𝑎𝑠)) =𝑚Enum(𝑎𝑠), by induction on 𝑎𝑠: merging two entries (𝑟,𝑥) and (𝑠,𝑥) into (𝑟 +𝑠,𝑥) changes no value of the mass function. So aggr is an inference transformation. It is not a natural transformation: for the map 𝑔 :{0,1} →{ ∗}, aggregating before applying 𝑔 and after applying 𝑔 give lists of different lengths, and the square does not commute in Enum, although both sides have the same meaning. Naturality is not part of definition 175.7, and this is why.
Referenced from 2 locations
★☆☆ Represent 𝗈𝖻𝗌 in Enum, compute the resulting list, apply 𝑚Enum, and check the answer against example 175.3.
Referenced from 2 locations
★☆☆ Do the same in Term: display the tree and evaluate its meaning by the two clauses of example 175.6.
Referenced from 2 locations
Importance weighting
Before assembling an algorithm, one step must be derived rather than postulated: why weights appear at all. They come from a change of measure on a one-step model.
Let 𝜇 and 𝜈 be finite measures with finite support on a countable set 𝑋 with 𝜇(𝑥) >0 whenever 𝜈(𝑥) >0, and let 𝑤(𝑥) =𝜈(𝑥)/𝜇(𝑥) for 𝜇(𝑥) >0. Then for every 𝑓 :𝑋 →Mass 𝑌, 𝜈≫=Mass𝑓=𝜇≫=Mass𝜆𝑥.(𝑤(𝑥)⋅𝑓(𝑥)). In particular, drawing from 𝜇 and weighting each draw by 𝑤 represents 𝜈.
Referenced from 4 locations
Proof of Proposition 175.11 — Importance weighting on one step
Proof. Evaluate both sides at 𝑦: ∑𝑥𝜈(𝑥)𝑓(𝑥)(𝑦)=∑𝑥:𝜇(𝑥)>0𝜇(𝑥)𝜈(𝑥)𝜇(𝑥)𝑓(𝑥)(𝑦), and the omitted terms have 𝜈(𝑥) =0 by hypothesis. ◻
Take 𝜇 =flipMass, the prior, and 𝜈 the unnormalized posterior of example 175.3. Then 𝑤(𝗍𝗍) =3/21/2 =3 and 𝑤(𝖿𝖿) =1/21/2 =1, which are the two scores of the model. Proposition 175.11 says that sampling 𝐻 from the fair coin and attaching the weight 3 or 1 represents 𝜈 exactly; the weighted population [( 3/2,𝗍𝗍),(1/2,𝖿𝖿)] has 𝑚Enum equal to {𝗍𝗍 ↦3/2,𝖿𝖿 ↦1/2}, which is example 175.3. The score construct of the model is the importance weight; nothing further is postulated.
Referenced from 4 locations
Sequential Monte Carlo is assembled from three constructions applied to a base representation, and each is introduced by the single obstruction it removes.
advance :SusT →SusT and finish :SusT →T are inference transformations, and tmapSus𝑡 is one whenever 𝑡 is.
Referenced from 4 locations
Proof of Lemma 175.15 — Suspension steps preserve meaning
Proof. By definition 175.14 the meaning of a suspended computation is the meaning of the computation obtained by running it to completion, so 𝑚Sus𝑇(advance(𝑎))=𝑚𝑇(finish(advance(𝑎)))=𝑚𝑇(finish(𝑎))=𝑚Sus𝑇(𝑎), the middle equality because finish runs every remaining step, and running one step first leaves the same computation to run. For finish itself, the required equation is its definition. For tmapSus𝑡, the meaning of the transformed computation is computed by folding 𝑚𝑆 ∘𝑡 over the suspension structure, and 𝑚𝑆 ∘𝑡 =𝑚𝑇 by hypothesis. ◻
For 𝑛 ≥1, let spark 𝑛 ∈Pop𝑇𝟏 be the population of 𝑛 particles each carrying the value ∗ and the weight 1/𝑛, and let spawn(𝑛,𝑎) =spark 𝑛 ≫ =𝜆 ∗. 𝑎. Then 𝑚Pop𝑇(spark 𝑛) =𝛿∗ and spawn(𝑛, −) :PopT →PopT is an inference transformation.
Referenced from 5 locations
Proof of Lemma 175.16 — Spawning preserves meaning
Proof. The total measure of spark 𝑛 is 𝑛 ⋅1𝑛 𝛿∗ =𝛿∗, of mass 1. Hence 𝑚(spawn(𝑛,𝑎)) =𝛿∗ ≫ =Mass𝜆 ∗. 𝑚(𝑎) =𝑚(𝑎) by the left unit law of definition 175.2. ◻
Let 𝑥𝑠 be the finite weighted list [(𝑟1,𝑥1),…,(𝑟𝑘,𝑥𝑘)], let 𝑤 =∑𝑖𝑟𝑖, and let 𝑈 be the uniform measure on [0,1). When 𝑤 >0, put dwrand(𝑥𝑠,𝑢) =Take 𝑥𝑗 for the unique 𝑗 with 1𝑤∑𝑖<𝑗𝑟𝑖 ≤ 𝑢 < 1𝑤∑𝑖≤𝑗𝑟𝑖, and when 𝑤 =0 define dwrand(𝑥𝑠,𝑢) =Fail. Then 𝑤=0 ⇒ dwrand(𝑥𝑠,−)∗𝑈=𝛿Fail,𝑤>0 ⇒ dwrand(𝑥𝑠,−)∗𝑈=∑𝑖𝑟𝑖𝑤𝛿Take𝑥𝑖. Consequently, for a representation T with an element fail of meaning 0, the discrete weighted sampler dwsample(𝑥𝑠) =score𝑇(𝑤) ≫ =𝜆 ∗. (sample ≫ =𝜆𝑢. case dwrand(𝑥𝑠,𝑢)) has 𝑚𝑇(dwsample(𝑥𝑠)) =∑𝑖𝑟𝑖 𝛿𝑥𝑖.
Referenced from 6 locations
Proof of Lemma 175.17 — The discrete weighted randomiser
Proof. The intervals [1𝑤∑𝑖<𝑗𝑟𝑖,1𝑤∑𝑖≤𝑗𝑟𝑖) for 𝑗 =1,…,𝑘 partition [0,1) and have lengths 𝑟𝑗/𝑤, so the pushforward of 𝑈 assigns 𝑟𝑗/𝑤 to Take 𝑥𝑗; when 𝑤 =0 the function is constantly Fail. For the second claim, 𝑚𝑇(dwsample(𝑥𝑠)) =𝑤 ⋅∑𝑖𝑟𝑖𝑤𝛿𝑥𝑖 =∑𝑖𝑟𝑖𝛿𝑥𝑖, using the score law and the bind law of definition 175.4 and the first claim; the Fail branch contributes 0 because 𝑚𝑇(fail) =0. ◻
Let resample(𝑛,𝑎) =𝑎 ≫ =𝜆𝑥𝑠. spawn(𝑛,dwsamplePop𝑇(𝑥𝑠)). Then resample(𝑛, −) :PopT →PopT is an inference transformation.
Referenced from 6 locations
Proof of Proposition 175.18 — Resampling preserves meaning
Proof. Fix a population 𝑥𝑠 of total weight 𝑤. By lemma 175.17 the discrete weighted sampler on 𝑥𝑠 has meaning ∑𝑖𝑟𝑖𝛿𝑥𝑖, which is the meaning of the population 𝑥𝑠; by lemma 175.16, spawning 𝑛 copies of it leaves that meaning unchanged. The meaning function of Pop𝑇 satisfies the bind law of definition 175.4, so replacing the population inside 𝑎 by one of equal meaning leaves the meaning of the bind unchanged. ◻
Take the ordered population [(3/2,𝗍𝗍),(1/2,𝖿𝖿)] of example 175.12, of total weight 2. The normalized cumulative bounds are 3/4 and 1, so dwrand sends 𝑢 <3/4 to 𝗍𝗍 and 3/4 ≤𝑢 <1 to 𝖿𝖿. Feeding the two uniforms 1/8 and 7/8 produces the ordered unweighted population [𝗍𝗍,𝖿𝖿], each particle carrying weight 1/2 after the spark, and total weight 2 after the score in dwsample. Its meaning is 2 ⋅(12𝛿𝗍𝗍 +12𝛿𝖿𝖿) =𝛿𝗍𝗍 +𝛿𝖿𝖿, of total mass 2 — the same total mass as example 175.3, as proposition 175.18 requires, although the two measures differ: resampling preserves the mass function of the population as a random object, not the value of one draw.
Referenced from 3 locations
Let T be a sampling representation and let 𝑛,𝑘 ≥1. The composite smc𝑛,𝑘: (Sus∘Pop)T tmapSusspawn(𝑛,−) ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←→(Sus∘Pop)T (advance∘tmapSusresample(𝑛,−))∘𝑘 ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←→(Sus∘Pop)T finish ←←←←←←←←←←←→PopT is an inference transformation.
Referenced from 5 locations
Proof of Theorem 175.20 — The sequential Monte Carlo composite
Proof. Each factor is an inference transformation: spawning by lemma 175.16 and resampling by proposition 175.18, hence their images under the suspension transformer by lemma 175.15, which also covers advance and finish. A 𝑘-fold composite of inference transformations is one by lemma 175.8, and so is the whole composite. ◻
★☆☆ Verify lemma 175.16 for 𝑛 =3 by computing the meaning of spark 3 directly, and state what goes wrong if the sparked weights are 1 rather than 1/𝑛.
Referenced from 2 locations
★★☆ In lemma 175.17, compute dwrand(𝑥𝑠,𝑢) for 𝑢 =3/4 exactly, and show that changing the half-open intervals to closed ones would make the pushforward assign mass to two outcomes at once.
Referenced from 2 locations
★★☆ Let 𝑥𝑠 have total weight 0. Compute 𝑚𝑇(dwsample(𝑥𝑠)) and show that proposition 175.18 still holds, identifying the hypothesis 𝑚𝑇(fail) =0 where it is used.
Referenced from 2 locations
Suggested first pass.
None of these problems is a prerequisite for a later chapter. Begin with exercise 175.7, then exercise 175.8, then the practical project exercise 175.11.
★☆☆ For 𝗈𝖻𝗌, compute the unnormalized measure and posterior by exact enumeration and by importance weighting from the prior, and check that the two agree with example 175.3 and example 175.12.
Referenced from 3 locations
★★☆ Write the proof of proposition 175.18 for a population of two particles, displaying every use of the bind law of definition 175.4 and the exact rational weights at each stage.
Referenced from 3 locations
★★☆ Modify resample so that the score score𝑇(𝑤) inside dwsample is omitted. Compute the meaning of the resulting population for example 175.19 and identify the exact factor by which it differs from the correct value. State which line of the proof of lemma 175.17 the modification invalidates.
Referenced from 2 locations
★★☆ Give a two-score program in the fragment of section 175.1, display its representation in SusEnum, and compute advance once and finish, checking lemma 175.15 on it.
Referenced from 2 locations
★★★ Practical project.smc-meaning-checker Build a meaning-preservation checker for the finite fragment. It has three parts: an exact enumerator computing 𝑚Enum as a table of reduced rationals; an importance-weighting stage implementing proposition 175.11 from an explicitly supplied proposal; and a multinomial resampler implementing dwrand of lemma 175.17 driven by an explicit list of rationals in [0,1) instead of a random source.
The invariant to maintain is that every stage records both the population and its total weight, and that the checker compares the complete rational representation of the mass function before and after each stage, not merely its normalization.
The concrete result is the sequence of exact tables for 𝗈𝖻𝗌 =𝐻 ←𝖼𝗈𝗂𝗇(1/2); 𝗌𝖼𝗈𝗋𝖾(𝗂𝖿 𝐻 𝗍𝗁𝖾𝗇 3 𝖾𝗅𝗌𝖾 1); 𝗋𝖾𝗍𝗎𝗋𝗇 𝐻. The acceptance test is decidable and exact: exact enumeration and importance weighting must both print the unnormalized table {𝗍𝗍 ↦3/2, 𝖿𝖿 ↦1/2} and the posterior {𝗍𝗍 ↦3/4, 𝖿𝖿 ↦1/4}; the resampler applied to the ordered particles [(𝗍𝗍,3/2),(𝖿𝖿,1/2)] with the stream [1/8,7/8] must return the ordered unweighted population [𝗍𝗍,𝖿𝖿], compared as a list, in that order; and the checker must report the total weight 2 unchanged across the resampling stage. A large-sample display of frequencies is commentary only. This checker exercises the finite instance of theorem 175.20 and proves no part of it.
Referenced from 3 locations