1
1
#include <grass/gis.h>
2
#include <grass/gmath.h>
2
4
#include "local_proto.h"
6
within(int samptot, int nclass, double nsamp[MC], double cov[MC][MX][MX],
7
double w[MX][MX], int bands)
7
within(int samptot, int nclass, double *nsamp, double ***cov,
11
12
/* Initialize within class covariance matrix */
12
for (i = 1; i <= bands; i++)
13
for (j = 1; j <= bands; j++)
13
for (i = 0; i < bands; i++)
14
for (j = 0; j < bands; j++)
16
for (i = 1; i <= nclass; i++)
17
for (j = 1; j <= bands; j++)
18
for (k = 1; k <= bands; k++)
17
for (i = 0; i < nclass; i++)
18
for (j = 0; j < bands; j++)
19
for (k = 0; k < bands; k++)
19
20
w[j][k] += (nsamp[i] - 1) * cov[i][j][k];
21
for (i = 1; i <= bands; i++)
22
for (j = 1; j <= bands; j++)
22
for (i = 0; i < bands; i++)
23
for (j = 0; j < bands; j++)
23
24
w[i][j] = (1.0 / ((double)(samptot - nclass))) * w[i][j];
30
between(int samptot, int nclass, double nsamp[MC], double mu[MC][MX],
31
double p[MX][MX], int bands)
31
between(int samptot, int nclass, double *nsamp, double **mu,
32
double **p, int bands)
34
double tmp0[MX][MX], tmp1[MX][MX], tmp2[MX][MX];
37
for (i = 0; i < MX; i++)
40
for (i = 1; i <= bands; i++)
41
for (j = 1; j <= bands; j++)
42
tmp1[i][j] = tmp2[i][j] = 0.0;
44
/* for (i = 1 ; i <= nclass ; i++)
45
product(mu[i],nsamp[i],tmp0,tmp1,bands);
46
for (i = 1 ; i <= nclass ; i++)
47
for (j = 1 ; j <= bands ; j++)
48
newvec[j] += nsamp[i] * mu[i][j];
49
for (i = 1 ; i <= bands ; i++)
50
for (j = 1 ; i <= bands ; j++)
51
tmp2[i][j] = (newvec[i] * newvec[j]) / samptot;
52
for (i = 1 ; i <= bands ; i++)
53
for (j = 1 ; j <= bands ; j++)
54
p[i][j] = (tmp1[i][j] - tmp2[i][j]) / (nclass - 1);
57
for (i = 1; i <= nclass; i++)
58
for (j = 1; j <= bands; j++)
35
double **tmp0, **tmp1, **tmp2;
38
tmp0 = G_alloc_matrix(bands, bands);
39
tmp1 = G_alloc_matrix(bands, bands);
40
tmp2 = G_alloc_matrix(bands, bands);
41
newvec = G_alloc_vector(bands);
43
for (i = 0; i < nclass; i++)
44
for (j = 0; j < bands; j++)
59
45
newvec[j] += nsamp[i] * mu[i][j];
60
for (i = 1; i <= bands; i++)
61
for (j = 1; j <= bands; j++)
46
for (i = 0; i < bands; i++)
47
for (j = 0; j < bands; j++)
62
48
tmp1[i][j] = (newvec[i] * newvec[j]) / samptot;
64
for (k = 1; k <= nclass; k++) {
50
for (k = 0; k < nclass; k++) {
65
51
product(mu[k], nsamp[k], tmp0, bands);
66
for (i = 1; i <= bands; i++)
67
for (j = 1; j <= bands; j++)
52
for (i = 0; i < bands; i++)
53
for (j = 0; j < bands; j++)
68
54
tmp2[i][j] += tmp0[i][j] - tmp1[i][j];
71
for (i = 1; i <= bands; i++)
72
for (j = 1; j <= bands; j++)
57
for (i = 0; i < bands; i++)
58
for (j = 0; j < bands; j++)
73
59
p[i][j] = tmp2[i][j] / (nclass - 1);
64
G_free_vector(newvec);