output: Include command names in titles in GUI output.
[pspp-builds.git] / src / math / design-matrix.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2005 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   Create design matrices for procedures that need them.
19  */
20
21 #ifndef DESIGN_MATRIX_H
22 #define DESIGN_MATRIX_H
23
24 #include <gsl/gsl_matrix.h>
25 #include <stdbool.h>
26 #include <data/category.h>
27
28 struct design_matrix_var
29 {
30   size_t first_column;          /* First column for this variable in
31                                    the design_matix. If this variable
32                                    is categorical, its values are
33                                    stored in multiple, contiguous
34                                    columns, as dictated by its vector
35                                    encoding in the variable's struct
36                                    cat_vals.
37                                  */
38   size_t last_column;
39   const struct variable *v;
40 };
41
42 struct design_matrix
43 {
44   gsl_matrix *m;
45   struct design_matrix_var *vars;       /* Element i corresponds to
46                                            the variable whose values
47                                            are stored in at least one
48                                            column of m. If that
49                                            variable is categorical
50                                            with more than two
51                                            categories, its values are
52                                            stored in multiple,
53                                            contiguous columns. The
54                                            variable's values are then
55                                            stored in the columns
56                                            first_column through
57                                            last_column of the
58                                            design_matrix_var
59                                            structure.
60                                          */
61   size_t *n_cases; /* Element i is the number of valid cases for this
62                       variable.
63                     */
64   size_t n_vars;
65 };
66
67
68 struct design_matrix *design_matrix_create (int, const struct variable *[],
69                                             const size_t);
70
71 void design_matrix_destroy (struct design_matrix *);
72
73 void design_matrix_set_categorical (struct design_matrix *, size_t,
74                                     const struct variable *,
75                                     const union value *);
76
77 void design_matrix_set_numeric (struct design_matrix *, size_t,
78                                     const struct variable *,
79                                     const union value *);
80
81 struct design_matrix *design_matrix_clone (const struct design_matrix *);
82
83 size_t design_matrix_var_to_column (const struct design_matrix *,
84                                     const struct variable *);
85
86 const struct variable *design_matrix_col_to_var (const struct design_matrix *,
87                                            size_t);
88 void design_matrix_increment_case_count (struct design_matrix *, const struct variable *);
89
90 void design_matrix_set_case_count (struct design_matrix *, const struct variable *, size_t);
91
92 size_t design_matrix_get_case_count (const struct design_matrix *, const struct variable *);
93 size_t design_matrix_get_n_cols (const struct design_matrix *);
94 size_t design_matrix_get_n_rows (const struct design_matrix *);
95 double design_matrix_get_element (const struct design_matrix *, size_t, size_t);
96 void design_matrix_set_element (const struct design_matrix *, size_t, size_t, double);
97 size_t dm_get_exact_subscript (const struct design_matrix *, const struct variable *,
98                                    const union value *);
99
100 #endif