DP3
Classes | Enumerations | Functions
TecOffsetDelayFitting.h File Reference
#include <optional>
#include <span>
#include <string>

Go to the source code of this file.

Classes

struct  TecOffsetDelayValues
 

Enumerations

enum class  TecOffsetDelayFittingMethod { LeastSquares , VonMises }
 

Functions

void EvaluateLinearTecOffsetValues (const TecOffsetDelayValues &fit, std::span< const double > x, std::span< double > y)
 
std::optional< TecOffsetDelayValuesGradientTecDelaySolve (std::span< const double > x, std::span< const double > y, std::span< const double > weights)
 
std::optional< TecOffsetDelayValuesGradientTecOffsetDelaySolve (std::span< const double > x, std::span< const double > y, std::span< const double > weights)
 
std::optional< TecOffsetDelayValuesLinearTecDelaySolve (std::span< const double > x, std::span< const double > y, std::span< const double > weights)
 
std::optional< TecOffsetDelayValuesLinearTecOffsetDelaySolve (std::span< const double > x, std::span< const double > y, std::span< const double > weights)
 
void PlotCostValues (const std::string &filename, std::span< const double > x_data, std::span< const double > y_data, std::span< const double > weights, size_t max_wraps)
 
double TecOffsetDelayCost (std::span< const double > x_data, std::span< const double > y_data, std::span< const double > weights, const TecOffsetDelayValues &fit)
 
TecOffsetDelayValues TecOffsetDelayGridSearch (std::span< const double > x_data, std::span< const double > y_data, std::span< const double > weights, bool include_b, size_t max_wraps, TecOffsetDelayFittingMethod method=TecOffsetDelayFittingMethod::LeastSquares)
 

Detailed Description

Contains functionality for fitting TEC, offset and delay to phase data.

Enumeration Type Documentation

◆ TecOffsetDelayFittingMethod

Enumerator
LeastSquares 
VonMises 

Function Documentation

◆ EvaluateLinearTecOffsetValues()

void EvaluateLinearTecOffsetValues ( const TecOffsetDelayValues fit,
std::span< const double >  x,
std::span< double >  y 
)

Evaluates the function y(x) = a/x + b + c x and writes the result in y. All values will be wrapped to the range [-pi, pi).

◆ GradientTecDelaySolve()

std::optional<TecOffsetDelayValues> GradientTecDelaySolve ( std::span< const double >  x,
std::span< const double >  y,
std::span< const double >  weights 
)

Same as GradientTecOffsetDelaySolve(), but assumes the delay offset b=0.

◆ GradientTecOffsetDelaySolve()

std::optional<TecOffsetDelayValues> GradientTecOffsetDelaySolve ( std::span< const double >  x,
std::span< const double >  y,
std::span< const double >  weights 
)

Minimizes with a cost function of the sum of -cos(y - model), i.e. assuming a von Mises distribution.

◆ LinearTecDelaySolve()

std::optional<TecOffsetDelayValues> LinearTecDelaySolve ( std::span< const double >  x,
std::span< const double >  y,
std::span< const double >  weights 
)

Same as LinearTecOffsetDelaySolve(), but assumes the delay offset b=0.

◆ LinearTecOffsetDelaySolve()

std::optional<TecOffsetDelayValues> LinearTecOffsetDelaySolve ( std::span< const double >  x,
std::span< const double >  y,
std::span< const double >  weights 
)

Perform a linear least-squares fit to solve the function y(x) = a / x + b + c

  • x, where a is the TEC, b is the offset and c the delay.

This function does not work well in the presence of wrapping: use the TecOffsetDelayGridSearch() for that.

Returns
an empty optional if the fit fails, otherwise

◆ PlotCostValues()

void PlotCostValues ( const std::string &  filename,
std::span< const double >  x_data,
std::span< const double >  y_data,
std::span< const double >  weights,
size_t  max_wraps 
)

◆ TecOffsetDelayCost()

double TecOffsetDelayCost ( std::span< const double >  x_data,
std::span< const double >  y_data,
std::span< const double >  weights,
const TecOffsetDelayValues fit 
)

◆ TecOffsetDelayGridSearch()

TecOffsetDelayValues TecOffsetDelayGridSearch ( std::span< const double >  x_data,
std::span< const double >  y_data,
std::span< const double >  weights,
bool  include_b,
size_t  max_wraps,
TecOffsetDelayFittingMethod  method = TecOffsetDelayFittingMethod::LeastSquares 
)

Perform a grid search for the TEC, offset and delay parameters. It optimizes a, b, c in the function y(x) = a/x + b + c x, modulus 2pi, to minimize the cost function.

The cost function during the grid search is the sum of -cos(y_i - model_i), i.e. it assumes the values follow the Van Mises distribution. During refinement, the cost depends on the specified method: least squares or Von Mises. When using least squares, the problem is linear and therefore fast. The Van Mises uses a non-linear minimization function and is therefore considerably slower.

This function scales as max_wraps^2 x n (n being the data size). The advantage of this method is that it is guaranteed to find the global minimum in the noiseless case, but it is slow for large values of max_wraps. If this becomes a bottleneck, a random sampling could be considered instead.

Parameters
x_dataThe frequency values, must be positive and in strictly increasing order. At least 3 values must be specified.
y_dataThe phase values to be fitted (normally between 0 and 2pi, but this is not required).
include_btrue to fit b, false to assume b=0.
max_wrapsThe maximum number of wraps expected. The grid searched will have dimensions of 2 x max_wraps, spread in such a way that the global minimum is guaranteed to be found.