Fix warnings
[pspp-builds.git] / src / math / categoricals.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2010, 2011, 2012 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
18 #ifndef _CATEGORICALS__
19 #define _CATEGORICALS__
20
21 #include <stddef.h>
22 #include "data/missing-values.h"
23
24 struct categoricals;
25 struct variable;
26 struct ccase;
27 struct interaction;
28
29 union value ;
30
31 struct categoricals *categoricals_create (struct interaction *const *, size_t n_int,
32                                           const struct variable *wv, enum mv_class exclude);
33
34 void categoricals_destroy (struct categoricals *);
35
36 void categoricals_update (struct categoricals *cat, const struct ccase *c);
37
38
39 /* Return the number of categories (distinct values) for variable N */
40 size_t categoricals_n_count (const struct categoricals *cat, size_t n);
41
42 size_t categoricals_df (const struct categoricals *cat, size_t n);
43
44 /* Return the total number of categories */
45 size_t categoricals_n_total (const struct categoricals *cat);
46
47 /* Return the total degrees of freedom */
48 size_t categoricals_df_total (const struct categoricals *cat);
49
50
51 /*
52   Return the total number of variables which participated in these categoricals.
53   Due to the possibility of missing values, this is NOT necessarily
54   equal to the number of variables passed in when the object was
55   created.
56 */
57 size_t categoricals_get_n_variables (const struct categoricals *cat);
58
59
60 bool categoricals_is_complete (const struct categoricals *cat);
61
62
63 /*
64   Must be called (once) before any call to the *_by_subscript or *_by_category
65   functions, but AFTER any calls to categoricals_update.
66   If this function returns false, then no calls to _by_subscript or *_by_category
67   are allowed.
68 */
69 bool categoricals_done (const struct categoricals *cat);
70
71
72 /*
73   The *_by_subscript functions use the short map.
74   Their intended use is by covariance matrix routines, where normally 1 less than 
75   the total number of distinct values of each categorical variable should
76   be considered.
77  */
78 double categoricals_get_weight_by_subscript (const struct categoricals *cat, int subscript);
79 const struct interaction *categoricals_get_interaction_by_subscript (const struct categoricals *cat, int subscript);
80
81 double categoricals_get_sum_by_subscript (const struct categoricals *cat, int subscript);
82
83 double categoricals_get_code_for_case (const struct categoricals *cat, int subscript, const struct ccase *c);
84
85
86 /* These use the long map.  Useful for descriptive statistics. */
87
88 /* Return the value corresponding to the N'th category */
89 const union value * categoricals_get_value_by_category (const struct categoricals *cat, int n);
90
91 const struct ccase *
92 categoricals_get_case_by_category_real (const struct categoricals *cat, int iact, int n);
93
94 void *
95 categoricals_get_user_data_by_category_real (const struct categoricals *cat, int iact, int n);
96
97
98 void * categoricals_get_user_data_by_category (const struct categoricals *cat, int category);
99
100 const struct ccase * categoricals_get_case_by_category (const struct categoricals *cat, int subscript);
101
102
103 struct payload
104 {
105   void* (*create)  (const void *aux1, void *aux2);
106   void (*update)  (const void *aux1, void *aux2, void *user_data, const struct ccase *, double weight);
107   void (*destroy) (const void *aux1, void *aux2, void *user_data);
108 };
109
110
111 void  categoricals_set_payload (struct categoricals *cats, const struct payload *p, const void *aux1, void *aux2);
112
113
114 #endif