X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fmath%2Fdesign-matrix.c;h=163c42fab66789e446af3b5643c8312f8d6b93be;hb=f4810d3c8656b3b3ab26303d2dae70fc361db7fb;hp=01fdb0851aca937aeefe1d7d4fbf98f6d0017b9d;hpb=1c4b7cfcec922cf6d1e92a607f23f00d26e7324e;p=pspp diff --git a/src/math/design-matrix.c b/src/math/design-matrix.c index 01fdb0851a..163c42fab6 100644 --- a/src/math/design-matrix.c +++ b/src/math/design-matrix.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -41,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, @@ -122,10 +72,10 @@ design_matrix_create (int n_variables, } else if (var_is_alpha (v)) { - assert (v->obs_vals != NULL); + size_t n_categories = cat_get_n_categories (v); (dm->vars + i)->last_column = - (dm->vars + i)->first_column + v->obs_vals->n_categories - 2; - n_cols += v->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); @@ -146,7 +96,7 @@ design_matrix_destroy (struct design_matrix *dm) 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; @@ -156,7 +106,7 @@ design_matrix_col_to_var (const struct design_matrix *dm, size_t col) { v = dm->vars[i]; if (v.first_column <= col && col <= v.last_column) - return (struct variable *) v.v; + return v.v; } return NULL; } @@ -231,6 +181,7 @@ design_matrix_set_categorical (struct design_matrix *dm, size_t row, 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)