Commit 96508b8f authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

new WelfordAggregate

parent 08e0a17b
Pipeline #158057 failed with stages
in 11 minutes and 27 seconds
......@@ -32,6 +32,36 @@ struct SampleCounter {
}
};
struct Weights {
double W = 0.0;
double W2 = 0.0;
double newW = 0.0;
double Wcomm = 0.0;
double W2comm = 0.0;
void Update(double _newW) {
newW = _newW;
Wcomm += newW;
W2comm += newW * newW;
}
void UpdateParallel(int commSplit) {
W = PPM->SumAcrossComm(Wcomm, commSplit);
W2 = PPM->SumAcrossComm(W2comm, commSplit);
}
friend Logging &operator<<(Logging &s, const Weights &wgt) {
return s << "W=" << wgt.W
<< " W2=" << wgt.W2
<< " WComm=" << wgt.Wcomm
<< " W2Comm=" << wgt.W2comm << endl;
}
};
struct Mean {
double C = 0.0;
......@@ -45,16 +75,16 @@ struct Mean {
double Ccomm = 0.0;
void Update(double dC, double dQ, double dY, SampleCounter ctr) {
Ccomm += dC / ctr.Mcomm;
Qcomm += dQ / ctr.Mcomm;
Ycomm += dY / ctr.Mcomm;
void Update(double dC, double dQ, double dY, SampleCounter ctr, Weights wgt) {
Ccomm += dC * (1.0 / ctr.Mcomm);
Qcomm += dQ * (wgt.newW / wgt.Wcomm);
Ycomm += dY * (wgt.newW / wgt.Wcomm);
}
void UpdateParallel(SampleCounter ctr, int commSplit) {
void UpdateParallel(SampleCounter ctr, Weights wgt, int commSplit) {
C = abs(PPM->SumAcrossComm(ctr.Mcomm * Ccomm, commSplit) / ctr.M);
Q = abs(PPM->SumAcrossComm(ctr.Mcomm * Qcomm, commSplit) / ctr.M);
Y = abs(PPM->SumAcrossComm(ctr.Mcomm * Ycomm, commSplit) / ctr.M);
Q = abs(PPM->SumAcrossComm(wgt.Wcomm * Qcomm, commSplit) / wgt.W);
Y = abs(PPM->SumAcrossComm(wgt.Wcomm * Ycomm, commSplit) / wgt.W);
}
friend Logging &operator<<(Logging &s, const Mean &mean) {
......@@ -179,6 +209,8 @@ private:
public:
SampleCounter ctr;
Weights wgt;
Mean mean;
SVar sVar;
......@@ -187,6 +219,8 @@ public:
Kurtosis kurtosis;
double W2 = 0.0;
double C2 = 0.0;
double Q2 = 0.0;
......@@ -202,21 +236,23 @@ public:
UpdateSampleCounter(dM);
}
void Update(const SampleSolution &fineSolution, const SampleSolution &coarseSolution) {
double newC = fineSolution.C;
double newQ = fineSolution.Q;
double newY = fineSolution.Q - coarseSolution.Q;
Update(newC, newQ, newY);
void Update(const SampleSolution &fSol, const SampleSolution &cSol) {
double newW = fSol.W;
double newC = fSol.C;
double newQ = fSol.Q;
double newY = fSol.Q - cSol.Q;
Update(newW, newC, newQ, newY);
}
void Update(double newC, double newQ, double newY) {
void Update(double newW, double newC, double newQ, double newY) {
ctr.Update();
wgt.Update(newW);
double dC = newC - mean.Ccomm;
double dQ = newQ - mean.Qcomm;
double dY = newY - mean.Ycomm;
mean.Update(dC, dQ, dY, ctr);
mean.Update(dC, dQ, dY, ctr, wgt);
double dC2 = newC - mean.Ccomm;
double dQ2 = newQ - mean.Qcomm;
......@@ -231,7 +267,8 @@ public:
void UpdateParallel() {
ctr.UpdateParallel(commSplit);
mean.UpdateParallel(ctr, commSplit);
wgt.UpdateParallel(commSplit);
mean.UpdateParallel(ctr, wgt, commSplit);
C2 = PPM->SumAcrossComm(C2comm, commSplit);
Q2 = PPM->SumAcrossComm(Q2comm, commSplit);
......
......@@ -26,7 +26,7 @@ protected:
void TestSampleCounterParallel() {
pout << "Before update: " << aggregate.ctr << endl;
while (aggregate.ctr.dMcomm != 0) aggregate.Update(0.0, 0.0, 0.0);
while (aggregate.ctr.dMcomm != 0) aggregate.Update(0.0, 0.0, 0.0, 0.0);
pout << "After update: " << aggregate.ctr << endl;
aggregate.UpdateParallel();
pout << "After parallel update: " << aggregate.ctr << endl;
......@@ -39,7 +39,7 @@ protected:
void TestMeanParallel() {
pout << "Before update: " << aggregate.mean << endl;
while (aggregate.ctr.dMcomm != 0) aggregate.Update(0.0, PPM->Proc(0), 0.0);
while (aggregate.ctr.dMcomm != 0) aggregate.Update(0.0, 0.0, PPM->Proc(0), 0.0);
pout << "After update: " << aggregate.mean << endl;
aggregate.UpdateParallel();
pout << "After parallel update: " << aggregate.mean << endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment