Sampling and Fractional Updates¶
Problem¶
An iteration of 2D or 3D alignment costs O(N x R x nrots) for N
particles and R references. Two different subsampling ideas reduce that
cost, and they must not be confused:
- the outer problem: which particles are updated in this iteration;
- the inner problem: for an updated particle, which of the
R x nrotscandidate poses are evaluated, and how one of them is chosen.
The outer problem is a stochastic-gradient idea: a fraction of the data gives a cheaper but noisier update of the references. The inner problem is importance sampling over poses. This chapter covers both, the assignment that consumes the inner samples, and the rule that blends a partial update into the running reference estimate.
Outer sampling¶
Let N_active be the number of active particles (state above zero) and
update_frac the requested fraction. The subset size is
n = min(N_active, max(1, round(update_frac * N_active))).
Each particle carries two counters: updatecnt, the number of times it has
been updated, and sampled, the last sampling round that selected it. The
n particles are chosen by one of these policies:
- random: uniform without replacement. The first stage of
solve2Ddraws its subset this way once and keeps it for all of the stage's iterations. - count-tiered (
balance=none, the default ofrefine3Dand of the latersolve2Dstages): take every particle at the lowestupdatecnt, then the next tier, until the budget is filled; within the tier at the cutoff, draw uniformly. This is lowest-count-first rather than a weighted draw, so coverage of the dataset is as even as possible. -
class units (
balance=classorbalance=cavg;classis the default ofsolve3D,refine3D_states, andclassify3D_refs): share the budget over sampling units built from the selected 2D classes. Each unit is one selected class, with its active particles in index order. -
Under
class, every unit gets an equal share, capped at its population, so rare views are sampled more often than proportional sampling would. - Under
cavg, the class averages are first clustered intonclustgroups (default 20) by average linkage on their rotation-, shift-, and mirror-invariant correlation between 30 and 6 A, so that a preferred view split over many classes becomes one group. A group holding fewer than 2.5% of the particles keeps merging into its nearest group, so outlier classes do not become groups of their own. The budget is then shared equally over the groups and, within a group, equally over its units, each capped at its population; the remainder of a split goes to the least-updated units. The group level keeps the views balanced, and the unit level keeps the classes inside a view, which may be different conformational states, on an equal footing.
In both modes the count-tiered rule applies inside each unit, over the
whole class: no per-particle score decides who is drawn, except in the draw
of single-state solve3D's sticky subset (below).
- reproduce: reuse exactly the particles whose sampled equals the
current maximum. This lets a probabilistic iteration choose the subset once,
on the master, and have every part's pipeline (the table rows, the draws, the
matching and the reconstruction) act on the same particles. The draw is
keyed on the run's seed, the pass, the iteration and the particle, so the
subset does not depend on the number of parts or threads.
- sticky (refine3D_states, and stages 1-4 of single-state solve3D,
from whatever stage the run enters at):
the set drawn at the first iteration of a frequency block or stage is kept
for the whole block; with sticky_sampling=keep a stage keeps the previous
stage's set from its first iteration (solve3D stages 2-4 keep stage 1's).
Later iterations reproduce it and advance its counters, so that state labels
and poses converge on one set. solve3D draws its set with
sticky_sampling=best: the same quotas, but each unit's particles with the
best 2D objective values (ptcl2D corr), whatever their update counts; the
free draws from stage 5 use no score. Every single-state fractional
solve3D run holds this set from its first stage through stage 4 and trails
from stage 5; multi-state runs hold none.
- missing: every active particle that has never been updated. This is the
terminal coverage pass.
Nothing derived from the 3D maps, the poses, or the projection directions decides which particles are sampled. The maps carry bias, and a sampler driven by them would feed that bias back; the 2D class averages are evidence independent of the maps.
With unequal quotas, visiting every particle once takes
max over units of ceil(pop / quota) iterations rather than
1 / update_frac, because a unit larger than its share takes longer. This
sweep length is printed in a table of the units before the first stage, and
nothing is adjusted automatically to meet it.
In solve3D, a target nsample above 90 percent of the active particles
switches to full updates (solve2D switches at 99 percent). Full updates
select every active particle and disable the blending described below: that
close to the full set, subsampling would save little and add noise.
Inner sampling: the probability table¶
Before a particle's hard assignment, the matcher fills its row of losses
against every reference j: in 3D the nstates x nspace projections, in 2D
the active classes. The rows are filled batch by batch inside the matcher's
pipeline, each batch's rows drawn from and released before the next (no table
across batches, no file); every random draw below is keyed on the seed, the
pass, the iteration, the particle and the draw. For each particle:
- a common shift seed is found by shift-only optimization at the particle's previous pose;
- every reference is scored at that shift over all in-plane rotations, and one in-plane rotation is drawn from the row's tempered posterior over all of them (below);
- the best
K_refreferences are refined again in shift (below).
For the Euclidean objective, the loss d is the whitened negative
log-likelihood, d = -log(score), normalized by the particle's weighted
power: one nat is 1/T_i of it with
T_i = pi wsqsum_i / (2 pftsz),
the particle's noise temperature, several hundred to a thousand on PfCRT
(measured 2026-10-22, doc/implementation_notes/completed/pose_marginalization.md,
sections 3 and 14). A draw from n candidates uses
w_j = exp[-beta T_i (d_j - d_min)], p_j = w_j / sum_l w_l,
the tempered posterior p^beta with beta = prob_beta (default 0.3, for
small membrane proteins; 1 is the physical posterior; below one hotter). No
truncation: the exploration of the draw is the data's width, not a fixed
angular window. The tables refuse the correlation objective. One candidate
is drawn and committed as a hard assignment. A particle is never spread
over several orientations in proportion to their probabilities, as it is
in expectation-maximization refinement.
The randomness of the in-plane draw is load-bearing: it is what keeps the
direction assignment diverse against the references' memory of where each
particle was last put (the self-reinforcement of the same note, 1-7 nats
on the own half). Scoring every entry at its best grid rotation instead
(K_inpl = 1, tried as a switch on 2026-10-23 and removed again) takes the
search noise out as intended but traps the run: 5 of 10 PfCRT restarts
ended near 7 A against 4.0-4.6 A for the other 5 and 4.0 A for the draw
(PfCRT_posterior/greedy_inpl). The in-plane angle a particle ends with is
the continuous refinement's in either case; what the draw buys is the
diversity of the direction assignment.
Before the posterior (until 2026-10-24) the in-plane rotation was drawn by
the untempered softmax exp[-(d_j - d_min)] over the best K_inpl
rotations, the truncation derived from an angular threshold,
K = min(n, max(1, floor(athres * n / 180))) with
athres = min(prob_athres, mean angular change of the last iteration) and
prob_athres 10 degrees: since T_i is hundreds, a uniform draw over a
random rotation within athres of the best (on PfCRT more than a nat worse
than the best grid pose for 17-27% of the particles; the note, section 14),
which athres shrinking with the measured in-plane change annealed as the
alignment settled. The tables' fills no longer use it; the SHC strategies
of the early 2D stages keep their own samplers.
The refined set is a search budget, not a posterior quantity. The dense
3D fill refines the K_ref = min(prob_athres, mean pose change of the last
iteration) x nspace / 180 lowest losses of the row (calc_num2sample; 10
degrees gives nspace/18 while the poses move, a few percent of nspace as they
settle), the neighbourhood table the npeaks_inpl lowest per state, the 2D
dense table a tenth of the classes (at most npeaks_inpl) and the sparse
table its annealed smpl_ncls. Sizing it by the row's own posterior mass
instead (tried 2026-10-25: the entries holding 99% of the tempered mass, each
at least 1%, the mode always) broke PorF: stages 3 and 4 a little worse,
stage 5 at 7.8-8.0 A against 4.9-6.8 A in ten restarts (the note, section 19,
item 10). The row's losses are conditional on the one seed shift and the
previous band, so after a band jump the posterior is sharp around poses
fitted at the coarser band, and only refining many candidates lets the shift
search re-rank them: the refinement is the search, and its breadth must come
from the pose uncertainty (what the pose-change term measures), not from the
sharpness of a row that has not been refined yet. Nor does a larger budget
help: at 20 and 40 degrees PorF was worse, because every refined wrong
reference gets a chance gain from fitting its shift to noise and the largest
of many such gains beats the true pose for a few percent of the particles
(the bench histogram of where the refined argmin sat in the unrefined
ranking is flat deep down: winners by chance). shift_prior=yes is the
experiment against that: the tables' shift searches carry a Gaussian prior
on the shift's distance from the seed, width the previous iteration's shift
variance, so a wandering wrong reference pays what it was gaining and the
true one near its seed pays nothing (the note, section 19, item 11).
Assignment¶
The rows are consumed particle by particle (2026-10-23; the only assignment
since 2026-10-24, when the class-balanced frontier was deleted from every
table): each particle's reference is one draw from its own row by the
tempered posterior above, within the state of its closest reference, T_i
kept with the row by the fill. Particles are assigned to
references; no reference is forced to be populated, and no particle takes
an argmin. The stage then ends on the resolution exit or its budget, not on
the pose overlap (the committed pose is a draw and stable from a stage's
first iterations). The 2D class assignment is the same per-particle draw
over the row (solve2D_policy.md); the neighbourhood tables follow the rule
on their candidate store (the state of the closest valid candidate, one
draw within it), the current pose among the candidates so that the draw is
an acceptance step and not a forced move.
The temperature is the band's: T_i grows with the number of Fourier
components the stage searches, so at solve3D's stages 1-2 (rings 2-5 on a
137 A box) T is about 33 where it is hundreds from stage 3 on, and the
physical posterior is flat there and a delta later; the ladder is itself a
cooling schedule. In ten streptavidin restarts at beta 0.3, with the current
pose missing from the shc neighbourhood's candidates, stages 1-2 did nothing
and stage 3 solved the structure from scratch (the note, section 19); the
incumbent is a candidate since, and whether the early stages also need a
colder draw is the open measurement (the prob_beta_ini override of stages
1-2 was removed 2026-10-29 with the other tempering inputs). prob_beta is the
search's annealing knob, since at the physical temperature the posterior
over directions is a delta once the map has any resolution (n_eff 1.0-1.2)
and the map-pose alternation then stops at the nearest fixed point (section
17 of the note). A refine3D run with prob_beta_end searches flat at
prob_beta until neither FSC 0.5 nor FSC 0.143 gained on the previous
iteration, then anneals geometrically to prob_beta_end over the next five
iterations and ends (the annealing tail); solve3D does so on its last
stage, to 1, so the final map is weighted at the physical posterior. The
design and its measurements are in
doc/implementation_notes/completed/pose_marginalization.md.
The balanced frontier, deleted¶
Until 2026-10-24 the tables consumed the table as one global assignment
problem: for each reference, sort its particles by d_ij; each reference
keeps a head, its best still-unassigned particle; until every particle is
assigned, draw one reference from the softmax over the head losses
(truncated to the best K heads), give it its head particle and advance
the heads. Every reference competed at every step and a winning reference
took exactly one particle, so populations evened out without quotas: a
stochastic greedy matching between particles and references, which forced
every reference to be populated whether or not any particle's data put it
there. Hans, 2026-10-24: methodologically it makes no sense; particles are
assigned to references, not references to particles. It was deleted from
the dense 3D table, the 2D tables and the neighbourhood table, with its
samplers and reference tests (the note, section 19).
Neighborhood variants (prob_neigh) restrict which references are scored
for each particle: a stochastic subset (shc, snhc), the projection
directions within athres_cont of the previous one (geom), or
the best npeaks coarse cells pooled across states (state); the cells are
defined in refine3D. The assignment is the same in every
case.
Blending partial updates¶
The requested update_frac is only a target. Restoration uses the realized
fraction of each 2D class or 3D state k,
rho_k = n_k / N_k,
where n_k counts the active members sampled in the current round and N_k
the active members that have been updated at least once (updatecnt > 0).
Population rule. Every carried set records M_k, the population its sums
represent. With u the applied update weight (u = rho_k unless
overridden), the assembly step blends
A_new = (u/rho_k) A_current + (1 - u) (N_k/M_k) A_previous, M_k <- N_k,
so the sampling mass after the blend is u N_k + (1 - u) N_k = N_k, the
represented population, whatever joined or left the group. With an unchanged
population (M_k = N_k), this reduces to the familiar
(u/rho_k) A_current + (1 - u) A_previous. The rule keeps the mass right,
not the membership: old contributions are removed in proportion, not
particle by particle.
2D. Class accumulators are carried forward with weight (N_k - n_k)/M_k,
the population rule with u = rho_k
(Refine2D).
3D trailing reconstruction. A persistent chain stores, per state and
half, the unregularized Fourier numerator and sampling density at the mass of
the population it represents. With f the realized fraction of the state
(rho_k above) and u the desired update weight (u = f unless
overridden), the blend in the accumulator domain is
A_new = (u/f) A_current + (1 - u) (N/M) A_previous,
applied identically to the numerator and the density. The factor u/f
rescales the partial sums so that the current data carry weight u while
the total sampling mass is that of the represented population:
(u/f)(f D) + (1-u)(N/M) M d = D for a per-particle density d and
D = N d. One density division after the blend therefore restores a
correctly normalized map. Blending the accumulators rather than restored
volumes keeps the FSC computed on the blended halves valid, because both
halves are still ratios of sums; finished, restored half maps are never
blended.
When a blend is due but no chain exists yet, the iteration does not blend.
The chain is seeded with the current partial sums scaled by 1/f, so that it
carries the mass of the full population, and the current sample alone is
restored and used for that iteration. The chain then fills over about 1/f
iterations. The override of u (ufrac_trec) applies to single-state runs
only; multi-state runs always use the realized fraction of each state.
Because the blend is an exponential moving average, previous contributions
decay geometrically, and the reference at iteration t is a weighted sum of
the partial reconstructions of roughly the last 1/u iterations. This is
why fractional 3D refinement converges at all: each partial reconstruction
on its own would be too noisy to align against.
Guards¶
- Full-update mode selects every active particle and disables trailing.
- Restoration and volume assembly read
sampledbut never choose a subset. - Final maps and final class averages require coverage when staged
fractional updates left any active particle unseen:
solve2Dends with a dense all-particle pass, and 3D runs end with the missing-update pass.
Implementation¶
- Sampling policies:
src/main/ori/simple_oris_sampling.f90; dispatch insrc/main/strategies/search/simple_matcher_smpl_and_lplims.f90. - Sampling units, class-average groups, and the unit table:
src/main/strategies/search/simple_view_partition_sampling.f90. - Probability tables and assignment:
src/main/strategies/search/probabilistic/simple_eul_prob_tab*.f90. - Trailing blend:
src/main/commanders/simple/simple_commanders_rec_distr.f90; the distributed PCG chain insrc/main/strategies/parallelization/simple_rec3D_pcg_strategy.f90. - The batch pipeline (the rows, the draws and the commit per batch):
src/main/strategies/search/simple_strategy3D_matcher.f90andsimple_strategy2D_matcher.f90; the master's sample draw:src/main/strategies/parallelization/simple_refine3D_strategy.f90andsimple_refine2D_strategy.f90. - Policy:
doc/policies/importance_sampling_fractional_update_policy.md; the design:doc/implementation_notes/completed/prob_align_batch_pipeline.md.