Weighted centered-moment kernels for the field-statistics pipeline. More...
#include <petscsys.h>Go to the source code of this file.
Data Structures | |
| struct | PicurvMomentState |
| Weighted centered state for one scalar quantity at one point. More... | |
| struct | PicurvCoMomentState |
| Weighted centered co-moment state for one ordered pair of quantities. More... | |
Functions | |
| void | PicurvMomentStateReset (PicurvMomentState *state) |
| Resets a scalar moment accumulator to the empty state. | |
| void | PicurvCoMomentStateReset (PicurvCoMomentState *state) |
| Resets a co-moment accumulator to the empty state. | |
| PetscErrorCode | PicurvMomentStateUpdate (PicurvMomentState *state, PetscReal value, PetscReal weight) |
| Applies one weighted sample to a scalar moment accumulator. | |
| PetscErrorCode | PicurvCoMomentStateUpdate (PicurvCoMomentState *state, PetscReal value_x, PetscReal value_y, PetscReal weight) |
| Applies one weighted paired sample to a co-moment accumulator. | |
| PetscErrorCode | PicurvMomentStateMerge (PicurvMomentState *result, const PicurvMomentState *a, const PicurvMomentState *b) |
| Merges two independently accumulated scalar states. | |
| PetscErrorCode | PicurvCoMomentStateMerge (PicurvCoMomentState *result, const PicurvCoMomentState *a, const PicurvCoMomentState *b) |
| Merges two independently accumulated co-moment states. | |
| PetscReal | PicurvMomentStateVariance (const PicurvMomentState *state) |
Returns the weighted variance M2/W, or zero when no weight accumulated. | |
| PetscReal | PicurvCoMomentStateCovariance (const PicurvCoMomentState *state) |
Returns the weighted covariance C/W, or zero when no weight accumulated. | |
| PetscReal | PicurvMomentStateEffectiveCount (const PicurvMomentState *state) |
Returns Kish effective sample size W^2/W2, or zero when no weight accumulated. | |
Weighted centered-moment kernels for the field-statistics pipeline.
These are pure numerical kernels: no configuration, no PETSc vectors, and no knowledge of windows, fields, or scheduling. They implement the accumulator contract described in 4.1 Per-Point State and Update.
Centered state is used rather than raw sums because it retains everything the first and second moments need while staying numerically stable for high-mean/low-fluctuation signals. Raw sums are recoverable as S_x = W*mu and Q_xx = M2 + W*mu^2.
Definition in file statistics_moments.h.
| struct PicurvMomentState |
Weighted centered state for one scalar quantity at one point.
weight_sq is retained because physical-time weighting produces unequal weights, so an effective sample size cannot be inferred from count alone.
Definition at line 26 of file statistics_moments.h.
| struct PicurvCoMomentState |
Weighted centered co-moment state for one ordered pair of quantities.
The two means are tracked inside the pair rather than referenced from two PicurvMomentState values, so a co-moment update is self-contained and cannot be corrupted by update ordering between the members.
Definition at line 41 of file statistics_moments.h.
| void PicurvMomentStateReset | ( | PicurvMomentState * | state | ) |
Resets a scalar moment accumulator to the empty state.
| [out] | state | Accumulator to clear; ignored when NULL. |
Resets a scalar moment accumulator to the empty state.
Definition at line 15 of file statistics_moments.c.
| void PicurvCoMomentStateReset | ( | PicurvCoMomentState * | state | ) |
Resets a co-moment accumulator to the empty state.
| [out] | state | Accumulator to clear; ignored when NULL. |
Resets a co-moment accumulator to the empty state.
Definition at line 29 of file statistics_moments.c.
| PetscErrorCode PicurvMomentStateUpdate | ( | PicurvMomentState * | state, |
| PetscReal | value, | ||
| PetscReal | weight | ||
| ) |
Applies one weighted sample to a scalar moment accumulator.
Implements the stable weighted update ‘W’ = W+w,d = x-mu,mu' = mu + (w/W')d,M2' = M2 + w*d*(x-mu')`.
| [in,out] | state | Accumulator to update. |
| [in] | value | Sample value x. |
| [in] | weight | Sample weight w; must be strictly positive. |
PETSC_ERR_ARG_OUTOFRANGE for a non-positive weight.Applies one weighted sample to a scalar moment accumulator.
Definition at line 44 of file statistics_moments.c.
| PetscErrorCode PicurvCoMomentStateUpdate | ( | PicurvCoMomentState * | state, |
| PetscReal | value_x, | ||
| PetscReal | value_y, | ||
| PetscReal | weight | ||
| ) |
Applies one weighted paired sample to a co-moment accumulator.
Uses the pre-update mean of x and the post-update mean of y, which is the form that reduces exactly to the M2 update when x and y are the same signal.
| [in,out] | state | Accumulator to update. |
| [in] | value_x | Sample value of the first member. |
| [in] | value_y | Sample value of the second member. |
| [in] | weight | Sample weight w; must be strictly positive. |
PETSC_ERR_ARG_OUTOFRANGE for a non-positive weight.Applies one weighted paired sample to a co-moment accumulator.
Definition at line 71 of file statistics_moments.c.
| PetscErrorCode PicurvMomentStateMerge | ( | PicurvMomentState * | result, |
| const PicurvMomentState * | a, | ||
| const PicurvMomentState * | b | ||
| ) |
Merges two independently accumulated scalar states.
Implements the stable weighted parallel combination d = mu_b - mu_a, W = W_a + W_b, mu = mu_a + (W_b/W)d, M2 = M2_a + M2_b + (W_a*W_b/W)d^2. Merging an empty state is a no-op, so partitions that received no samples are safe to combine.
| [out] | result | Merged state; may alias a or b. |
| [in] | a | First partition. |
| [in] | b | Second partition. |
PETSC_ERR_ARG_NULL when any argument is NULL.Merges two independently accumulated scalar states.
Definition at line 100 of file statistics_moments.c.
| PetscErrorCode PicurvCoMomentStateMerge | ( | PicurvCoMomentState * | result, |
| const PicurvCoMomentState * | a, | ||
| const PicurvCoMomentState * | b | ||
| ) |
Merges two independently accumulated co-moment states.
| [out] | result | Merged state; may alias a or b. |
| [in] | a | First partition. |
| [in] | b | Second partition. |
PETSC_ERR_ARG_NULL when any argument is NULL.Merges two independently accumulated co-moment states.
Definition at line 129 of file statistics_moments.c.
| PetscReal PicurvMomentStateVariance | ( | const PicurvMomentState * | state | ) |
Returns the weighted variance M2/W, or zero when no weight accumulated.
This is the population (weight-normalized) variance the postprocessing contract uses for R_ii. It is never negative for a state built only through PicurvMomentStateUpdate, but callers taking a square root must still clamp, because cancellation can drive M2 slightly negative for degenerate inputs.
| [in] | state | Accumulator to read. |
Returns the weighted variance M2/W, or zero when no weight accumulated.
Definition at line 161 of file statistics_moments.c.
| PetscReal PicurvCoMomentStateCovariance | ( | const PicurvCoMomentState * | state | ) |
Returns the weighted covariance C/W, or zero when no weight accumulated.
| [in] | state | Accumulator to read. |
Returns the weighted covariance C/W, or zero when no weight accumulated.
Definition at line 171 of file statistics_moments.c.
| PetscReal PicurvMomentStateEffectiveCount | ( | const PicurvMomentState * | state | ) |
Returns Kish effective sample size W^2/W2, or zero when no weight accumulated.
Equals the sample count exactly under equal weights, and degrades toward one as the weight distribution becomes dominated by a single sample.
| [in] | state | Accumulator to read. |
Returns Kish effective sample size W^2/W2, or zero when no weight accumulated.
Definition at line 181 of file statistics_moments.c.