Module running_float

Module running_float 

Source
Expand description

§Type

  • RunningFloat
    • RunningFloat provides statistical summaries of samples of type f64.

    • This includes a very coarse log histogram similar to the one that is provided for i64 data.

§Example

     use rustics::Rustics;
     use rustics::PrintOpts;
     use rustics::float_histogram::HistoOpts;
     use rustics::ExportStats;
     use rustics::printable::Printable;
     use rustics::running_float::RunningFloat;

     // Accept the default print options except for the histogram
     // option.  See the RunningInteger comments for an example of
     // how to set the other print options.

     // Create a HistoOpts for new().

     let merge_min    = 0;  // not implemented yet
     let merge_max    = 0;  // not implemented yet
     let no_zero_rows = true;

     let histo_opts = HistoOpts { merge_min, merge_max, no_zero_rows };
     let histo_opts = Some(histo_opts);
     let printer    = None;
     let title      = None;
     let units      = None;
     let print_opts = PrintOpts { printer, title, units, histo_opts };
     let print_opts = Some(print_opts);

     let mut float = RunningFloat::new("Test Statistic", &print_opts);
     let     end   = 1000;

     // Record the integers from 1 to "end".

     for i in 1..=end {
         float.record_f64(i as f64);
     }

     // Print our data.

     float.print();

    // Compute the expected mean.  We need the sum of
    //     1 + 2 + ... + n
    // which is
    //     n * (n + 1) / 2.

     let float_end = end as f64;
     let sum       = (float_end * (float_end + 1.0)) / 2.0;
     let mean      = sum / float_end;

     assert!(float.count()   == end as u64);
     assert!(float.mean()    == mean      );
     assert!(float.min_f64() == 1.0       );
     assert!(float.max_f64() == float_end );

     // The code should keep count of NaNs and non-finite
     // values, but not record them for the mean, etc.

     float.record_f64(f64::INFINITY);
     float.record_f64(f64::NEG_INFINITY);
     float.record_f64(f64::NAN);

     float.print();

     // NaN and non-finite values shouldn't be counted
     // as samples.

     assert!(float.mean()    == mean      );
     assert!(float.count()   == end as u64);

     // Check that the non-finite values were counted in their
     // special counters.  Test export_stats and the more direct
     // methods of getting those counts.

     let stats = float.export_stats();

     assert!(stats.printable.n          == end);
     assert!(stats.printable.nans       == 1);
     assert!(stats.printable.infinities == 2);

     assert!(float.nans()               == 1);
     assert!(float.infinities()         == 2);

     // Print all the summary information.

     float.print();

Structs§

FloatExporter
FloatExport is used by a Hier instance to make summations of multiple RunningFloat instances.
RunningFloat
This type implements a simple set of statistics for a sequence of f64 values.