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