Local sampler

Local sampler

Link to the source files:


Hierarchy of types

The events in the local settings are triples of the form (x,v,t). These can be encapsulated in the immutable Event type. Every node in the graph has a list of such events attached to it. For efficiency reasons, the list of event is not actually a list of Event but rather another type EventList which allows traversing the corresponding data structure efficiently.

The list of EventList (i.e. all events that have happened on the graph) is encapsulated in another type AllEventList.


The EventList type corresponds to what is stored by a single node of the factor graph. It contains the list of positions xs, the list of velocities vs and the list of times ts associated with that node.

The function getevent, getlastevent, pushevent!, getlocalsegment, samplelocalpath, quadpathpoly and pathmean all work on an EventList object.

In other words, an EventList is analogous to the Path object of the global sampler.


This is just a vector of EventList. It also keeps track of the types associated with each EventList. Indeed, each node may correspond to a variable of different dimensionality so these types make initialisation procedures simpler.

Auxiliary functions

Factor Graph

Hierarchy of types

All types are immutables (define the graph).


A Factor encapsulates


A FactorGraphStruct encapsulates

implicitly it also encapsulates

The function chainstruct defines a returns a FactorGraphStruct corresponding to a chain with a given number of nodes (variables).


A FactorGraph encapsulates

Auxiliary functions


That file has the same structure as that for the global sampler with one major LocalSimulation object encapsulating all the parameters of a given simulation.

The main loop uses a number of helper functions ls_* in order to make the logic appear more clearly. Focusing on the main loop for now, it should be clear that is centered around a priority queue.

(fidx, tbounce) = peek(pq)
if t < tref

So the minimum time is recovered from the priority queue as well as the index of the corresponding factor. Then, there is a check to see whether we are in the bouncing scenario (first branch) or the refreshment scenario (second branch).

Helper functions


The function ls_init initialises an AllEventList object corresponding to the graph as well as a priority queue.

Reshape, Random

Once a factor is selected, the operations are very similar to the global BPS. But once an event is generated, it is necessary to slice it according to the different nodes so that they all store the relevant portion of information. The ls_reshape function reshapes a generated object into the appropriate format.

The ls_random generates random numbers of the appropriate dimensions corresponding to an event list.


The ls_retrieve function is called to access a specific factor. For that factor it retrieves:

The interpolation is done following the method highlighted in the paper (recover the last event and follow the ray for required time).

Update Priority Queue

For a given factor, the ls_updatepq! updates the current priority queue by generating an event (possibly with thinning) for the required factor and storing it in the priority queue then returning that priority queue.

That function is usually called after a call of ls_retrieve: i.e. the interpolated position is recovered then correspondingly an event is generated and stored in the priority queue using ls_updatepq!.

Save update

Once a factor has been triggered and a new event computed, it is pushed in the relevant EventList objects using this ls_saveupdate! function which updates the all_eventlist object corresponding to the general simulation.


The function ls_refreshment triggers a refreshment for the current factor and the corresponding refreshment of the priority queue.