projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge commit 'window-manager/master'
[pspp]
/
src
/
math
/
linreg.c
diff --git
a/src/math/linreg.c
b/src/math/linreg.c
index a7fa15657344bd1cf52aad870acffd80c9d661f6..a50aa7d8f105aaff4a6921ee84a88539956d3122 100644
(file)
--- a/
src/math/linreg.c
+++ b/
src/math/linreg.c
@@
-24,7
+24,6
@@
#include <math/coefficient.h>
#include <math/linreg.h>
#include <math/coefficient.h>
#include <math/coefficient.h>
#include <math/linreg.h>
#include <math/coefficient.h>
-#include <math/covariance-matrix.h>
#include <math/design-matrix.h>
#include <src/data/category.h>
#include <src/data/variable.h>
#include <math/design-matrix.h>
#include <src/data/category.h>
#include <src/data/variable.h>
@@
-96,10
+95,10
@@
linreg_mean_std (gsl_vector_const_view v, double *mp, double *sp, double *ssp)
The return value is the number of distinct variables found.
*/
int
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_;
{
const pspp_linreg_cache *c = c_;
- struct variable *tmp;
+
const
struct variable *tmp;
int i;
int j;
int result = 0;
int i;
int j;
int result = 0;
@@
-661,20
+660,23
@@
void pspp_linreg_set_indep_variable_mean (pspp_linreg_cache *c, const struct var
only variables in the model are in the covariance matrix.
*/
static struct design_matrix *
only variables in the model are in the covariance matrix.
*/
static struct design_matrix *
-rearrange_covariance_matrix (const struct
design_matrix *cov
, pspp_linreg_cache *c)
+rearrange_covariance_matrix (const struct
covariance_matrix *cm
, pspp_linreg_cache *c)
{
{
- struct variable **model_vars;
+ const struct variable **model_vars;
+ struct design_matrix *cov;
struct design_matrix *result;
size_t *permutation;
size_t i;
size_t j;
size_t k;
struct design_matrix *result;
size_t *permutation;
size_t i;
size_t j;
size_t k;
+ assert (cm != NULL);
+ cov = covariance_to_design (cm);
assert (cov != NULL);
assert (c != NULL);
assert (cov->m->size1 > 0);
assert (cov->m->size2 == cov->m->size1);
assert (cov != NULL);
assert (c != NULL);
assert (cov->m->size1 > 0);
assert (cov->m->size2 == cov->m->size1);
- permutation = xnmalloc (
cov->m->size2
, sizeof (*permutation));
+ permutation = xnmalloc (
1 + c->n_indeps
, sizeof (*permutation));
model_vars = xnmalloc (1 + c->n_indeps, sizeof (*model_vars));
/*
model_vars = xnmalloc (1 + c->n_indeps, sizeof (*model_vars));
/*
@@
-688,17
+690,18
@@
rearrange_covariance_matrix (const struct design_matrix *cov, pspp_linreg_cache
result = covariance_matrix_create (1 + c->n_indeps, model_vars);
for (j = 0; j < cov->m->size2; j++)
{
result = covariance_matrix_create (1 + c->n_indeps, model_vars);
for (j = 0; j < cov->m->size2; j++)
{
- for (k = 0; k < result->m->size2; k++)
+ k = 0;
+ while (k < result->m->size2)
{
if (design_matrix_col_to_var (cov, j) == design_matrix_col_to_var (result, k))
{
permutation[k] = j;
{
if (design_matrix_col_to_var (cov, j) == design_matrix_col_to_var (result, k))
{
permutation[k] = j;
- break;
}
}
+ k++;
}
}
}
}
- for (
j = 0; j < result->m->size2; j
++)
- for (
i = 0; i < result->m->size1; i
++)
+ for (
i = 0; i < result->m->size1; i
++)
+ for (
j = 0; j < result->m->size2; j
++)
{
gsl_matrix_set (result->m, i, j, gsl_matrix_get (cov->m, permutation[i], permutation[j]));
}
{
gsl_matrix_set (result->m, i, j, gsl_matrix_get (cov->m, permutation[i], permutation[j]));
}
@@
-718,8
+721,8
@@
rearrange_covariance_matrix (const struct design_matrix *cov, pspp_linreg_cache
having to alter it. The problem is that this means the caller must
set CACHE->N_COEFFS.
*/
having to alter it. The problem is that this means the caller must
set CACHE->N_COEFFS.
*/
-int
-pspp_linreg_with_cov (const struct
design
_matrix *full_cov,
+void
+pspp_linreg_with_cov (const struct
covariance
_matrix *full_cov,
pspp_linreg_cache * cache)
{
struct design_matrix *cov;
pspp_linreg_cache * cache)
{
struct design_matrix *cov;
@@
-731,6
+734,6
@@
pspp_linreg_with_cov (const struct design_matrix *full_cov,
cache_init (cache);
reg_sweep (cov->m);
post_sweep_computations (cache, cov, cov->m);
cache_init (cache);
reg_sweep (cov->m);
post_sweep_computations (cache, cov, cov->m);
-
covariance
_matrix_destroy (cov);
+
design
_matrix_destroy (cov);
}
}