~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to imagery/i.cca/stats.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <grass/gis.h>
 
2
#include <grass/gmath.h>
 
3
 
2
4
#include "local_proto.h"
3
5
 
4
 
 
5
6
int
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,
 
8
       double **w, int bands)
8
9
{
9
10
    int i, j, k;
10
11
 
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++)
14
15
            w[i][j] = 0.0;
15
16
 
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];
20
21
 
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];
24
25
 
25
26
    return 0;
27
28
 
28
29
 
29
30
int
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)
32
33
{
33
34
    int i, j, k;
34
 
    double tmp0[MX][MX], tmp1[MX][MX], tmp2[MX][MX];
35
 
    double newvec[MX];
36
 
 
37
 
    for (i = 0; i < MX; i++)
38
 
        newvec[i] = 0.0;
39
 
 
40
 
    for (i = 1; i <= bands; i++)
41
 
        for (j = 1; j <= bands; j++)
42
 
            tmp1[i][j] = tmp2[i][j] = 0.0;
43
 
 
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);
55
 
     */
56
 
 
57
 
    for (i = 1; i <= nclass; i++)
58
 
        for (j = 1; j <= bands; j++)
 
35
    double **tmp0, **tmp1, **tmp2;
 
36
    double *newvec;
 
37
 
 
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);
 
42
 
 
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;
63
49
 
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];
69
55
    }
70
56
 
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);
74
60
 
 
61
    G_free_matrix(tmp0);
 
62
    G_free_matrix(tmp1);
 
63
    G_free_matrix(tmp2);
 
64
    G_free_vector(newvec);
 
65
 
75
66
    return 0;
76
67
}
 
68