Skip to content

Commit

Permalink
Merge pull request #3890 from dmos62/dao-facts-and-figures-outlier-re…
Browse files Browse the repository at this point in the history
…sistance

Improve readability of the daily burnt BSQ chart
  • Loading branch information
ripcurlx authored Jan 23, 2020
2 parents d4e566f + c403ee7 commit a29d490
Show file tree
Hide file tree
Showing 9 changed files with 983 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.common.util;

import java.util.DoubleSummaryStatistics;

/* Adds logic to DoubleSummaryStatistics for keeping track of sum of squares
* and computing population variance and population standard deviation.
* Kahan summation algorithm (for `getSumOfSquares`) sourced from the DoubleSummaryStatistics class.
* Incremental variance algorithm sourced from https://math.stackexchange.com/a/1379804/316756
*/
public class DoubleSummaryStatisticsWithStdDev extends DoubleSummaryStatistics {
private double sumOfSquares;
private double sumOfSquaresCompensation; // Low order bits of sum of squares
private double simpleSumOfSquares; // Used to compute right sum of squares for non-finite inputs

@Override
public void accept(double value) {
super.accept(value);
double valueSquared = value * value;
simpleSumOfSquares += valueSquared;
sumOfSquaresWithCompensation(valueSquared);
}

public void combine(DoubleSummaryStatisticsWithStdDev other) {
super.combine(other);
simpleSumOfSquares += other.simpleSumOfSquares;
sumOfSquaresWithCompensation(other.sumOfSquares);
sumOfSquaresWithCompensation(other.sumOfSquaresCompensation);
}

/* Incorporate a new squared double value using Kahan summation /
* compensated summation.
*/
private void sumOfSquaresWithCompensation(double valueSquared) {
double tmp = valueSquared - sumOfSquaresCompensation;
double velvel = sumOfSquares + tmp; // Little wolf of rounding error
sumOfSquaresCompensation = (velvel - sumOfSquares) - tmp;
sumOfSquares = velvel;
}

private double getSumOfSquares() {
// Better error bounds to add both terms as the final sum of squares
double tmp = sumOfSquares + sumOfSquaresCompensation;
if (Double.isNaN(tmp) && Double.isInfinite(simpleSumOfSquares))
// If the compensated sum of squares is spuriously NaN from
// accumulating one or more same-signed infinite values,
// return the correctly-signed infinity stored in
// simpleSumOfSquares.
return simpleSumOfSquares;
else
return tmp;
}

private double getVariance() {
double sumOfSquares = getSumOfSquares();
long count = getCount();
double mean = getAverage();
return (sumOfSquares / count) - (mean * mean);
}

public final double getStandardDeviation() {
double variance = getVariance();
return Math.sqrt(variance);
}

}
2 changes: 2 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,8 @@ dao.factsAndFigures.supply.compRequestIssueAmount=BSQ issued for compensation re
dao.factsAndFigures.supply.reimbursementAmount=BSQ issued for reimbursement requests

dao.factsAndFigures.supply.burnt=BSQ burnt
dao.factsAndFigures.supply.burntMovingAverage=15 days moving average
dao.factsAndFigures.supply.burntZoomToInliers=Zoom to inliers

dao.factsAndFigures.supply.locked=Global state of locked BSQ
dao.factsAndFigures.supply.totalLockedUpAmount=Locked up in bonds
Expand Down
11 changes: 11 additions & 0 deletions desktop/src/main/java/bisq/desktop/bisq.css
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,17 @@ textfield */
-fx-stroke: -bs-buy;
}

/* The .chart-line-symbol rules change the color of the legend symbol */
#charts-dao .default-color0.chart-series-line { -fx-stroke: -bs-chart-dao-line1; }
#charts-dao .default-color0.chart-line-symbol { -fx-background-color: -bs-chart-dao-line1, -bs-background-color; }

#charts-dao .default-color1.chart-series-line { -fx-stroke: -bs-chart-dao-line2; }
#charts-dao .default-color1.chart-line-symbol { -fx-background-color: -bs-chart-dao-line2, -bs-background-color; }

#charts-dao .chart-series-line {
-fx-stroke-width: 1px;
}

#charts .default-color0.chart-series-area-fill {
-fx-fill: -bs-sell-transparent;
}
Expand Down
Loading

0 comments on commit a29d490

Please sign in to comment.