GRASS GIS 8 Programmer's Manual
8.2.2dev(2023)-3d2c704037
c_means.c
Go to the documentation of this file.
1
/*!
2
\file cluster/c_means.c
3
4
\brief Cluster library - Means value
5
6
(C) 2001-2009 by the GRASS Development Team
7
8
This program is free software under the GNU General Public License
9
(>=v2). Read the file COPYING that comes with GRASS for details.
10
11
\author Original author CERL
12
*/
13
14
#include <math.h>
15
#include <
grass/cluster.h
>
16
17
/*!
18
\brief Calculate means value
19
20
\param C pointer to Cluster structure
21
22
\return 0
23
*/
24
int
I_cluster_means
(
struct
Cluster
*C)
25
{
26
int
band;
27
int
class
;
28
double
m, v;
/* m=mean, v=variance then std dev */
29
double
s;
30
31
G_debug
(3,
"I_cluster_means(nbands=%d,nclasses=%d)"
,
32
C->
nbands
, C->
nclasses
);
33
34
for
(band = 0; band < C->
nbands
; band++) {
35
s = C->
band_sum
[band];
36
m = s / C->
npoints
;
37
v = C->
band_sum2
[band] - s * m;
38
v = sqrt(v / (C->
npoints
- 1));
39
for
(
class
= 0;
class
< C->nclasses;
class
++)
40
C->
mean
[band][
class
] = m;
41
if
(C->
nclasses
> 1)
42
for
(
class
= 0;
class
< C->nclasses;
class
++)
43
C->
mean
[band][
class
] +=
44
((2.0 *
class
) / (C->
nclasses
- 1) - 1.0) * v;
45
}
46
47
return
0;
48
}
if
if(!(yy_init))
Definition:
sqlp.yy.c:775
Cluster::nbands
int nbands
Definition:
cluster.h:9
Cluster::mean
double ** mean
Definition:
cluster.h:24
Cluster::band_sum
double * band_sum
Definition:
cluster.h:14
Cluster::nclasses
int nclasses
Definition:
cluster.h:27
Cluster
Definition:
cluster.h:7
I_cluster_means
int I_cluster_means(struct Cluster *C)
Calculate means value.
Definition:
c_means.c:24
Cluster::npoints
int npoints
Definition:
cluster.h:10
cluster.h
Cluster::band_sum2
double * band_sum2
Definition:
cluster.h:15
G_debug
int G_debug(int, const char *,...) __attribute__((format(printf
lib
cluster
c_means.c
Generated on Tue Feb 14 2023 05:55:58 for GRASS GIS 8 Programmer's Manual by
1.8.13