LMMS
Loading...
Searching...
No Matches
juce_StatisticsAccumulator.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
33template <typename FloatType>
35{
36public:
37 //==============================================================================
40
41 //==============================================================================
45 void addValue (FloatType v) noexcept
46 {
48
49 sum += v;
50 sumSquares += v * v;
51 ++count;
52
53 if (v > maximum) maximum = v;
54 if (v < minimum) minimum = v;
55 }
56
61
62 //==============================================================================
67 {
68 return count > 0 ? sum / (FloatType) count
69 : FloatType();
70 }
71
76 {
77 return count > 0 ? (sumSquares - sum * sum / (FloatType) count) / (FloatType) count
78 : FloatType();
79 }
80
85 {
86 return std::sqrt (getVariance());
87 }
88
93 {
94 return minimum;
95 }
96
101 {
102 return maximum;
103 }
104
107 {
108 return count;
109 }
110
111private:
112 //==============================================================================
113 struct KahanSum
114 {
115 KahanSum() = default;
116 operator FloatType() const noexcept { return sum; }
117
118 void JUCE_NO_ASSOCIATIVE_MATH_OPTIMISATIONS operator+= (FloatType value) noexcept
119 {
120 FloatType correctedValue = value - error;
121 FloatType newSum = sum + correctedValue;
122 error = (newSum - sum) - correctedValue;
123 sum = newSum;
124 }
125
126 FloatType sum{}, error{};
127 };
128
129 //==============================================================================
130 size_t count { 0 };
132 FloatType minimum { std::numeric_limits<FloatType>::infinity() },
133 maximum { -std::numeric_limits<FloatType>::infinity() };
134};
135
136} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
FloatType minimum
Definition juce_StatisticsAccumulator.h:132
FloatType getMinValue() const noexcept
Definition juce_StatisticsAccumulator.h:92
KahanSum sumSquares
Definition juce_StatisticsAccumulator.h:131
FloatType getAverage() const noexcept
Definition juce_StatisticsAccumulator.h:66
size_t count
Definition juce_StatisticsAccumulator.h:130
KahanSum sum
Definition juce_StatisticsAccumulator.h:131
void reset() noexcept
Definition juce_StatisticsAccumulator.h:60
FloatType maximum
Definition juce_StatisticsAccumulator.h:133
FloatType getVariance() const noexcept
Definition juce_StatisticsAccumulator.h:75
size_t getCount() const noexcept
Definition juce_StatisticsAccumulator.h:106
void addValue(FloatType v) noexcept
Definition juce_StatisticsAccumulator.h:45
FloatType getStandardDeviation() const noexcept
Definition juce_StatisticsAccumulator.h:84
FloatType getMaxValue() const noexcept
Definition juce_StatisticsAccumulator.h:100
unsigned v[N_MAX]
Definition inflate.c:1584
static PuglViewHint int value
Definition pugl.h:1708
#define jassert(expression)
#define JUCE_NO_ASSOCIATIVE_MATH_OPTIMISATIONS
Definition carla_juce.cpp:31
bool juce_isfinite(NumericType) noexcept
Definition juce_MathsFunctions.h:421
Definition juce_StatisticsAccumulator.h:114
FloatType error
Definition juce_StatisticsAccumulator.h:126
FloatType sum
Definition juce_StatisticsAccumulator.h:126
int error
Definition extract.c:1038
#define const
Definition zconf.h:137