pysdic.SDICTemporalRegularizationTerm#

SDICTemporalRegularizationTerm class#

class SDICTemporalRegularizationTerm(analysis, unknowns, order, *, frames=None, accuracy=2, boundary='one_sided', max_gap=None, target=None, component_weights=None, row_weights='uniform', mode='rJ', weight=1.0, loss=None, loss_scale=1.0, sparse=True)[source]#

The temporal regularization of the displacements of the vertices of the mesh along the frames of an analysis, by penalizing their temporal derivative of order \(n\). The pysolvegn.Term to give to pysolvegn.solve is the property term.

The term works on the vector of unknowns \(\vec{p} = [\vec{p}_U, \vec{p}_T]\) described by unknowns (see pysdic.SDICUnknowns) in analysis: give it the same analysis and the same unknowns objects as the correlation term to combine both terms in the same problem (see pysdic.check_same_problem()). \(\vec{p}_U\) are the displacements of the optimized frames (Fortran order, frame after frame) and \(\vec{p}_T\) the parameters of the optimized transformations. The regularization does not depend on the transformations: their columns of the Jacobian are zero.

The object is immutable: with_unknowns() and with_options() create a new regularization (e.g. with other unknowns, another order or another weight).

Residuals. The frames of the regularization (frames) are sorted by time. The optimized frames take their displacement in \(\vec{p}_U\), the other ones (fixed frames) their displacement set in the analysis. For each evaluated frame \(f_i\), each vertex \(v\) and each component \(e\):

\[r_{i,v,e} = \sqrt{w_e \, \omega_i} \left( \sum_{k} c_{i,k} \, u_{f_k, v, e} - a_{f_i, v, e} \right)\]

where \(c_{i,k}\) are the finite difference coefficients of the derivative of order \(n\) at the time \(t_{f_i}\) (see pysdic.numeric.assemble_finite_difference_matrix()), \(a\) the target derivative (zero by default), \(w_e\) the component_weights and \(\omega_i\) the row_weights.

Sampling. The coefficients are computed for the times of acquisition of the frames, defined in the analysis (pysdic.SDICAnalysis.times, required): the frames that are not in the regularization (frames without displacement, or not in frames) only make the step between their neighbors larger. No displacement is interpolated or extrapolated:

  • centered stencils when the neighbors are uniformly spaced, the most centered window of \(n + p\) frames otherwise (accuracy \(p\));

  • at the first and last frames, one-sided stencils (boundary="one_sided") or no equation (boundary="valid");

  • with max_gap, no stencil spans a step larger than max_gap: the frames on each side are regularized separately.

Equations. Only the equations involving at least one optimized frame are kept (the other ones are constant). The equations of the fixed frames next to optimized frames are kept: for example, the equation of the reference frame links it with the first optimized frames.

Weights of the rows. The one-sided stencils have larger coefficients than the centered ones: the first and last frames are more regularized. The coefficients of a frame across a large step are smaller: a displacement change over a longer duration is a smaller derivative. With row_weights="time", each equation is weighted by the duration \(\omega_i\) it represents (half the distance between the previous and the next frames, half the step at the ends), so that the cost approximates \(\int \| \vec{u}^{(n)}(t) - \vec{a}(t) \|^2 dt\) independently of the sampling of the frames.

The residual is linear: \(\vec{r} = J \vec{p} + \vec{b}\), with a constant Jacobian computed once. The vector \(\vec{b}\) (contribution of the fixed frames, minus the target) is computed at each evaluation from the current displacements of the fixed frames: a displacement updated after the creation of the term (for example the result of a previous measurement) is taken into account.

Note

The frames of the regularization are fixed at the creation of the term: a frame whose displacement is set later is not added (build a new term to include it). The displacements of the fixed frames cannot be removed from the analysis, so they are always available.

The residuals are ordered by evaluated frame (chronological order), each frame in Fortran order of \((N_v, E)\) (all the \(x\) components, then all the \(y\) components, …).

Parameters:
  • analysis (pysdic.SDICAnalysis) – The analysis, with the times of the frames defined (pysdic.SDICAnalysis.times) and the displacements of the fixed frames of the regularization set.

  • unknowns (pysdic.SDICUnknowns) – The unknowns of the problem, with at least one optimized frame, validated by the analysis. The optimized transformations only define the size of the vector of unknowns.

  • order (Integral) – The order \(n \geq 1\) of the penalized derivative (1 for the velocity, 2 for the acceleration).

  • frames (Optional[Sequence[Integral]], optional) – The frames of the regularization, which must contain the optimized frames. By default, the optimized frames and all the frames whose displacement is set.

  • accuracy (Integral, optional (default: 2)) – The order \(p\) of the error of the finite differences, a positive even integer.

  • boundary (str, optional (default: "one_sided")) – The equations at the first and last frames: "one_sided" or "valid".

  • max_gap (Optional[Real], optional) – The largest step between two frames that a stencil can span, in the unit of the times of the analysis. By default, no limit.

  • target (Optional[ArrayLike], optional) – The target derivative \(a\), of shape \((N_f, N_v, E)\) (only the evaluated frames are used). By default, zero.

  • component_weights (Optional[ArrayLike], optional) – The non-negative weights \(w_e\) of the components of the displacement, of shape \((E,)\), e.g. [1, 1, 0] to regularize only the in-plane components. By default, 1.

  • row_weights (str, optional (default: "uniform")) – The weights \(\omega_i\) of the evaluated frames: "uniform" (1) or "time" (duration represented by each frame, see above).

  • mode (str, optional (default: "rJ")) – The mode of the term: "rJ" (residuals and Jacobian) or "gH" (gradient \(J^T \vec{r}\), Hessian \(J^T J\) and cost, only the "linear" loss).

  • weight (Real, optional (default: 1.0)) – The weight of the term in the pysolvegn problem.

  • loss (Optional[Union[str, Callable]], optional) – The loss function of the term (see pysolvegn.Term), only for the mode "rJ". None means "linear".

  • loss_scale (Real, optional (default: 1.0)) – The soft threshold of the loss function. Only for the mode "rJ".

  • sparse (bool, optional (default: True)) – If True, the Jacobian ("rJ") or the Hessian ("gH") is a scipy.sparse.csr_matrix, otherwise a dense array.

Raises:
  • TypeError – If an input has a wrong type.

  • ValueError – If the times of the analysis are not defined, the frames or the transformations are not consistent, the displacement of a fixed frame of the regularization is not set, a loss other than "linear" is used in mode "gH", or an input has a wrong shape or value.

Examples

Measure the displacements of the frames 1 to 9 with a penalty on the acceleration, the frame 0 being the reference:

import pysolvegn
from pysdic import SDICCorrelationTerm, SDICTemporalRegularizationTerm, SDICUnknowns

unknowns = SDICUnknowns(list(range(1, 10)), [])
correlation = SDICCorrelationTerm(analysis, unknowns, integration_points, pairings)
regularization = SDICTemporalRegularizationTerm(analysis, unknowns, order=2, weight=1e-2)

result = pysolvegn.solve([correlation.term, regularization.term], analysis.pack_unknowns(unknowns), max_iteration=20)
analysis.apply_unknowns(unknowns, result.parameters)

# The same problem with a stronger regularization of the velocity
regularization = regularization.with_options(order=1, weight=1e-1)

Instantiation and new terms#

A SDICTemporalRegularizationTerm is created with the unknowns of the problem (the same pysdic.SDICUnknowns as the correlation term), the order of the derivative and its options. The analysis must have times. The term is immutable: the methods below create a new term.

regularization = SDICTemporalRegularizationTerm(unknowns, order=2, weight=1e-2)
result = pysolvegn.solve([correlation.term, regularization.term], unknowns.pack())

regularization_2 = regularization.with_unknowns(unknowns_2)              # New unknowns
softer = regularization.with_options(order=1, weight=1e-1)               # Other options

SDICTemporalRegularizationTerm.with_unknowns(...)

A new regularization with other unknowns and the same options.

SDICTemporalRegularizationTerm.with_options(...)

A new regularization with the same unknowns and other options (any parameter of the constructor except analysis and unknowns), e.g. with_options(order=1, weight=1e-1).

Term and unknowns#

SDICTemporalRegularizationTerm.term

The pysolvegn.Term, to give to pysolvegn.solve.

SDICTemporalRegularizationTerm.unknowns

The unknowns of the problem (shared with the correlation term).

SDICTemporalRegularizationTerm.analysis

The analysis (shared with the other objects of the problem).

SDICTemporalRegularizationTerm.pack()

The vector of unknowns of the current state of the analysis, see pysdic.SDICAnalysis.pack_unknowns().

Configuration#

SDICTemporalRegularizationTerm.order

The order \(n\) of the penalized derivative.

SDICTemporalRegularizationTerm.weight

The weight of the term in the pysolvegn problem.

SDICTemporalRegularizationTerm.options

the parameters of the constructor except analysis and unknowns.

SDICTemporalRegularizationTerm.evaluated_frames

The frames with an equation, in chronological order (read-only).