Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QualityAssessor::Assessor Class Reference

Per-metric QualityAssessor data. More...

#include <QualityAssessor.hpp>

Collaboration diagram for QualityAssessor::Assessor:

Public Member Functions

 Assessor (QualityMetric *metric)
 
double get_average () const
 
double get_maximum () const
 
double get_minimum () const
 
double get_rms () const
 
double get_stddev () const
 
int get_count () const
 
int get_invalid_element_count () const
 
void get_histogram (double &lower_bound_out, double &upper_bound_out, msq_std::vector< int > &counts_out, MsqError &err) const
 Get historgram of data, if calculated. More...
 
void reset_data ()
 Reset all calculated data. More...
 
void print_histogram (msq_stdio::ostream &) const
 Print the histogram. More...
 
QualityMetricget_metric () const
 Get the QualityMetric. More...
 
void add_value (double metric_value)
 Add a value to the running counts. More...
 
void add_hist_value (double metric_value)
 Add a value to the hisogram data. More...
 
void add_invalid_value ()
 Note invalid result. More...
 
void calculate_histogram_range ()
 If range of histogram has not yet been determined, calculate it from the min/max values. More...
 
 Assessor (QualityMetric *metric)
 
double get_average () const
 
double get_maximum () const
 
double get_minimum () const
 
double get_rms () const
 
double get_stddev () const
 
int get_count () const
 
int get_invalid_element_count () const
 
void get_histogram (double &lower_bound_out, double &upper_bound_out, msq_std::vector< int > &counts_out, MsqError &err) const
 Get historgram of data, if calculated. More...
 
void reset_data ()
 Reset all calculated data. More...
 
void print_histogram (msq_stdio::ostream &) const
 Print the histogram. More...
 
QualityMetricget_metric () const
 Get the QualityMetric. More...
 
void add_value (double metric_value)
 Add a value to the running counts. More...
 
void add_hist_value (double metric_value)
 Add a value to the hisogram data. More...
 
void add_invalid_value ()
 Note invalid result. More...
 
void calculate_histogram_range ()
 If range of histogram has not yet been determined, calculate it from the min/max values. More...
 

Private Attributes

QualityMetric *const qualMetric
 
unsigned funcFlags
 
unsigned long count
 
double sum
 
double maximum
 
double minimum
 
double sqrSum
 
unsigned long numInvalid
 
bool haveHistRange
 The histogram counts, where the first and last values are counts of values below the lower bound and above the upper bound, respectively. More...
 
double histMin
 
double histMax
 
msq_std::vector< int > histogram
 

Friends

class QualityAssessor
 

Detailed Description

Per-metric QualityAssessor data.

The Assessor class holds QualityAssessor data for each metric added by the calling application, including a pointer to the metric instance, QAFunction flags dictating what is to be calculated and output, histogram parameters, and the variables used to accumulate results as the QualityAssessor is running. It also provides methods to access the calculated data once the QualityAssessor pass is completed.

Definition at line 196 of file includeLinks/QualityAssessor.hpp.

Constructor & Destructor Documentation

Assessor ( QualityMetric metric)

Definition at line 508 of file QualityAssessor/QualityAssessor.cpp.

References QualityAssessor::Assessor::reset_data().

509  : qualMetric(metric),
510  funcFlags(0),
511  haveHistRange(false),
512  histMin(1.0),
513  histMax(0.0)
514 {
515  reset_data();
516 }
bool haveHistRange
The histogram counts, where the first and last values are counts of values below the lower bound and ...
Definition: metric.h:35

Here is the call graph for this function:

Assessor ( QualityMetric metric)

Member Function Documentation

void add_hist_value ( double  metric_value)

Add a value to the hisogram data.

Definition at line 585 of file QualityAssessor/QualityAssessor.cpp.

586 {
587  // Width of one interval in histogram
588  double step = (histMax - histMin) / (histogram.size()-2);
589 
590  // First and last values in array are counts of values
591  // outside the user-specified range of the histogram
592  // (below and above, respectively.)
593  if (metric_value < histMin)
594  ++histogram[0];
595  else if (metric_value > histMax)
596  ++histogram[histogram.size()-1];
597  else
598  {
599  // Calculate which interval the value is in. Add one
600  // because first entry is for values below user-specifed
601  // minimum value for histogram.
602  unsigned cell;
603  if (step > DBL_EPSILON)
604  cell = 1+(unsigned)((metric_value - histMin) / step);
605  else
606  cell = 1;
607 
608  // If value exactly equals maximum value, put in last
609  // valid interval, not the count of values above the
610  // maximum.
611  if (cell + 1 == histogram.size())
612  --cell;
613  // Add value to interval.
614  ++histogram[cell];
615  }
616 }
void add_hist_value ( double  metric_value)

Add a value to the hisogram data.

void add_invalid_value ( )

Note invalid result.

Definition at line 580 of file QualityAssessor/QualityAssessor.cpp.

581 {
582  ++numInvalid;
583 }
void add_invalid_value ( )

Note invalid result.

void add_value ( double  metric_value)

Add a value to the running counts.

void add_value ( double  metric_value)

Add a value to the running counts.

Definition at line 562 of file QualityAssessor/QualityAssessor.cpp.

References QualityAssessor::HISTOGRAM.

563 {
564  sum += metric_value;
565  sqrSum += metric_value*metric_value;
566  if (metric_value > maximum)
567  maximum = metric_value;
568  if (metric_value < minimum)
569  minimum = metric_value;
570  // Only add value to histogram data from this function if
571  // the user has specified the range. If user has not
572  // specified the range, QualityAssessor will call add_hist_value()
573  // directly once the range has been calculated.
575  add_hist_value( metric_value );
576 
577  ++count;
578 }
bool haveHistRange
The histogram counts, where the first and last values are counts of values below the lower bound and ...
void add_hist_value(double metric_value)
Add a value to the hisogram data.
void calculate_histogram_range ( )

If range of histogram has not yet been determined, calculate it from the min/max values.

void calculate_histogram_range ( )

If range of histogram has not yet been determined, calculate it from the min/max values.

Definition at line 618 of file QualityAssessor/QualityAssessor.cpp.

References cimg_library::log10(), and Mesquite::pow().

619 {
620  double step = (maximum - minimum) / (histogram.size() - 2);
621  double size = pow( 10, ceil(log10(step)) );
622  histMin = size * floor( minimum / size );
623  histMax = size * ceil( maximum / size );
624 }
CImg< _cimg_Tfloat > log10(const CImg< T > &instance)
Definition: CImg.h:6026
double pow(double value, const Exponent &exp)

Here is the call graph for this function:

double get_average ( ) const
double get_average ( ) const
int get_count ( ) const
inline
int get_count ( ) const
inline
void get_histogram ( double &  lower_bound_out,
double &  upper_bound_out,
msq_std::vector< int > &  counts_out,
MsqError err 
) const

Get historgram of data, if calculated.

Parameters
lower_bound_outThe lower bound of the histogram
upper_bound_outThe upper bound of the histogram
counts_outAn array of counts of elements where the first entry is the number of elements for which the metric is below the lower bound, the last entry is the number of elements above the upper bound, and all other values are the counts for histogram intervals between the lower and upper bounds.

Definition at line 528 of file QualityAssessor/QualityAssessor.cpp.

References QualityAssessor::HISTOGRAM, MsqError::INVALID_STATE, and MSQ_SETERR.

532 {
534  {
535  MSQ_SETERR(err)("No histogram calculated.", MsqError::INVALID_STATE);
536  return;
537  }
538 
539  if (haveHistRange) {
540  lower_bound_out = histMin;
541  upper_bound_out = histMax;
542  }
543  else {
544  lower_bound_out = minimum;
545  upper_bound_out = maximum;
546  }
547 
548  counts_out = histogram;
549 }
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
bool haveHistRange
The histogram counts, where the first and last values are counts of values below the lower bound and ...
object is in an invalid state
void get_histogram ( double &  lower_bound_out,
double &  upper_bound_out,
msq_std::vector< int > &  counts_out,
MsqError err 
) const

Get historgram of data, if calculated.

Parameters
lower_bound_outThe lower bound of the histogram
upper_bound_outThe upper bound of the histogram
counts_outAn array of counts of elements where the first entry is the number of elements for which the metric is below the lower bound, the last entry is the number of elements above the upper bound, and all other values are the counts for histogram intervals between the lower and upper bounds.
int get_invalid_element_count ( ) const
inline
int get_invalid_element_count ( ) const
inline
double get_maximum ( ) const
inline
double get_maximum ( ) const
inline
QualityMetric* get_metric ( ) const
inline
QualityMetric* get_metric ( ) const
inline
double get_minimum ( ) const
inline
double get_minimum ( ) const
inline
double get_rms ( ) const

Definition at line 146 of file QualityAssessor/QualityAssessor.cpp.

References sqrt().

147 {
148  return count ? sqrt(sqrSum/count) : 0;
149 }
double sqrt(double d)
Definition: double.h:73

Here is the call graph for this function:

double get_rms ( ) const
double get_stddev ( ) const
double get_stddev ( ) const

Definition at line 151 of file QualityAssessor/QualityAssessor.cpp.

References cimg_library::cimg::sqr(), and sqrt().

152 {
153  double sqr = sqrSum/count - sum*sum/((double)count*count);
154  return sqr < 0 ? 0 : sqrt(sqr);
155 }
double sqrt(double d)
Definition: double.h:73
T sqr(const T val)
Return the square of a number.
Definition: CImg.h:4717

Here is the call graph for this function:

void print_histogram ( msq_stdio::ostream &  stream) const

Print the histogram.

Definition at line 737 of file QualityAssessor/QualityAssessor.cpp.

References i, cimg_library::log10(), max(), and min().

738 {
739  // Portability notes:
740  // Use log10 rather than log10f because the float variations require
741  // including platform-dependent headers on some platforms.
742  // Explicitly cast log10 argument to double because some platforms
743  // have overloaded float and double variations in C++ making an
744  // implicit cast from an integer ambiguous.
745 
746  const char GRAPH_CHAR = '='; // Character used to create bar graphs
747  const int FLOATW = 12; // Width of floating-point output
748  const int GRAPHW = 50; // Width of bar graph
749 
750  // range is either user-specified (histMin & histMax) or
751  // calculated (minimum & maximum)
752  double min, max;
753  //if (haveHistRange) {
754  min = histMin;
755  max = histMax;
756  //}
757  //else {
758  // min = minimum;
759  // max = maximum;
760  //}
761  // Witdh of one interval of histogram
762  double step = (max - min) / (histogram.size()-2);
763 
764  // Find maximum value for an interval of the histogram
765  unsigned i;
766  int max_interval = 1;
767  for (i = 0; i < histogram.size(); ++i)
768  if (histogram[i] > max_interval)
769  max_interval = histogram[i];
770 
771  if (0 == max_interval)
772  return; // no data
773 
774  // Calculate width of field containing counts for
775  // histogram intervals (log10(max_interval)).
776  int num_width = 1;
777  for (int temp = max_interval; temp > 0; temp /= 10)
778  ++num_width;
779 
780  // Create an array of bar graph characters for use in output
781  char graph_chars[GRAPHW+1];
782  memset( graph_chars, GRAPH_CHAR, sizeof(graph_chars) );
783 
784  // Check if bar-graph should be linear or log10 plot
785  // Do log plot if standard deviation is less that 1.5
786  // histogram intervals.
787  bool log_plot = false;
788  double stddev = get_stddev();
789  if (stddev > 0 && stddev < 2.0*step)
790  {
791  int new_interval = (int)(log10((double)(1+max_interval)));
792  if (new_interval > 0) {
793  log_plot = true;
794  max_interval = new_interval;
795  }
796  }
797 
798 
799  // Write title
800  stream << msq_stdio::endl << " " << get_metric()->get_name() << " histogram:";
801  if (log_plot)
802  stream << " (log10 plot)";
803  stream << msq_stdio::endl;
804 
805 
806  // For each interval of histogram
807  for (i = 0; i < histogram.size(); ++i)
808  {
809  // First value is the count of the number of values that
810  // were below the minimum value of the histogram.
811  if (0 == i)
812  {
813  if (0 == histogram[i])
814  continue;
815  stream << setw(FLOATW) << "under min";
816  }
817  // Last value is the count of the number of values that
818  // were above the maximum value of the histogram.
819  else if (i+1 == histogram.size())
820  {
821  if (0 == histogram[i])
822  continue;
823  stream << setw(FLOATW) << "over max";
824  }
825  // Anything else is a valid interval of the histogram.
826  // Print the lower bound for each interval.
827  else
828  {
829  stream << " " << setw(FLOATW) << min + (i-1)*step;
830  }
831 
832  // Print interval count.
833  stream << ": " << setw(num_width) << histogram[i] << ": ";
834 
835  // Print bar graph
836 
837  // First calculate the number of characters to output
838  int num_graph;
839  if (log_plot)
840  num_graph = GRAPHW * (int)log10((double)(1+histogram[i])) / max_interval;
841  else
842  num_graph = GRAPHW * histogram[i] / max_interval;
843 
844  // print num_graph characters using array of fill characters.
845  graph_chars[num_graph] = '\0';
846  stream << graph_chars << msq_stdio::endl;
847  graph_chars[num_graph] = GRAPH_CHAR;
848  }
849 
850  stream << msq_stdio::endl;
851 }
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
QualityMetric * get_metric() const
Get the QualityMetric.
blockLoc i
Definition: read.cpp:79
CImg< _cimg_Tfloat > log10(const CImg< T > &instance)
Definition: CImg.h:6026
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
msq_std::string get_name()
Returns the name of this metric (as a string).

Here is the call graph for this function:

void print_histogram ( msq_stdio::ostream &  ) const

Print the histogram.

void reset_data ( )

Reset all calculated data.

Definition at line 551 of file QualityAssessor/QualityAssessor.cpp.

Referenced by QualityAssessor::Assessor::Assessor().

Here is the caller graph for this function:

void reset_data ( )

Reset all calculated data.

Friends And Related Function Documentation

Definition at line 252 of file includeLinks/QualityAssessor.hpp.

Member Data Documentation

unsigned long count
private
unsigned funcFlags
private

Definition at line 255 of file includeLinks/QualityAssessor.hpp.

bool haveHistRange
private

The histogram counts, where the first and last values are counts of values below the lower bound and above the upper bound, respectively.

The remaining values are the histogram counts.

Definition at line 270 of file includeLinks/QualityAssessor.hpp.

double histMax
private

Definition at line 272 of file includeLinks/QualityAssessor.hpp.

double histMin
private

Definition at line 271 of file includeLinks/QualityAssessor.hpp.

msq_std::vector< int > histogram
private

Definition at line 273 of file includeLinks/QualityAssessor.hpp.

double maximum
private
double minimum
private
unsigned long numInvalid
private
QualityMetric *const qualMetric
private
double sqrSum
private

Definition at line 262 of file includeLinks/QualityAssessor.hpp.

double sum
private

Definition at line 259 of file includeLinks/QualityAssessor.hpp.


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