17 if (state == NULL)
return;
31 if (state == NULL)
return;
46 PetscReal new_weight = 0.0;
47 PetscReal delta = 0.0;
49 PetscFunctionBeginUser;
50 PetscCheck(state != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
51 "Moment accumulator is required.");
52 PetscCheck(weight > 0.0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
53 "Sample weight must be strictly positive, got %g.", (
double)weight);
55 new_weight = state->
weight + weight;
56 delta = value - state->
mean;
57 state->
mean += (weight / new_weight) * delta;
60 state->
m2 += weight * delta * (value - state->
mean);
61 state->
weight = new_weight;
64 PetscFunctionReturn(0);
72 PetscReal value_x, PetscReal value_y, PetscReal weight)
74 PetscReal new_weight = 0.0;
75 PetscReal delta_x = 0.0;
77 PetscFunctionBeginUser;
78 PetscCheck(state != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
79 "Co-moment accumulator is required.");
80 PetscCheck(weight > 0.0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
81 "Sample weight must be strictly positive, got %g.", (
double)weight);
83 new_weight = state->
weight + weight;
84 delta_x = value_x - state->
mean_x;
85 state->
mean_x += (weight / new_weight) * delta_x;
86 state->
mean_y += (weight / new_weight) * (value_y - state->
mean_y);
89 state->
cm += weight * delta_x * (value_y - state->
mean_y);
90 state->
weight = new_weight;
93 PetscFunctionReturn(0);
103 PetscReal total_weight = 0.0;
104 PetscReal delta = 0.0;
107 PetscFunctionBeginUser;
108 PetscCheck(result != NULL && a != NULL && b != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
109 "Merge requires a destination and two source accumulators.");
111 if (b->
weight == 0.0) { *result = *a; PetscFunctionReturn(0); }
112 if (a->
weight == 0.0) { *result = *b; PetscFunctionReturn(0); }
117 merged.
weight = total_weight;
122 PetscFunctionReturn(0);
132 PetscReal total_weight = 0.0;
133 PetscReal delta_x = 0.0;
134 PetscReal delta_y = 0.0;
137 PetscFunctionBeginUser;
138 PetscCheck(result != NULL && a != NULL && b != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
139 "Merge requires a destination and two source accumulators.");
141 if (b->
weight == 0.0) { *result = *a; PetscFunctionReturn(0); }
142 if (a->
weight == 0.0) { *result = *b; PetscFunctionReturn(0); }
148 merged.
weight = total_weight;
152 merged.
cm = a->
cm + b->
cm + (a->
weight * b->
weight / total_weight) * delta_x * delta_y;
154 PetscFunctionReturn(0);
163 if (state == NULL || state->
weight == 0.0)
return 0.0;
173 if (state == NULL || state->
weight == 0.0)
return 0.0;
183 if (state == NULL || state->
weight_sq == 0.0)
return 0.0;
PetscErrorCode PicurvMomentStateMerge(PicurvMomentState *result, const PicurvMomentState *a, const PicurvMomentState *b)
Implementation of PicurvMomentStateMerge().
PetscErrorCode PicurvCoMomentStateUpdate(PicurvCoMomentState *state, PetscReal value_x, PetscReal value_y, PetscReal weight)
Implementation of PicurvCoMomentStateUpdate().
PetscErrorCode PicurvCoMomentStateMerge(PicurvCoMomentState *result, const PicurvCoMomentState *a, const PicurvCoMomentState *b)
Implementation of PicurvCoMomentStateMerge().
PetscReal PicurvMomentStateEffectiveCount(const PicurvMomentState *state)
Implementation of PicurvMomentStateEffectiveCount().
void PicurvCoMomentStateReset(PicurvCoMomentState *state)
Implementation of PicurvCoMomentStateReset().
PetscReal PicurvMomentStateVariance(const PicurvMomentState *state)
Implementation of PicurvMomentStateVariance().
PetscReal PicurvCoMomentStateCovariance(const PicurvCoMomentState *state)
Implementation of PicurvCoMomentStateCovariance().
void PicurvMomentStateReset(PicurvMomentState *state)
Implementation of PicurvMomentStateReset().
PetscErrorCode PicurvMomentStateUpdate(PicurvMomentState *state, PetscReal value, PetscReal weight)
Implementation of PicurvMomentStateUpdate().
Weighted centered-moment kernels for the field-statistics pipeline.
PetscReal weight_sq
Sum of squared weights W2.
PetscReal weight_sq
Sum of squared weights W2.
PetscReal mean_y
Weighted mean of the second member.
PetscReal weight
Total weight W.
PetscReal count
Number of accepted samples.
PetscReal cm
Centered co-moment sum C.
PetscReal m2
Centered second-moment sum M2.
PetscReal mean
Weighted mean mu.
PetscReal mean_x
Weighted mean of the first member.
PetscReal weight
Total weight W.
PetscReal count
Number of accepted samples.
Weighted centered co-moment state for one ordered pair of quantities.
Weighted centered state for one scalar quantity at one point.