MOAB: Mesh Oriented datABase  (version 5.4.1)
MBMesquite::QualityAssessor::Assessor Class Reference

Per-metric QualityAssessor data. More...

#include <QualityAssessor.hpp>

+ Collaboration diagram for MBMesquite::QualityAssessor::Assessor:

Public Member Functions

MESQUITE_EXPORT Assessor (QualityMetric *metric, const char *name=0)
MESQUITE_EXPORT double get_average () const
MESQUITE_EXPORT double get_maximum () const
MESQUITE_EXPORT double get_minimum () const
MESQUITE_EXPORT double get_rms () const
MESQUITE_EXPORT double get_stddev () const
MESQUITE_EXPORT double get_power_mean () const
MESQUITE_EXPORT double get_power () const
MESQUITE_EXPORT int get_count () const
MESQUITE_EXPORT bool have_power_mean () const
MESQUITE_EXPORT int get_invalid_element_count () const
MESQUITE_EXPORT void get_histogram (double &lower_bound_out, double &upper_bound_out, std::vector< int > &counts_out, MsqError &err) const
MESQUITE_EXPORT void reset_data ()
MESQUITE_EXPORT void print_histogram (std::ostream &, int width=0) const
MESQUITE_EXPORT QualityMetricget_metric () const
MESQUITE_EXPORT const std::string & get_label () const
MESQUITE_EXPORT void add_value (double metric_value)
MESQUITE_EXPORT void add_hist_value (double metric_value)
MESQUITE_EXPORT void add_invalid_value ()
MESQUITE_EXPORT bool have_histogram () const
MESQUITE_EXPORT void calculate_histogram_range ()
MESQUITE_EXPORT bool write_to_tag () const
MESQUITE_EXPORT void set_stopping_function (bool value)
MESQUITE_EXPORT bool stopping_function () const
MESQUITE_EXPORT double stopping_function_value () const

Private Attributes

QualityMetric *const qualMetric
std::string mLabel
unsigned long count
double sum
double maximum
double minimum
double sqrSum
double pSum
unsigned long numInvalid
double pMean
bool haveHistRange
double histMin
double histMax
std::vector< int > histogram
std::string tagName
TagHandle tagHandle
bool stoppingFunction
int referenceCount
enum AssessSchemes assessScheme

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 416 of file QualityAssessor.hpp.


Constructor & Destructor Documentation

MBMesquite::QualityAssessor::Assessor::Assessor ( QualityMetric metric,
const char *  name = 0 
)

Definition at line 1151 of file QualityAssessor.cpp.

References reset_data().

    : qualMetric( metric ), mLabel( label ? std::string( label ) : metric->get_name() ), pMean( 0.0 ),
      haveHistRange( false ), histMin( 1.0 ), histMax( 0.0 ), tagHandle( 0 ), stoppingFunction( false ),
      referenceCount( 0 ), assessScheme( NO_SCHEME )
{
    reset_data();
}

Member Function Documentation

Add a value to the hisogram data

Definition at line 1229 of file QualityAssessor.cpp.

{
    // First and last values in array are counts of values
    // outside the user-specified range of the histogram
    // (below and above, respectively.)
    if( metric_value < histMin )
        ++histogram[0];
    else if( metric_value > histMax )
        ++histogram[histogram.size() - 1];
    else
    {
        // Calculate which interval the value is in.  Add one
        // because first entry is for values below user-specifed
        // minimum value for histogram.
        double range = histMax - histMin;
        double fract;
        if( range > DBL_EPSILON )
            fract = ( metric_value - histMin ) / range;
        else
            fract = 0.0;
        unsigned cell;
        if( fabs( fract - 1.0 ) < histMax * DBL_EPSILON )
            cell = histogram.size() - 1;
        else
            cell = 1 + (int)( ( fract * ( histogram.size() - 2 ) ) );

        // Add value to interval.
        ++histogram[cell];
    }
}

Note invalid result

Definition at line 1224 of file QualityAssessor.cpp.

{
    ++numInvalid;
}
void MBMesquite::QualityAssessor::Assessor::add_value ( double  metric_value)

Add a value to the running counts

Definition at line 1207 of file QualityAssessor.cpp.

References moab::sum().

{
    sum += metric_value;
    sqrSum += metric_value * metric_value;
    if( metric_value > maximum ) maximum = metric_value;
    if( metric_value < minimum ) minimum = metric_value;
    // Only add value to histogram data from this function if
    // the user has specified the range.  If user has not
    // specified the range, QualityAssessor will call add_hist_value()
    // directly once the range has been calculated.
    if( have_histogram() && haveHistRange ) add_hist_value( metric_value );

    if( have_power_mean() ) pSum += pow( metric_value, pMean );

    ++count;
}

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

Definition at line 1260 of file QualityAssessor.cpp.

References size.

{
    double lower_bound = minimum;
    int num_intervals  = histogram.size();
    double step        = ( maximum - lower_bound ) / num_intervals;
    if( step == 0 ) step = 1.0;
    double size = pow( 10.0, floor( log10( step / ( num_intervals - 1 ) ) ) );
    if( size < 1e-6 ) size = 1.0;
    histMin = lower_bound;
    histMax = lower_bound + num_intervals * size * ceil( step / size );
}

Definition at line 203 of file QualityAssessor.cpp.

References count, and sum.

Referenced by main(), and run().

{
    return count ? sum / count : 0;
}

Definition at line 437 of file QualityAssessor.hpp.

References count.

Referenced by QualityAssessorTest::test_free_only().

        {
            return count;
        }
void MBMesquite::QualityAssessor::Assessor::get_histogram ( double &  lower_bound_out,
double &  upper_bound_out,
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 1175 of file QualityAssessor.cpp.

References MBMesquite::MsqError::INVALID_STATE, and MSQ_SETERR.

Referenced by QualityAssessorTest::test_histogram_known_range(), and QualityAssessorTest::test_histogram_unknown_range().

{
    if( !have_histogram() )
    {
        MSQ_SETERR( err )( "No histogram calculated.", MsqError::INVALID_STATE );
        return;
    }

    lower_bound_out = histMin;
    upper_bound_out = histMax;
    counts_out      = histogram;
}

Definition at line 481 of file QualityAssessor.hpp.

References mLabel.

        {
            return mLabel;
        }

Definition at line 422 of file QualityAssessor.hpp.

References maximum.

        {
            return maximum;
        }

Get the QualityMetric

Definition at line 476 of file QualityAssessor.hpp.

References qualMetric.

        {
            return qualMetric;
        }

Definition at line 426 of file QualityAssessor.hpp.

References minimum.

        {
            return minimum;
        }

Definition at line 433 of file QualityAssessor.hpp.

References pMean.

Referenced by QualityAssessorTest::test_power_mean().

        {
            return pMean;
        }

Definition at line 219 of file QualityAssessor.cpp.

Referenced by QualityAssessorTest::test_power_mean().

{
    return ( count && pMean ) ? pow( pSum / count, 1 / pMean ) : 0;
}

Definition at line 208 of file QualityAssessor.cpp.

{
    return count ? sqrt( sqrSum / count ) : 0;
}

Definition at line 213 of file QualityAssessor.cpp.

References moab::sum().

Referenced by main().

{
    double sqr = count ? sqrSum / count - sum * sum / ( (double)count * count ) : 0;
    return sqr < 0 ? 0 : sqrt( sqr );
}
void MBMesquite::QualityAssessor::Assessor::print_histogram ( std::ostream &  stream,
int  width = 0 
) const

Print the histogram

Definition at line 1473 of file QualityAssessor.cpp.

References MBMesquite::arrptr(), and MBMesquite::QualityAssessor::round_to_3_significant_digits().

{
    // Portability notes:
    //  Use log10 rather than log10f because the float variations require
    //  including platform-dependent headers on some platforms.
    //  Explicitly cast log10 argument to double because some platforms
    //  have overloaded float and double variations in C++ making an
    //  implicit cast from an integer ambiguous.

    const char indent[]   = "   ";
    const char GRAPH_CHAR = '=';                              // Character used to create bar graphs
    const int TOTAL_WIDTH = termwidth > 30 ? termwidth : 70;  // Width of histogram
    int GRAPHW            = TOTAL_WIDTH - sizeof( indent );

    // range is either user-specified (histMin & histMax) or
    // calculated (minimum & maximum)
    double min, max;
    min = histMin;
    max = histMax;
    // Witdh of one interval of histogram
    double step = ( max - min ) / ( histogram.size() - 2 );
    // round step to 3 significant digits

    if( step >= 0.001 ) step = round_to_3_significant_digits( step );

    // Find maximum value for an interval bin of the histogram
    unsigned i;
    int max_bin_value = 1;
    for( i = 0; i < histogram.size(); ++i )
        if( histogram[i] > max_bin_value ) max_bin_value = histogram[i];

    if( 0 == max_bin_value ) return;  // no data

    // Calculate width of field containing counts for
    // histogram intervals (log10(max_bin_value)).
    int num_width = 1;
    for( int temp = max_bin_value; temp > 0; temp /= 10 )
        ++num_width;
    GRAPHW -= num_width;

    // Create an array of bar graph characters for use in output
    std::vector< char > graph_chars( GRAPHW + 1, GRAPH_CHAR );

    // Check if bar-graph should be linear or log10 plot
    // Do log plot if standard deviation is less that 1.5
    // histogram intervals.
    bool log_plot = false;
    double stddev = get_stddev();
    if( stddev > 0 && stddev < 2.0 * step )
    {
        int new_interval = (int)( log10( (double)( 1 + max_bin_value ) ) );
        if( new_interval > 0 )
        {
            log_plot      = true;
            max_bin_value = new_interval;
        }
    }

    // Write title
    stream << indent << get_label() << " histogram:";
    if( log_plot ) stream << " (log10 plot)";
    stream << std::endl;

    // Calculate width of a single quality interval value

    double interval_value  = 0.0;
    int max_interval_width = 0;
    std::stringstream str_stream;
    std::string interval_string;
    for( i = 0; i < histogram.size(); ++i )
    {
        interval_value = min + (i)*step;
        if( step >= 0.001 ) interval_value = round_to_3_significant_digits( interval_value );
        str_stream.clear();
        str_stream.str( "" );
        interval_string = "";
        str_stream << interval_value;
        interval_string = str_stream.str();
        if( interval_string.length() > (size_t)max_interval_width ) max_interval_width = interval_string.length();
    }

    // adjust graph width for actual size of interval values
    GRAPHW = GRAPHW - ( max_interval_width * 2 ) - 5;

    // For each interval of histogram
    for( i = 0; i < histogram.size(); ++i )
    {
        // First value is the count of the number of values that
        // were below the minimum value of the histogram.
        if( 0 == i )
        {
            if( 0 == histogram[i] ) continue;
            stream << indent << std::setw( max_interval_width ) << "under min";
        }
        // Last value is the count of the number of values that
        // were above the maximum value of the histogram.
        else if( i + 1 == histogram.size() )
        {
            if( 0 == histogram[i] ) continue;
            stream << indent << std::setw( max_interval_width ) << "over max";
        }
        // Anything else is a valid interval of the histogram.
        // Print the range for each interval.
        else
        {
            double start_value = min + ( i - 1 ) * step;
            double end_value   = min + (i)*step;
            if( step >= 0.001 )
            {
                start_value = round_to_3_significant_digits( start_value );
                end_value   = round_to_3_significant_digits( end_value );
            }

            stream << indent << "(" << std::setw( max_interval_width ) << std::right << start_value << "-"
                   << std::setw( max_interval_width ) << std::left << end_value << ") |";

            // reset stream alignment to right (the default)
            stream << std::right;
        }

        // Print bar graph

        // First calculate the number of characters to output
        int num_graph;
        if( log_plot )
            num_graph = GRAPHW * (int)log10( (double)( 1 + histogram[i] ) ) / max_bin_value;
        else
            num_graph = GRAPHW * histogram[i] / max_bin_value;

        // print num_graph characters using array of fill characters.
        graph_chars[num_graph] = '\0';
        stream << arrptr( graph_chars );
        graph_chars[num_graph] = GRAPH_CHAR;

        // Print interval count.
        stream << histogram[i] << std::endl;
    }
    stream << "  metric was evaluated " << count << " times." << std::endl << std::endl;
}

Reset all calculated data

Definition at line 1191 of file QualityAssessor.cpp.

References MBMesquite::NO_SCHEME, and moab::sum().

Referenced by Assessor().

{
    count        = 0;
    sum          = 0;
    maximum      = -HUGE_VAL;
    minimum      = HUGE_VAL;
    sqrSum       = 0;
    pSum         = 0;
    numInvalid   = 0;
    assessScheme = NO_SCHEME;
    // zero histogram data
    size_t hist_size = histogram.size();
    histogram.clear();
    histogram.resize( hist_size, 0 );
}

Definition at line 505 of file QualityAssessor.hpp.

References tagName.

        {
            return !tagName.empty();
        }

Friends And Related Function Documentation

friend class QualityAssessor [friend]

Definition at line 523 of file QualityAssessor.hpp.


Member Data Documentation

Definition at line 528 of file QualityAssessor.hpp.

Referenced by get_average(), and get_count().

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 544 of file QualityAssessor.hpp.

Definition at line 546 of file QualityAssessor.hpp.

Definition at line 545 of file QualityAssessor.hpp.

Definition at line 547 of file QualityAssessor.hpp.

Referenced by have_histogram().

Definition at line 531 of file QualityAssessor.hpp.

Referenced by get_maximum().

Definition at line 532 of file QualityAssessor.hpp.

Referenced by get_minimum().

Definition at line 526 of file QualityAssessor.hpp.

Referenced by get_label().

Definition at line 535 of file QualityAssessor.hpp.

Referenced by get_invalid_element_count().

Definition at line 537 of file QualityAssessor.hpp.

Referenced by get_power(), and have_power_mean().

Definition at line 534 of file QualityAssessor.hpp.

Definition at line 525 of file QualityAssessor.hpp.

Referenced by get_metric().

Definition at line 533 of file QualityAssessor.hpp.

Value is return value for all of QualityAssessor

Definition at line 554 of file QualityAssessor.hpp.

Referenced by set_stopping_function(), and stopping_function().

Definition at line 530 of file QualityAssessor.hpp.

Referenced by get_average().

Cached tag handle

Definition at line 551 of file QualityAssessor.hpp.

Definition at line 549 of file QualityAssessor.hpp.

Referenced by write_to_tag().

List of all members.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines