Histograms


os_histogram class provides the capability to represent and manipulate data in histograms. It provides various methods to create bins in the histogram and add data to the histogram.

The example code below shows how to use various methods supported by the os_histogram class.

Example <ospace/math/examples/histogram.cpp>
#include <ospace/math.h>


int
main()
  {
  os_math_toolkit math_init;

  os_num_vector< double > vec;
  os_rand_poisson randgen( 50 );
  randgen.fill_values( 1000, vec );

  os_histogram hgram( 5, 40, 60 );
  hgram.add_data( vec );

  cout << "Total number of data points = \t" << hgram.num_data_points() << endl;
  cout << "Total number of bins = \t\t" << hgram.num_bins() << endl;
  cout << "Number of larger points = \t" << hgram.num_larger() << endl;
  cout << "Number of smaller points = \t" << hgram.num_smaller() << endl;
  cout << endl;

  os_num_vector< double > bin_bounds;
  hgram.bin_boundaries( bin_bounds );

  cout << "Bin Number\t- Bin Bounds -\tCount" << endl;
  for ( int i = 0; i < hgram.num_bins(); i++ )
    {
    cout << "    " << i << "\t\t    " << bin_bounds[ i ] << " " << bin_bounds[ i + 1 ] << "\t" << hgram.bin_count( i ) << endl;
    }


  return 0;
  }

Copyright©1994-2013 Recursion Software LLC
All Rights Reserved - For use by licensed users only.