Commit e66d588c authored by Davis King's avatar Davis King

Removed the max_n feature from the running_stats object since it's actually

been broken for a while and I doubt anyone ever used it (this also simplifies
it's interface).  Note that this change, along with the previous change by
Steven breaks backwards compatibility with the previous serialization format
for running_stats object.
parent a75645b1
...@@ -40,18 +40,10 @@ namespace dlib ...@@ -40,18 +40,10 @@ namespace dlib
sum_four = 0; sum_four = 0;
n = 0; n = 0;
maximum_n = std::numeric_limits<T>::max();
min_value = std::numeric_limits<T>::infinity(); min_value = std::numeric_limits<T>::infinity();
max_value = -std::numeric_limits<T>::infinity(); max_value = -std::numeric_limits<T>::infinity();
} }
void set_max_n (
const T& val
)
{
maximum_n = val;
}
void add ( void add (
const T& val const T& val
) )
...@@ -66,14 +58,7 @@ namespace dlib ...@@ -66,14 +58,7 @@ namespace dlib
if (val > max_value) if (val > max_value)
max_value = val; max_value = val;
if (n < maximum_n) ++n;
++n;
}
T max_n (
) const
{
return maximum_n;
} }
T current_n ( T current_n (
...@@ -204,15 +189,6 @@ namespace dlib ...@@ -204,15 +189,6 @@ namespace dlib
const running_stats& rhs const running_stats& rhs
) const ) const
{ {
// make sure requires clause is not broken
DLIB_ASSERT(max_n() == rhs.max_n(),
"\trunning_stats running_stats::operator+(rhs)"
<< "\n\t invalid inputs were given to this function"
<< "\n\t max_n(): " << max_n()
<< "\n\t rhs.max_n(): " << rhs.max_n()
<< "\n\t this: " << this
);
running_stats temp(*this); running_stats temp(*this);
temp.sum += rhs.sum; temp.sum += rhs.sum;
...@@ -243,7 +219,6 @@ namespace dlib ...@@ -243,7 +219,6 @@ namespace dlib
T sum_cub; T sum_cub;
T sum_four; T sum_four;
T n; T n;
T maximum_n;
T min_value; T min_value;
T max_value; T max_value;
...@@ -265,7 +240,6 @@ namespace dlib ...@@ -265,7 +240,6 @@ namespace dlib
serialize(item.sum_cub, out); serialize(item.sum_cub, out);
serialize(item.sum_four, out); serialize(item.sum_four, out);
serialize(item.n, out); serialize(item.n, out);
serialize(item.maximum_n, out);
serialize(item.min_value, out); serialize(item.min_value, out);
serialize(item.max_value, out); serialize(item.max_value, out);
} }
...@@ -286,7 +260,6 @@ namespace dlib ...@@ -286,7 +260,6 @@ namespace dlib
deserialize(item.sum_cub, in); deserialize(item.sum_cub, in);
deserialize(item.sum_four, in); deserialize(item.sum_four, in);
deserialize(item.n, in); deserialize(item.n, in);
deserialize(item.maximum_n, in);
deserialize(item.min_value, in); deserialize(item.min_value, in);
deserialize(item.max_value, in); deserialize(item.max_value, in);
} }
......
...@@ -116,28 +116,12 @@ namespace dlib ...@@ -116,28 +116,12 @@ namespace dlib
- T must be a float, double, or long double type - T must be a float, double, or long double type
INITIAL VALUE INITIAL VALUE
- max_n() == std::numeric_limits<T>::max()
- mean() == 0 - mean() == 0
- current_n() == 0 - current_n() == 0
WHAT THIS OBJECT REPRESENTS WHAT THIS OBJECT REPRESENTS
This object represents something that can compute the running mean, This object represents something that can compute the running mean,
variance, skewness, and excess kurtosis of a stream of real numbers. variance, skewness, and excess kurtosis of a stream of real numbers.
As this object accumulates more and more numbers it will be the case
that each new number impacts the current mean and variance estimate
less and less. This may be what you want. But it might not be.
For example, your stream of numbers might be non-stationary, that is,
the mean and variance might change over time. To enable you to use
this object on such a stream of numbers this object provides the
ability to set a "max_n." The meaning of the max_n() parameter
is that after max_n() samples have been seen each new sample will
have the same impact on the mean and variance estimates from then on.
So if you have a highly non-stationary stream of data you might
set the max_n to a small value while if you have a very stationary
stream you might set it to a very large value.
!*/ !*/
public: public:
...@@ -156,27 +140,11 @@ namespace dlib ...@@ -156,27 +140,11 @@ namespace dlib
- clears all memory of any previous data points - clears all memory of any previous data points
!*/ !*/
void set_max_n (
const T& val
);
/*!
ensures
- #max_n() == val
!*/
T max_n (
) const;
/*!
ensures
- returns the max value that current_n() is allowed to take on
!*/
T current_n ( T current_n (
) const; ) const;
/*! /*!
ensures ensures
- returns the number of points given to this object so far or - returns the number of points given to this object so far.
max_n(), whichever is smallest.
!*/ !*/
void add ( void add (
...@@ -191,10 +159,7 @@ namespace dlib ...@@ -191,10 +159,7 @@ namespace dlib
- #variance() == the updated variance that takes this new value into account. - #variance() == the updated variance that takes this new value into account.
- #skewness() == the updated skewness that takes this new value into account. - #skewness() == the updated skewness that takes this new value into account.
- #ex_kurtosis() == the updated kurtosis that takes this new value into account. - #ex_kurtosis() == the updated kurtosis that takes this new value into account.
- if (current_n() < max_n()) then - #current_n() == current_n() + 1
- #current_n() == current_n() + 1
- else
- #current_n() == current_n()
!*/ !*/
T mean ( T mean (
...@@ -277,8 +242,6 @@ namespace dlib ...@@ -277,8 +242,6 @@ namespace dlib
const running_stats& rhs const running_stats& rhs
) const; ) const;
/*! /*!
requires
- max_n() == rhs.max_n()
ensures ensures
- returns a new running_stats object that represents the combination of all - returns a new running_stats object that represents the combination of all
the values given to *this and rhs. That is, this function returns a the values given to *this and rhs. That is, this function returns a
......
...@@ -422,8 +422,6 @@ namespace ...@@ -422,8 +422,6 @@ namespace
DLIB_TEST(std::abs((rc1+rc2).covariance() - rc3.covariance()) < 1e-13); DLIB_TEST(std::abs((rc1+rc2).covariance() - rc3.covariance()) < 1e-13);
DLIB_TEST((rc1+rc2).current_n() == rc3.current_n()); DLIB_TEST((rc1+rc2).current_n() == rc3.current_n());
rs1.set_max_n(50);
DLIB_TEST(rs1.max_n() == 50);
} }
void test_average_precision() void test_average_precision()
......
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