7adbe7255ed4cec61c22a343e0e7eb0b2bad91ae
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
.BasicSegment
;
15 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
18 * Class to calculate simple segment store statistics (min, max, average)
20 * @author Bernd Hufmann
22 public class SegmentStoreStatistics
{
23 private ISegment fMin
;
24 private ISegment fMax
;
25 private long fNbSegments
;
26 private double fAverage
;
27 private double fVariance
;
32 public SegmentStoreStatistics() {
33 fMin
= new BasicSegment(0, Long
.MAX_VALUE
);
34 fMax
= new BasicSegment(Long
.MIN_VALUE
, 0);
43 * @return minimum value
45 public long getMin() {
46 return fMin
.getLength();
52 * @return maximum value
54 public long getMax() {
55 return fMax
.getLength();
59 * Get segment with minimum length
61 * @return segment with minimum length
63 public ISegment
getMinSegment() {
68 * Get segment with maximum length
70 * @return segment with maximum length
72 public ISegment
getMaxSegment() {
77 * Get number of segments analyzed
79 * @return number of segments analyzed
81 public long getNbSegments() {
86 * Gets the arithmetic average
88 * @return arithmetic average
90 public double getAverage() {
95 * Gets the standard deviation of the segments, uses the online algorithm
97 * "https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm">
98 * Wikipedia article of dec 3 2015 </a>
100 * @return the standard deviation of the segment store, will return NaN if
101 * there are less than 3 elements
103 public double getStdDev() {
104 return fNbSegments
> 2 ? Math
.sqrt(fVariance
/ (fNbSegments
- 1)) : Double
.NaN
;
108 * Update the statistics based on a given segment
110 * This is an online algorithm and must retain a complexity of O(1)
113 * the segment used for the update
115 public void update(ISegment segment
) {
116 long value
= segment
.getLength();
118 * Min and max are trivial, as well as number of segments
120 long min
= fMin
.getLength();
121 long max
= fMax
.getLength();
122 fMin
= min
<= value ? fMin
: segment
;
123 fMax
= max
>= value ? fMax
: segment
;
127 * The running mean is not trivial, see proof in javadoc.
129 double delta
= value
- fAverage
;
130 fAverage
+= delta
/ fNbSegments
;
131 fVariance
+= delta
* (value
- fAverage
);
This page took 0.035252 seconds and 4 git commands to generate.