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