X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Flinreg.h;h=17fe3c733c990e45df1b3a4012baf6b84a3d9608;hb=e385eeb8a2ea75fb2d9c1c628619baa03c914dae;hp=ff37a84fe815931962aaa9ff46add55e0a394353;hpb=73f67789df91a09ee91976434fb15c2ee1fb5e78;p=pspp-builds.git diff --git a/src/math/linreg.h b/src/math/linreg.h index ff37a84f..17fe3c73 100644 --- a/src/math/linreg.h +++ b/src/math/linreg.h @@ -20,13 +20,12 @@ #include #include #include -#include enum { - PSPP_LINREG_CONDITIONAL_INVERSE, - PSPP_LINREG_QR, - PSPP_LINREG_SWEEP, + LINREG_CONDITIONAL_INVERSE, + LINREG_QR, + LINREG_SWEEP, }; @@ -88,21 +87,20 @@ typedef struct pspp_linreg_opts_struct pspp_linreg_opts; */ -struct pspp_linreg_cache_struct +struct linreg_struct { - int n_obs; /* Number of observations. */ + double n_obs; /* Number of observations. */ int n_indeps; /* Number of independent variables. */ int n_coeffs; /* The intercept is not considered a coefficient here. */ /* - The variable struct is ignored during estimation. It is here so - the calling procedure can find the variable used in the model. + Pointers to the variables. */ const struct variable *depvar; + const struct variable **indep_vars; - gsl_vector *residuals; - struct pspp_coeff **coeff; + double *coeff; double intercept; int method; /* Method to use to estimate parameters. */ /* @@ -153,66 +151,55 @@ struct pspp_linreg_cache_struct */ gsl_matrix *hat; - double (*predict) (const struct variable **, const union value **, - const void *, int); - double (*residual) (const struct variable **, - const union value **, - const union value *, const void *, int); - /* - Returns pointers to the variables used in the model. - */ - int (*get_vars) (const void *, const struct variable **); - struct variable *resid; struct variable *pred; - + struct variable *resid; }; -typedef struct pspp_linreg_cache_struct pspp_linreg_cache; +typedef struct linreg_struct linreg; -/* - Allocate a pspp_linreg_cache and return a pointer - to it. n is the number of cases, p is the number of - independent variables. - */ -pspp_linreg_cache *pspp_linreg_cache_alloc (size_t n, size_t p); +linreg *linreg_alloc (const struct variable *, const struct variable **, + double, size_t); -bool pspp_linreg_cache_free (void *); +bool linreg_free (void *); /* Fit the linear model via least squares. All pointers passed to pspp_linreg are assumed to be allocated to the correct size and initialized to the values as indicated by opts. */ -int -pspp_linreg (const gsl_vector *, const struct design_matrix *, - const pspp_linreg_opts *, pspp_linreg_cache *); +void +linreg_fit (const gsl_matrix *, linreg *); double -pspp_linreg_predict (const struct variable **, const union value **, - const void *, int); +linreg_predict (const linreg *, const double *, size_t); double -pspp_linreg_residual (const struct variable **, const union value **, - const union value *, const void *, int); -/* - All variables used in the model. - */ -int pspp_linreg_get_vars (const void *, const struct variable **); +linreg_residual (const linreg *, double, const double *, size_t); +const struct variable ** linreg_get_vars (const linreg *); -const struct pspp_coeff *pspp_linreg_get_coeff (const pspp_linreg_cache - *, - const struct variable - *, - const union value *); /* Return or set the standard deviation of the independent variable. */ -double pspp_linreg_get_indep_variable_sd (pspp_linreg_cache *, const struct variable *); -void pspp_linreg_set_indep_variable_sd (pspp_linreg_cache *, const struct variable *, double); +double linreg_get_indep_variable_sd (linreg *, size_t); +void linreg_set_indep_variable_sd (linreg *, size_t, double); /* Mean of the independent variable. */ -double pspp_linreg_get_indep_variable_mean (pspp_linreg_cache *, const struct variable *); -void pspp_linreg_set_indep_variable_mean (pspp_linreg_cache *, const struct variable *, double); +double linreg_get_indep_variable_mean (linreg *, size_t); +void linreg_set_indep_variable_mean (linreg *, size_t, double); + +double linreg_mse (const linreg *); + +double linreg_intercept (const linreg *); + +gsl_matrix * linreg_cov (const linreg *); +double linreg_coeff (const linreg *, size_t); +const struct variable * linreg_indep_var (const linreg *, size_t); +size_t linreg_n_coeffs (const linreg *); +size_t linreg_n_obs (const linreg *); +double linreg_sse (const linreg *); +double linreg_ssreg (const linreg *); +double linreg_dfmodel (const linreg *); +double linreg_sst (const linreg *); #endif