ONE - On-device Neural Engine
Loading...
Searching...
No Matches
mpqsolver::core::MAEMetric Class Referencefinal

#include <ErrorMetric.h>

Collaboration diagram for mpqsolver::core::MAEMetric:

Public Member Functions

float compute (const WholeOutput &first, const WholeOutput &second) const
 compare first and second operands in MAE (Mean Average Error metric)
 
- Public Member Functions inherited from mpqsolver::core::ErrorMetric
virtual ~ErrorMetric ()=default
 

Detailed Description

Definition at line 43 of file ErrorMetric.h.

Member Function Documentation

◆ compute()

float MAEMetric::compute ( const WholeOutput first,
const WholeOutput second 
) const
virtual

compare first and second operands in MAE (Mean Average Error metric)

Implements mpqsolver::core::ErrorMetric.

Definition at line 31 of file ErrorMetric.cpp.

32{
33 if (first.size() != second.size())
34 {
35 throw std::runtime_error("Can not compare vectors of different sizes");
36 }
37
38 double output_errors = 0.; // mean over mean outputs errors
39 size_t num_output_errors = 0;
40
41 for (size_t sample_index = 0; sample_index < first.size(); ++sample_index)
42 {
43 assert(first[sample_index].size() == second[sample_index].size());
44 for (size_t out_index = 0; out_index < first[sample_index].size(); ++out_index)
45 {
46 const Buffer &first_elementary = first[sample_index][out_index];
47 const Buffer &second_elementary = second[sample_index][out_index];
48 assert(first_elementary.size() == second_elementary.size());
49 size_t cur_size = first_elementary.size() / luci::size(loco::DataType::FLOAT32);
50
51 double output_error = 0.; // mean error oevr current output
52
53 const float *first_floats = reinterpret_cast<const float *>(first_elementary.data());
54 const float *second_floats = reinterpret_cast<const float *>(second_elementary.data());
55 for (size_t index = 0; index < cur_size; index++)
56 {
57 double ref_value = static_cast<double>(*(first_floats + index));
58 double cur_value = static_cast<double>(*(second_floats + index));
59 output_error += std::fabs(ref_value - cur_value);
60 }
61 if (cur_size != 0)
62 {
63 output_errors += (output_error / cur_size);
64 num_output_errors += 1;
65 }
66 }
67 }
68
69 if (num_output_errors == 0)
70 {
71 throw std::runtime_error("Nothing to compare");
72 }
73
74 return static_cast<float>(output_errors / num_output_errors);
75}
uint32_t size(loco::DataType data_type)
Returns the size of the data type.
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54
std::vector< char > Buffer
Definition ErrorMetric.h:27
int32_t size[5]
Definition Slice.cpp:35

References luci::size(), and size.


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