1 /********************************************************************** 2 * File: statistc.h (Formerly stats.h) 3 * Description: Class description for STATS class. 4 * Author: Ray Smith 5 * Created: Mon Feb 04 16:19:07 GMT 1991 6 * 7 * (C) Copyright 1991, Hewlett-Packard Ltd. 8 ** Licensed under the Apache License, Version 2.0 (the "License"); 9 ** you may not use this file except in compliance with the License. 10 ** You may obtain a copy of the License at 11 ** http://www.apache.org/licenses/LICENSE-2.0 12 ** Unless required by applicable law or agreed to in writing, software 13 ** distributed under the License is distributed on an "AS IS" BASIS, 14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 ** See the License for the specific language governing permissions and 16 ** limitations under the License. 17 * 18 **********************************************************************/ 19 20 #ifndef STATISTC_H 21 #define STATISTC_H 22 23 #include <stdio.h> 24 #include "scrollview.h" 25 #include "host.h" 26 27 class DLLSYM STATS //statistics package 28 { 29 inT32 rangemin; //min of range 30 inT32 rangemax; //max of range 31 inT32 total_count; //no of samples 32 inT32 *buckets; //array of cells 33 34 public: 35 STATS( //constructor 36 inT32 min, //min of range 37 inT32 max); //max of range 38 STATS(); //empty for arrays 39 40 ~STATS (); //destructor 41 42 bool set_range( //change range 43 inT32 min, //min of range 44 inT32 max); //max of range 45 46 void clear(); //empty buckets 47 48 void add( //add sample 49 inT32 value, //bucket 50 inT32 count); //no to add 51 52 inT32 mode(); //get mode of samples 53 54 float mean(); //get mean of samples 55 56 float sd(); //standard deviation 57 58 float ile( //percentile 59 float frac); //[0,1] for percentil 60 61 inT32 min_bucket(); //Find min 62 63 inT32 max_bucket(); //Find max 64 65 float median(); //get median of samples 66 67 void smooth( //apply blurring 68 inT32 factor); //filter to stats 69 inT32 cluster( //cluster samples 70 float lower, //thresholds 71 float upper, 72 float multiple, //distance threshold 73 inT32 max_clusters, //max no to make 74 STATS *clusters); //array of clusters 75 pile_count(inT32 value)76 inT32 pile_count( //access function 77 inT32 value //pile to count 78 ) { 79 return value > rangemin ? (value < rangemax 80 ? buckets[value - 81 rangemin] : buckets[rangemax - 82 rangemin - 83 1]) : buckets[0]; 84 } 85 get_total()86 inT32 get_total() { //access function 87 return total_count; //total of all piles 88 } 89 90 BOOL8 local_min( //test local minness 91 inT32 x); 92 93 void print( //print summary/table 94 FILE *fp, //file to print on 95 BOOL8 dump); //dump whole table 96 97 void short_print( //print summary/table 98 FILE *fp, //file to print on 99 BOOL8 dump); //dump whole table 100 101 void plot( //draw histogram rect 102 ScrollView* window, //window to draw in 103 float xorigin, //origin of histo 104 float yorigin, //gram 105 float xscale, //size of one unit 106 float yscale, //size of one uint 107 ScrollView::Color colour); //colour to draw in 108 109 void plotline( //draw histogram line 110 ScrollView* window, //window to draw in 111 float xorigin, //origin of histo 112 float yorigin, //gram 113 float xscale, //size of one unit 114 float yscale, //size of one uint 115 ScrollView::Color colour); //colour to draw in 116 }; 117 DLLSYM inT32 choose_nth_item( //fast median 118 inT32 index, //index to choose 119 float *array, //array of items 120 inT32 count //no of items 121 ); 122 DLLSYM inT32 choose_nth_item ( //fast median 123 inT32 index, //index to choose 124 void *array, //array of items 125 inT32 count, //no of items 126 size_t size, //element size 127 //comparator 128 int (*compar) (const void *, const void *) 129 ); 130 void swap_entries( //swap in place 131 void *array, //array of entries 132 size_t size, //size of entry 133 inT32 index1, //entries to swap 134 inT32 index2); 135 #endif 136