Compute Library
 22.05
InstrumentsStats Class Reference

Generate common statistics for a set of measurements. More...

#include <InstrumentsStats.h>

Public Member Functions

 InstrumentsStats (const std::vector< Measurement > &measurements)
 Compute statistics for the passed set of measurements. More...
 
const Measurementmin () const
 The measurement with the minimum value. More...
 
const Measurementmax () const
 The measurement with the maximum value. More...
 
const Measurementmedian () const
 The median measurement. More...
 
const Measurement::Valuemean () const
 The average of all the measurements. More...
 
double relative_standard_deviation () const
 The relative standard deviation of the measurements. More...
 

Detailed Description

Generate common statistics for a set of measurements.

Definition at line 39 of file InstrumentsStats.h.

Constructor & Destructor Documentation

◆ InstrumentsStats()

InstrumentsStats ( const std::vector< Measurement > &  measurements)

Compute statistics for the passed set of measurements.

Parameters
[in]measurementsThe measurements to process

Definition at line 33 of file InstrumentsStats.cpp.

References arm_compute::test::validation::reference::accumulate(), arm_compute::test::validation::b, Measurement::Value::is_floating_point, Measurement::Value::relative_standard_deviation(), arm_compute::utility::sort_indices(), and Measurement::value().

34  : _min(nullptr), _max(nullptr), _median(nullptr), _mean(measurements.begin()->value().is_floating_point), _stddev(0.0)
35 {
36  auto add_measurements = [](Measurement::Value a, const Measurement & b)
37  {
38  return a + b.value();
39  };
40 
41  //Calculate min, max & median values
42  auto indices = arm_compute::utility::sort_indices(measurements);
43  _median = &measurements[indices[measurements.size() / 2]];
44  _min = &measurements[indices[0]];
45  _max = &measurements[indices[measurements.size() - 1]];
46 
47  Measurement::Value sum_values = std::accumulate(measurements.begin(), measurements.end(), Measurement::Value(_min->value().is_floating_point), add_measurements);
48 
49  // Calculate the relative standard deviation
50  _mean = sum_values / measurements.size();
51  std::vector<Measurement::Value> diff(measurements.size(), _min->value().is_floating_point);
52  std::transform(measurements.begin(), measurements.end(), diff.begin(), [&](const Measurement & x)
53  {
54  return x.value() - _mean;
55  });
56  auto sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), Measurement::Value(_min->value().is_floating_point));
57  auto variance = sq_sum / measurements.size();
58  _stddev = Measurement::Value::relative_standard_deviation(variance, _mean);
59 }
static double relative_standard_deviation(const Value &variance, const Value &mean)
Get the relative standard deviation to a given distribution as a percentage.
Definition: Measurement.h:198
SimpleTensor< float > b
Definition: DFT.cpp:157
SimpleTensor< T2 > accumulate(const SimpleTensor< T1 > &src, DataType output_data_type)
Definition: Accumulate.cpp:38
bool is_floating_point
Is the stored value floating point or integer ?
Definition: Measurement.h:216
const Value & value() const
Accessor for the stored value.
Definition: Measurement.h:301
std::vector< size_t > sort_indices(const std::vector< T > &v)
Perform an index sort of a given vector.
Definition: Utility.h:157

Member Function Documentation

◆ max()

const Measurement& max ( ) const
inline

The measurement with the maximum value.

Definition at line 55 of file InstrumentsStats.h.

Referenced by PrettyPrinter::print_measurements().

56  {
57  return *_max;
58  }

◆ mean()

const Measurement::Value& mean ( ) const
inline

The average of all the measurements.

Definition at line 67 of file InstrumentsStats.h.

Referenced by PrettyPrinter::print_measurements().

68  {
69  return _mean;
70  }

◆ median()

const Measurement& median ( ) const
inline

The median measurement.

Definition at line 61 of file InstrumentsStats.h.

Referenced by PrettyPrinter::print_measurements().

62  {
63  return *_median;
64  }

◆ min()

const Measurement& min ( ) const
inline

The measurement with the minimum value.

Definition at line 49 of file InstrumentsStats.h.

Referenced by PrettyPrinter::print_measurements().

50  {
51  return *_min;
52  }

◆ relative_standard_deviation()

double relative_standard_deviation ( ) const
inline

The relative standard deviation of the measurements.

Definition at line 73 of file InstrumentsStats.h.

Referenced by PrettyPrinter::print_measurements().

74  {
75  return _stddev;
76  }

The documentation for this class was generated from the following files: