8c268de42422f36504f75e87e05f2e8c85afa0d8
[pspp-builds.git] / src / math / design-matrix.h
1 /* PSPP - Creates design matrices.
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   Create design matrices for procedures that need them.
22  */
23
24 #ifndef DESIGN_MATRIX_H
25 #define DESIGN_MATRIX_H
26
27 #include <gsl/gsl_matrix.h>
28 #include <stdbool.h>
29 #include <data/category.h>
30 #include <data/cat-routines.h>
31 struct design_matrix_var
32 {
33   size_t first_column;          /* First column for this variable in
34                                    the design_matix. If this variable
35                                    is categorical, its values are
36                                    stored in multiple, contiguous
37                                    columns, as dictated by its vector
38                                    encoding in the variable's struct
39                                    cat_vals.
40                                  */
41   size_t last_column;
42   const struct variable *v;
43 };
44 struct design_matrix
45 {
46   gsl_matrix *m;
47   struct design_matrix_var *vars;       /* Element i corresponds to
48                                            the variable whose values
49                                            are stored in at least one
50                                            column of m. If that
51                                            variable is categorical
52                                            with more than two
53                                            categories, its values are
54                                            stored in multiple,
55                                            contiguous columns. The
56                                            variable's values are then
57                                            stored in the columns
58                                            first_column through
59                                            last_column of the
60                                            design_matrix_var
61                                            structure.
62                                          */
63   size_t n_vars;
64 };
65 union value *cat_vector_to_value (const gsl_vector *, struct variable *);
66
67 struct design_matrix *design_matrix_create (int, const struct variable *[],
68                                             const size_t);
69
70 void design_matrix_destroy (struct design_matrix *);
71
72 void design_matrix_set_categorical (struct design_matrix *, size_t,
73                                     const struct variable *,
74                                     const union value *);
75
76 void design_matrix_set_numeric (struct design_matrix *, size_t,
77                                 const struct variable *, const union value *);
78
79 size_t design_matrix_var_to_column (const struct design_matrix *,
80                                     const struct variable *);
81
82 struct variable *design_matrix_col_to_var (const struct design_matrix *,
83                                            size_t);
84
85 #endif