root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridStatistics / neighborhood / patternBase / PatternBaseAlgorithm.java @ 59
History | View | Annotate | Download (2.02 KB)
1 |
package es.unex.sextante.gridStatistics.neighborhood.patternBase; |
---|---|
2 |
|
3 |
import java.util.HashMap; |
4 |
import java.util.Iterator; |
5 |
import java.util.Set; |
6 |
|
7 |
import es.unex.sextante.gridStatistics.base.NeighborhoodStatsBaseAlgorithm; |
8 |
|
9 |
public abstract class PatternBaseAlgorithm |
10 |
extends
|
11 |
NeighborhoodStatsBaseAlgorithm { |
12 |
|
13 |
|
14 |
protected int getNumberOfClasses() { |
15 |
|
16 |
int i;
|
17 |
double dValue;
|
18 |
Double value;
|
19 |
final HashMap map = new HashMap(); |
20 |
|
21 |
for (i = 0; i < m_dValues.length; i++) { |
22 |
dValue = m_dValues[i]; |
23 |
if (dValue != NO_DATA) {
|
24 |
value = new Double(dValue); |
25 |
if (!map.containsKey(value)) {
|
26 |
map.put(value, "");
|
27 |
} |
28 |
} |
29 |
} |
30 |
|
31 |
return map.size();
|
32 |
|
33 |
} |
34 |
|
35 |
|
36 |
protected double getDiversity() { |
37 |
|
38 |
int i;
|
39 |
int iCount = 0; |
40 |
int iCells = 0; |
41 |
double dProp;
|
42 |
double dValue;
|
43 |
double dReturn = 0; |
44 |
Integer count;
|
45 |
Double value;
|
46 |
final HashMap map = new HashMap(); |
47 |
|
48 |
for (i = 0; i < m_dValues.length; i++) { |
49 |
dValue = m_dValues[i]; |
50 |
if (dValue != NO_DATA) {
|
51 |
iCells++; |
52 |
value = new Double(dValue); |
53 |
count = (Integer) map.get(value);
|
54 |
if (count != null) { |
55 |
count = new Integer(count.intValue() + 1); |
56 |
} |
57 |
else {
|
58 |
count = new Integer(1); |
59 |
} |
60 |
map.put(value, count); |
61 |
} |
62 |
} |
63 |
|
64 |
if (iCells != 0) { |
65 |
final Set set = map.keySet(); |
66 |
final Iterator iter = set.iterator(); |
67 |
|
68 |
while (iter.hasNext()) {
|
69 |
value = (Double) iter.next();
|
70 |
dValue = value.doubleValue(); |
71 |
count = (Integer) map.get(value);
|
72 |
iCount = count.intValue(); |
73 |
dProp = (double) iCount / (double) iCells; |
74 |
dReturn += (dProp * Math.log(dProp));
|
75 |
} |
76 |
|
77 |
return dReturn;
|
78 |
} |
79 |
else {
|
80 |
return NO_DATA;
|
81 |
} |
82 |
|
83 |
|
84 |
} |
85 |
|
86 |
} |