Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.buffer / org.gvsig.raster.lib.buffer.impl / src / main / java / org / gvsig / raster / lib / buffer / impl / statistics / DefaultStatistics.java @ 5486

History | View | Annotate | Download (5.28 KB)

1
package org.gvsig.raster.lib.buffer.impl.statistics;
2

    
3
import java.util.List;
4

    
5
import org.gvsig.raster.lib.buffer.api.Band;
6
import org.gvsig.raster.lib.buffer.api.statistics.Histogram;
7
import org.gvsig.raster.lib.buffer.api.statistics.HistogramBand;
8
import org.gvsig.raster.lib.buffer.api.statistics.Statistics;
9
import org.gvsig.raster.lib.buffer.api.statistics.StatisticsBand;
10
import org.gvsig.tools.task.SimpleTaskStatus;
11

    
12

    
13
/**
14
 * @author fdiaz
15
 *
16
 */
17
public class DefaultStatistics implements Statistics {
18

    
19
    StatisticsBand[] statisticsBands;
20
    List<Band> bands;
21
    boolean calculated;
22
    double[][] varCov;
23

    
24
    /**
25
     * @param bands
26
     *
27
     */
28
    public DefaultStatistics( List<Band> bands) {
29
        this.bands = bands;
30
        statisticsBands = new StatisticsBand[bands.size()];
31
        for (int i = 0; i < statisticsBands.length; i++) {
32
            statisticsBands[i] = new DefaultStatisticsBand(this.bands.get(i));
33
        }
34
        varCov = new double[statisticsBands.length][statisticsBands.length];
35
        calculated = false;
36
    }
37

    
38
    @Override
39
    public long[] getNumberOfValues() {
40
        long[] result = new long[statisticsBands.length];
41
        for (int i = 0; i < statisticsBands.length; i++) {
42
            result[i]= statisticsBands[i].getBandLenght();
43
        }
44
        return result;
45
    }
46

    
47
    @Override
48
    public double[] getMax() {
49
        double[] result = new double[statisticsBands.length];
50
        for (int i = 0; i < statisticsBands.length; i++) {
51
            result[i]= statisticsBands[i].getMaximum();
52
        }
53
        return result;
54
    }
55

    
56
    @Override
57
    public double[] getSecondMax() {
58
        double[] result = new double[statisticsBands.length];
59
        for (int i = 0; i < statisticsBands.length; i++) {
60
            result[i]= statisticsBands[i].getSecondMax();
61
        }
62
        return result;
63
    }
64

    
65
    @Override
66
    public double[] getSecondMin() {
67
        double[] result = new double[statisticsBands.length];
68
        for (int i = 0; i < statisticsBands.length; i++) {
69
            result[i]= statisticsBands[i].getSecondMin();
70
        }
71
        return result;
72
    }
73

    
74
    @Override
75
    public double getMaximun() {
76
        double result = Double.NEGATIVE_INFINITY;
77
        for (int i = 0; i < statisticsBands.length; i++) {
78
            double max = statisticsBands[i].getMaximum();
79
            if(result<max){
80
                result = max;
81
            }
82
        }
83
        return result;
84
    }
85

    
86
    @Override
87
    public double getMinimun() {
88
        double result = Double.POSITIVE_INFINITY;
89
        for (int i = 0; i < statisticsBands.length; i++) {
90
            double min = statisticsBands[i].getMinimum();
91
            if(result>min){
92
                result = min;
93
            }
94
        }
95
        return result;
96
    }
97

    
98
    @Override
99
    public double[] getMean() {
100
        double[] result = new double[statisticsBands.length];
101
        for (int i = 0; i < statisticsBands.length; i++) {
102
            result[i]= statisticsBands[i].getMean();
103
        }
104
        return result;
105
    }
106

    
107
    @Override
108
    public double[] getMin() {
109
        double[] result = new double[statisticsBands.length];
110
        for (int i = 0; i < statisticsBands.length; i++) {
111
            result[i]= statisticsBands[i].getMinimum();
112
        }
113
        return result;
114
    }
115

    
116
    @Override
117
    public double[] getVariance() {
118
        double[] result = new double[statisticsBands.length];
119
        for (int i = 0; i < statisticsBands.length; i++) {
120
            result[i]= statisticsBands[i].getVariance();
121
        }
122
        return result;
123
    }
124

    
125
    @Override
126
    public int getBandCount() {
127
        return statisticsBands.length;
128
    }
129

    
130
    @Override
131
    public Object getTailTrimValue(double percent) {
132
        // TODO Auto-generated method stub
133
        return null;
134
    }
135

    
136
    @Override
137
    public Object[] getTailTrimValue(int pos) {
138
        // TODO Auto-generated method stub
139
        return null;
140
    }
141

    
142
    @Override
143
    public int getTailTrimCount() {
144
        // TODO Auto-generated method stub
145
        return 0;
146
    }
147

    
148
    @Override
149
    public boolean isCalculated() {
150
        return calculated;
151
    }
152

    
153
    @Override
154
    public void calculate(SimpleTaskStatus status) {
155
        calculated = false;
156
        for (int i = 0; i < statisticsBands.length; i++) {
157
            statisticsBands[i].calculate(status);
158
        }
159
        for (int i = 0; i < statisticsBands.length; i++) {
160
            for (int j = i; j < statisticsBands.length; j++) {
161
                this.varCov[i][j] = statisticsBands[i].getCovariance(statisticsBands[j]);
162
            }
163
        }
164

    
165
        for (int i = 0; i < statisticsBands.length; i++) {
166
            for (int j = 0; j < i; j++) {
167
                varCov[i][j] = varCov[j][i];
168
            }
169
        }
170
        calculated = true;
171
    }
172
//
173
//    @Override
174
//    public long[] getNumberOfCells() {
175
//        // TODO Auto-generated method stub
176
//        return null;
177
//    }
178

    
179
    @Override
180
    public double[][] getVarianceCovarianceMatrix() {
181
        return this.varCov;
182
    }
183

    
184
    @Override
185
    public Histogram getHistogram() {
186
        HistogramBand[] histogramBands = new HistogramBand[statisticsBands.length];
187
        for (int i = 0; i < statisticsBands.length; i++) {
188
            histogramBands[i]= statisticsBands[i].getHistogramBand();
189
        }
190
        Histogram histogram = new DefaultHistogram(histogramBands);
191
        return histogram;
192
    }
193

    
194
}