[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pspp-cvs] pspp/src data/ChangeLog data/automake.mk data/c...
From: |
John Darrington |
Subject: |
[Pspp-cvs] pspp/src data/ChangeLog data/automake.mk data/c... |
Date: |
Sun, 22 Apr 2007 00:48:50 +0000 |
CVSROOT: /sources/pspp
Module name: pspp
Changes by: John Darrington <jmd> 07/04/22 00:48:50
Modified files:
src/data : ChangeLog automake.mk category.c category.h
dictionary.c sys-file-reader.c variable.c
src/language/stats: regression.q
src/math : coefficient.c design-matrix.c design-matrix.h
src/math/linreg: linreg.c linreg.h
Removed files:
src/data : cat-routines.h
Log message:
Miscellaneous cleanup to categorical values, linreg and design matrix
code.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/ChangeLog?cvsroot=pspp&r1=1.111&r2=1.112
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/automake.mk?cvsroot=pspp&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/category.c?cvsroot=pspp&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/category.h?cvsroot=pspp&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/dictionary.c?cvsroot=pspp&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/sys-file-reader.c?cvsroot=pspp&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/variable.c?cvsroot=pspp&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/pspp/src/data/cat-routines.h?cvsroot=pspp&r1=1.3&r2=0
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/stats/regression.q?cvsroot=pspp&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/pspp/src/math/coefficient.c?cvsroot=pspp&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/pspp/src/math/design-matrix.c?cvsroot=pspp&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/pspp/src/math/design-matrix.h?cvsroot=pspp&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/pspp/src/math/linreg/linreg.c?cvsroot=pspp&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/pspp/src/math/linreg/linreg.h?cvsroot=pspp&r1=1.14&r2=1.15
Patches:
Index: data/ChangeLog
===================================================================
RCS file: /sources/pspp/pspp/src/data/ChangeLog,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -b -r1.111 -r1.112
--- data/ChangeLog 20 Apr 2007 11:04:55 -0000 1.111
+++ data/ChangeLog 22 Apr 2007 00:48:50 -0000 1.112
@@ -1,3 +1,8 @@
+2007-04-22 John Darrington <address@hidden>
+
+ * Deleted existing category.h and moved cat-routines.h into
+ category.h Encapsulated struct cat_vals better.
+
2007-04-19 John Darrington <address@hidden>
* sys-file-reader.c: When reading a system file which has no
Index: data/automake.mk
===================================================================
RCS file: /sources/pspp/pspp/src/data/automake.mk,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- data/automake.mk 16 Jan 2007 00:14:41 -0000 1.15
+++ data/automake.mk 22 Apr 2007 00:48:50 -0000 1.16
@@ -27,7 +27,6 @@
src/data/case.h \
src/data/category.c \
src/data/category.h \
- src/data/cat-routines.h \
src/data/data-in.c \
src/data/data-in.h \
src/data/data-out.c \
Index: data/category.c
===================================================================
RCS file: /sources/pspp/pspp/src/data/category.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- data/category.c 2 Apr 2007 08:55:51 -0000 1.7
+++ data/category.c 22 Apr 2007 00:48:50 -0000 1.8
@@ -41,18 +41,36 @@
#include <libpspp/alloc.h>
#include <libpspp/message.h>
-#include "cat-routines.h"
+#include "category.h"
#include "value.h"
#include "variable.h"
+#define CAT_VALUE_NOT_FOUND -2
+
#define N_INITIAL_CATEGORIES 1
+/*
+ This structure contains the observed values of a
+ categorical variable.
+ */
+struct cat_vals
+{
+ union value *vals;
+ size_t n_categories;
+ size_t n_allocated_categories; /* This is used only during
+ initialization to keep
+ track of the number of
+ values stored.
+ */
+};
+
void
cat_stored_values_create (const struct variable *v)
{
if (!var_has_obs_vals (v))
{
struct cat_vals *obs_vals = xmalloc (sizeof *obs_vals);
+
obs_vals->n_categories = 0;
obs_vals->n_allocated_categories = N_INITIAL_CATEGORIES;
obs_vals->vals = xnmalloc (N_INITIAL_CATEGORIES, sizeof *obs_vals->vals);
@@ -117,8 +135,8 @@
}
}
-union value *
-cat_subscript_to_value (const size_t s, struct variable *v)
+const union value *
+cat_subscript_to_value (const size_t s, const struct variable *v)
{
struct cat_vals *obs_vals = var_get_obs_vals (v);
return s < obs_vals->n_categories ? obs_vals->vals + s : NULL;
Index: data/category.h
===================================================================
RCS file: /sources/pspp/pspp/src/data/category.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- data/category.h 8 Jul 2006 03:05:51 -0000 1.2
+++ data/category.h 22 Apr 2007 00:48:50 -0000 1.3
@@ -33,29 +33,26 @@
*/
-#ifndef CAT_H
-#define CAT_H
-#define CAT_VALUE_NOT_FOUND -2
-#include <stdbool.h>
+#ifndef CATEGORY_H
+#define CATEGORY_H
+
#include <stddef.h>
-union value;
+struct cat_vals;
struct variable ;
+union value;
+
+void cat_stored_values_create (const struct variable *);
+void cat_stored_values_destroy (struct cat_vals *);
+
+size_t cat_value_find (const struct variable *, const union value *);
+
+const union value *cat_subscript_to_value (const size_t,
+ const struct variable *);
+
+
+void cat_value_update (const struct variable *, const union value *);
-/*
- This structure contains the observed values of a
- categorical variable.
- */
-struct cat_vals
-{
- union value *vals;
- size_t n_categories;
- size_t n_allocated_categories; /* This is used only during
- initialization to keep
- track of the number of
- values stored.
- */
-};
/*
Return the number of categories of a categorical variable.
Index: data/dictionary.c
===================================================================
RCS file: /sources/pspp/pspp/src/data/dictionary.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- data/dictionary.c 2 Apr 2007 08:55:51 -0000 1.33
+++ data/dictionary.c 22 Apr 2007 00:48:50 -0000 1.34
@@ -24,7 +24,6 @@
#include <ctype.h>
#include "case.h"
-#include "cat-routines.h"
#include "category.h"
#include "settings.h"
#include "value-labels.h"
Index: data/sys-file-reader.c
===================================================================
RCS file: /sources/pspp/pspp/src/data/sys-file-reader.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- data/sys-file-reader.c 20 Apr 2007 11:04:55 -0000 1.34
+++ data/sys-file-reader.c 22 Apr 2007 00:48:50 -0000 1.35
@@ -261,8 +261,6 @@
struct variable *var = dict_get_var (*dict, i);
char short_name [SHORT_NAME_LEN + 1];
char long_name [SHORT_NAME_LEN + 1];
- char *s = short_name;
- char *d = long_name;
strcpy (short_name, var_get_name (var));
Index: data/variable.c
===================================================================
RCS file: /sources/pspp/pspp/src/data/variable.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- data/variable.c 2 Apr 2007 08:55:51 -0000 1.22
+++ data/variable.c 22 Apr 2007 00:48:50 -0000 1.23
@@ -21,7 +21,8 @@
#include <stdlib.h>
-#include "cat-routines.h"
+
+#include "category.h"
#include "data-out.h"
#include "format.h"
#include "dictionary.h"
Index: language/stats/regression.q
===================================================================
RCS file: /sources/pspp/pspp/src/language/stats/regression.q,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- language/stats/regression.q 12 Apr 2007 22:40:53 -0000 1.49
+++ language/stats/regression.q 22 Apr 2007 00:48:50 -0000 1.50
@@ -27,7 +27,6 @@
#include "regression-export.h"
#include <data/case.h>
#include <data/casefile.h>
-#include <data/cat-routines.h>
#include <data/category.h>
#include <data/dictionary.h>
#include <data/missing-values.h>
@@ -565,7 +564,7 @@
pspp_linreg_cache *model;
union value *output = NULL;
const union value **vals = NULL;
- struct variable **vars = NULL;
+ const struct variable **vars = NULL;
assert (trns != NULL);
model = trns->c;
@@ -605,7 +604,7 @@
union value *output = NULL;
const union value **vals = NULL;
const union value *obs = NULL;
- struct variable **vars = NULL;
+ const struct variable **vars = NULL;
assert (trns != NULL);
model = trns->c;
@@ -790,7 +789,7 @@
for (j = 0; j < n_categories; j++)
{
- union value *val = cat_subscript_to_value (j, varlist[i]);
+ const union value *val = cat_subscript_to_value (j, varlist[i]);
fprintf (fp, "%s.values[%d] = \"%s\";\n\t",
var_get_name (varlist[i]), j,
var_get_value_name (varlist[i], val));
@@ -1225,7 +1224,6 @@
if (n_data > 0)
{
Y = gsl_vector_alloc (n_data);
-
X =
design_matrix_create (n_indep, (const struct variable **)
indep_vars,
n_data);
Index: math/coefficient.c
===================================================================
RCS file: /sources/pspp/pspp/src/math/coefficient.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- math/coefficient.c 23 Dec 2006 06:11:33 -0000 1.7
+++ math/coefficient.c 22 Apr 2007 00:48:50 -0000 1.8
@@ -69,8 +69,7 @@
*/
c[i]->v_info = xnmalloc (c[i]->n_vars, sizeof (*c[i]->v_info));
assert (c[i]->v_info != NULL);
- c[i]->v_info->v =
- (const struct variable *) design_matrix_col_to_var (X, i);
+ c[i]->v_info->v = design_matrix_col_to_var (X, i);
if (var_is_alpha (c[i]->v_info->v))
{
@@ -79,7 +78,7 @@
assert (k <= i);
k = i - k;
c[i]->v_info->val =
- cat_subscript_to_value (k, (struct variable *) c[i]->v_info->v);
+ cat_subscript_to_value (k, c[i]->v_info->v);
}
}
}
Index: math/design-matrix.c
===================================================================
RCS file: /sources/pspp/pspp/src/math/design-matrix.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- math/design-matrix.c 10 Dec 2006 03:42:51 -0000 1.6
+++ math/design-matrix.c 22 Apr 2007 00:48:50 -0000 1.7
@@ -42,57 +42,6 @@
#define DM_COLUMN_NOT_FOUND -1
#define DM_INDEX_NOT_FOUND -3
-/*
- Which element of a vector is equal to the value x?
- */
-static size_t
-cat_which_element_eq (const gsl_vector * vec, double x)
-{
- size_t i;
-
- for (i = 0; i < vec->size; i++)
- {
- if (fabs (gsl_vector_get (vec, i) - x) < GSL_DBL_EPSILON)
- {
- return i;
- }
- }
- return CAT_VALUE_NOT_FOUND;
-}
-static int
-cat_is_zero_vector (const gsl_vector * vec)
-{
- size_t i;
-
- for (i = 0; i < vec->size; i++)
- {
- if (gsl_vector_get (vec, i) != 0.0)
- {
- return 0;
- }
- }
- return 1;
-}
-
-/*
- Return the value of v corresponding to the vector vec.
- */
-union value *
-cat_vector_to_value (const gsl_vector * vec, struct variable *v)
-{
- size_t i;
-
- i = cat_which_element_eq (vec, 1.0);
- if (i != CAT_VALUE_NOT_FOUND)
- {
- return cat_subscript_to_value (i + 1, v);
- }
- if (cat_is_zero_vector (vec))
- {
- return cat_subscript_to_value (0, v);
- }
- return NULL;
-}
struct design_matrix *
design_matrix_create (int n_variables,
@@ -123,10 +72,10 @@
}
else if (var_is_alpha (v))
{
- struct cat_vals *obs_vals = var_get_obs_vals (v);
+ size_t n_categories = cat_get_n_categories (v);
(dm->vars + i)->last_column =
- (dm->vars + i)->first_column + obs_vals->n_categories - 2;
- n_cols += obs_vals->n_categories - 1;
+ (dm->vars + i)->first_column + n_categories - 2;
+ n_cols += n_categories - 1;
}
}
dm->m = gsl_matrix_calloc (n_data, n_cols);
@@ -147,7 +96,7 @@
Return the index of the variable for the
given column.
*/
-struct variable *
+const struct variable *
design_matrix_col_to_var (const struct design_matrix *dm, size_t col)
{
size_t i;
@@ -157,7 +106,7 @@
{
v = dm->vars[i];
if (v.first_column <= col && col <= v.last_column)
- return (struct variable *) v.v;
+ return v.v;
}
return NULL;
}
@@ -232,6 +181,7 @@
gsl_matrix_set (dm->m, row, col, entry);
}
}
+
void
design_matrix_set_numeric (struct design_matrix *dm, size_t row,
const struct variable *var, const union value *val)
Index: math/design-matrix.h
===================================================================
RCS file: /sources/pspp/pspp/src/math/design-matrix.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- math/design-matrix.h 21 Jan 2007 03:44:53 -0000 1.3
+++ math/design-matrix.h 22 Apr 2007 00:48:50 -0000 1.4
@@ -26,7 +26,7 @@
#include <gsl/gsl_matrix.h>
#include <stdbool.h>
#include <data/category.h>
-#include <data/cat-routines.h>
+
struct design_matrix_var
{
size_t first_column; /* First column for this variable in
@@ -40,6 +40,7 @@
size_t last_column;
const struct variable *v;
};
+
struct design_matrix
{
gsl_matrix *m;
@@ -61,7 +62,7 @@
*/
size_t n_vars;
};
-union value *cat_vector_to_value (const gsl_vector *, struct variable *);
+
struct design_matrix *design_matrix_create (int, const struct variable *[],
const size_t);
@@ -73,12 +74,13 @@
const union value *);
void design_matrix_set_numeric (struct design_matrix *, size_t,
- const struct variable *, const union value *);
+ const struct variable *,
+ const union value *);
size_t design_matrix_var_to_column (const struct design_matrix *,
const struct variable *);
-struct variable *design_matrix_col_to_var (const struct design_matrix *,
+const struct variable *design_matrix_col_to_var (const struct design_matrix *,
size_t);
#endif
Index: math/linreg/linreg.c
===================================================================
RCS file: /sources/pspp/pspp/src/math/linreg/linreg.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- math/linreg/linreg.c 12 Apr 2007 22:40:53 -0000 1.18
+++ math/linreg/linreg.c 22 Apr 2007 00:48:50 -0000 1.19
@@ -95,7 +95,7 @@
The return value is the number of distinct variables found.
*/
int
-pspp_linreg_get_vars (const void *c_, struct variable **v)
+pspp_linreg_get_vars (const void *c_, const struct variable **v)
{
const pspp_linreg_cache *c = c_;
struct pspp_coeff *coef = NULL;
@@ -114,7 +114,7 @@
/*
Start at c->coeff[1] to avoid the intercept.
*/
- v[result] = (struct variable *) pspp_coeff_get_var (c->coeff[1], 0);
+ v[result] = pspp_coeff_get_var (c->coeff[1], 0);
result = (v[result] == NULL) ? 0 : 1;
for (coef = c->coeff[2]; coef < c->coeff[c->n_coeffs]; coef++)
@@ -130,7 +130,7 @@
}
if (i < 0 && result < c->n_coeffs)
{
- v[result] = (struct variable *) tmp;
+ v[result] = tmp;
result++;
}
}
Index: math/linreg/linreg.h
===================================================================
RCS file: /sources/pspp/pspp/src/math/linreg/linreg.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- math/linreg/linreg.h 19 May 2006 21:08:20 -0000 1.14
+++ math/linreg/linreg.h 22 Apr 2007 00:48:50 -0000 1.15
@@ -165,7 +165,7 @@
/*
Returns pointers to the variables used in the model.
*/
- int (*get_vars) (const void *, struct variable **);
+ int (*get_vars) (const void *, const struct variable **);
struct variable *resid;
struct variable *pred;
@@ -202,5 +202,5 @@
/*
All variables used in the model.
*/
-int pspp_linreg_get_vars (const void *, struct variable **);
+int pspp_linreg_get_vars (const void *, const struct variable **);
#endif
Index: data/cat-routines.h
===================================================================
RCS file: data/cat-routines.h
diff -N data/cat-routines.h
--- data/cat-routines.h 2 Apr 2007 08:55:51 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,53 +0,0 @@
-/* PSPP - Binary encodings for categorical variables.
- Copyright (C) 2005 Free Software Foundation, Inc.
- Written by Jason H Stover <address@hidden>.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
-
-/*
- Functions and data structures to recode categorical variables into
- vectors and sub-rows of matrices.
-
- To fit many types of statistical models, it is necessary
- to change each value of a categorical variable to a vector with binary
- entries. These vectors are then stored as sub-rows within a matrix
- during model-fitting. We need functions and data strucutres to,
- e.g., map a value, say 'a', of a variable named 'cat_var', to a
- vector, say (0 1 0 0 0), and vice versa. We also need to be able
- to map the vector back to the value 'a', and if the vector is a
- sub-row of a matrix, we need to know which sub-row corresponds to
- the variable 'cat_var'.
-
- */
-
-#ifndef CAT_ROUTINES_H
-#define CAT_ROUTINES_H
-#define CAT_VALUE_NOT_FOUND -2
-#include <stdbool.h>
-#include "category.h"
-
-size_t cat_value_find (const struct variable *, const union value *);
-
-union value *cat_subscript_to_value (const size_t, struct variable *);
-
-void cat_stored_values_create (const struct variable *);
-
-void cat_value_update (const struct variable *, const union value *);
-
-void cat_create_value_matrix (const struct variable *);
-
-void cat_stored_values_destroy (struct cat_vals *);
-#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pspp-cvs] pspp/src data/ChangeLog data/automake.mk data/c...,
John Darrington <=