1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.analysis
.timing
.core
.segmentstore
.statistics
;
14 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
17 * Class to calculate simple segment store statistics (min, max, average)
19 * @author Bernd Hufmann
21 public class SegmentStoreStatistics
{
24 private long fNbSegments
;
25 private double fAverage
;
26 private double fVariance
;
31 public SegmentStoreStatistics() {
32 fMin
= Long
.MAX_VALUE
;
33 fMax
= Long
.MIN_VALUE
;
42 * @return minimum value
44 public long getMin() {
51 * @return maximum value
53 public long getMax() {
58 * Get number of segments analyzed
60 * @return number of segments analyzed
62 public long getNbSegments() {
67 * Gets the arithmetic average
69 * @return arithmetic average
71 public double getAverage() {
76 * Gets the standard deviation of the segments, uses the online algorithm
78 * "https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm">
79 * Wikipedia article of dec 3 2015 </a>
81 * @return the standard deviation of the segment store, will return NaN if
82 * there are less than 3 elements
84 public double getStdDev() {
85 return fNbSegments
> 2 ? Math
.sqrt(fVariance
/ (fNbSegments
- 1)) : Double
.NaN
;
89 * Update the statistics based on a given segment
91 * This is an online algorithm and must retain a complexity of O(1)
94 * the segment used for the update
96 public void update(ISegment segment
) {
97 long value
= segment
.getLength();
99 * Min and max are trivial, as well as number of segments
101 fMin
= Math
.min(fMin
, value
);
102 fMax
= Math
.max(fMax
, value
);
106 * The running mean is not trivial, see proof in javadoc.
108 double delta
= value
- fAverage
;
109 fAverage
+= delta
/ fNbSegments
;
110 fVariance
+= delta
* (value
- fAverage
);
This page took 0.046061 seconds and 6 git commands to generate.