removed "Written by" line
[pspp-builds.git] / src / data / category.h
1 /* PSPP - Binary encodings for categorical variables.
2    Copyright (C) 2005 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    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, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17    02110-1301, USA. */
18
19 /*
20   Functions and data structures to recode categorical variables into
21   vectors and sub-rows of matrices.
22   
23   To fit many types of statistical models, it is necessary
24   to change each value of a categorical variable to a vector with binary
25   entries. These vectors are then stored as sub-rows within a matrix
26   during model-fitting. We need functions and data strucutres to,
27   e.g., map a value, say 'a', of a variable named 'cat_var', to a
28   vector, say (0 1 0 0 0), and vice versa.  We also need to be able
29   to map the vector back to the value 'a', and if the vector is a
30   sub-row of a matrix, we need to know which sub-row corresponds to
31   the variable 'cat_var'.
32
33  */
34
35 #ifndef CATEGORY_H
36 #define CATEGORY_H
37
38 #include <stddef.h>
39
40 struct cat_vals;
41 struct variable ; 
42 union value;
43
44 void cat_stored_values_create (const struct variable *);
45 void cat_stored_values_destroy (struct cat_vals *);
46
47 size_t cat_value_find (const struct variable *, const union value *);
48
49 const union value *cat_subscript_to_value (const size_t,
50                                            const struct variable *);
51
52
53 void cat_value_update (const struct variable *, const union value *);
54
55
56 /*
57   Return the number of categories of a categorical variable.
58  */
59 size_t  cat_get_n_categories (const struct variable *v);
60
61
62 #endif