math: Improve comments.
[pspp] / src / math / order-stats.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2004, 2008, 2011 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef __ORDER_STATS_H__
18 #define __ORDER_STATS_H__
19
20 /* Support for order statistics.
21
22    This data structure supplies infrastructure for higher-level statistics that
23    rely on order statistics.  It is a kind of "abstract base class" that is not
24    useful on its own.  The common pattern for using the statistics based on it
25    is this:
26
27    - Create the higher-level statistic with, for example, percentile_create().
28
29    - Feed in all the data with order_stats_accumulate() or
30      order_stats_accumulate_idx(). The data must be in sorted order: if
31      necessary, use one of the sorting functions from sort.h to sort them.
32
33    - Obtain the desired results by examining the higher-level data structure or
34      by calling an appropriate function, e.g. percentile_calculate().
35
36    - Destroy the data structure with statistic_destroy().
37 */
38
39 #include <stddef.h>
40 #include "data/missing-values.h"
41 #include "math/statistic.h"
42
43 struct casereader;
44 struct variable;
45
46 /*
47   cc <= tc < cc_p1
48 */
49 struct k
50 {
51   double tc;
52   double cc;
53   double cc_p1;
54   double c;
55   double c_p1;
56   double y;
57   double y_p1;
58 };
59
60 /* Order statistics calculation data structure.  See the comment at the top of
61    this file for usage details. */
62 struct order_stats
63 {
64   struct statistic parent;
65   int n_k;
66   struct k *k;
67
68   double cc;
69 };
70
71 void order_stats_accumulate_idx (struct order_stats **os, size_t n_os,
72                                  struct casereader *reader,
73                                  int weight_idx,
74                                  int data_idx);
75 void order_stats_accumulate (struct order_stats **os, size_t n_os,
76                              struct casereader *,
77                              const struct variable *weight_var,
78                              const struct variable *data_var,
79                              enum mv_class exclude);
80
81 /* Debugging support. */
82 void order_stats_dump (const struct order_stats *);
83
84 #endif