Packet Selection¶
Implements packet selection with a selection operator of choice. The following operators are supported: sample-average, sample-median, sample-minimum, sample-maximum, sample-mode, and exponentially-weighted moving average (EWMA).
- class ptp.pktselection.PktSelection(N, data)[source]¶
Packet Selection
- Parameters
N – Observation window length
data – Array of objects with simulation data
- process(strategy, drift_comp=True, vectorize=True, batch=True, batch_size=4096, calc_drift=True, recursive=True)[source]¶
Process the observations
Using the raw time offset measurements, estimate the time offset using sample-average, EWMA, sample-median, sample-minimum, sample-maximum, or sample-mode over sliding windows of observations.
Note
Drift compensation:
If drift compensation is enabled, use vector of drifts to compensate the differences of timestamps along the observation window.
Note that:
\[x[n] = t2[n] - (t1[n] + d_{ms}[n])\]\[x[n] = (t3[n] + d_{sm}[n]) - t4[n]\]so that
\[t2[n] - t1[n] = +x[n] + d_{ms}[n],\]\[t4[n] - t3[n] = -x[n] + d_{sm}[n]\]However, x[n] can be modeled as:
\[x[n] = x_0 + drift[n],\]where the drift[n] term is mostly due to frequency offset, which sometimes can be accurately estimated (especially for high quality oscillators).
Using this model, and if the drift is compensated, it can be stated that:
\[t2[n] - t1[n] - drift[n] = +x_0 + d_{ms}[n],\]\[t4[n] - t3[n] + drift[n] = -x_0 + d_{sm}[n]\]In the end, this means that drift-compensated timestamp differences will lead to an approximately constant time offset corrupted by variable delay realizations. This is the ideal input to packet selection operators. Once the operators process the drift-compensated timestamp differences, ideally its result would approach:
x_est -> x_0
To complete the work, the total (cumulative) drift over the observation window should be re-added to the estimate, so that it approaches the true time offset by the end of the observation window (while x_0 is the offset in the beginning):
x_est += drift[N-1]
For the operators that process time offset observations x_est[n] directly, the drift can be similarly removed prior to the selection operator and the sum of the drift re-added to the final result.
Note
Vectorization and batch processing:
There are two types of packet-selection processing in this function: sample-by-sample and window-by-window. All window-based processing algorithms also have corresponding vectorized implementations. The difference on the vectorized implementations is that, instead of processing one window at a time, they process several windows at once, i.e. process a matrix with windows stacked on top of each other. This is referred to as matrix-by-matrix processing.
Depending on the dataset size, it may become infeasible to stack all available windows and process the resulting matrix at once. This could consume too much memory. To overcome this, this function relies also on batch processing. In this case, the vectorized implementation is still used, but the number of windows that are processed at once is limited. They are capped to the batch size.
In contrast, the two methods (moving average methods) that are sample-by-sample cannot benefit from vectorization. The reason is that they are recursive, and hence must be computed sample by sample.
- Parameters
strategy – Select the strategy of interest: “avg”, “ewma”, “median”, “min”, “max”, or “mode”
drift_comp – Whether to compensate drift of timestamp differences or time offset measurements prior to computing packet selection operators.
vectorize – Whether to use vectorized implementation of selection operators. When enabled, all observation windows will be stacked as lines of a matrix and the full matrix will be processed at once. Otherwise, each observation window is processed independently.
batch – Whether to use batch processing with vectorized implementation. When enabled, divided the matrix with all the observation windows into batches. Use this option in order to decrease the amount of RAM required for processing all windows.
batch_size – Define the size of each batch, that is, the number of observation windows that will be processed at once.
calc_drift – Compute the cumulative time offset drift estimates and save them on self.data before running the algorithms. In the end, remove the results from self.data. On multiprocessing worker objects, set this to false given that the parent object will already calculate the cumulative drifts and make them available to all workers through the shared self.data.
recursive – Prefer a recursive implementation when available.