Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java @ 3055:1fbf8462f808
FixWQCurveGenerator generates randomized curves as the Facets crashes when retrieving data
flys-artifacts/trunk@4631 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Sat, 09 Jun 2012 13:46:04 +0000 |
parents | 52aac4941d2a |
children | 0b5a7a2c3724 |
rev | line source |
---|---|
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import gnu.trove.TDoubleArrayList; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.io.Serializable; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
2785
f87fcedbfa82
FixA: Fixed stupid index bug.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2744
diff
changeset
|
7 import org.apache.log4j.Logger; |
f87fcedbfa82
FixA: Fixed stupid index bug.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2744
diff
changeset
|
8 |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 public class Parameters |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 implements Serializable |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 { |
2785
f87fcedbfa82
FixA: Fixed stupid index bug.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2744
diff
changeset
|
12 private static Logger log = Logger.getLogger(Parameters.class); |
f87fcedbfa82
FixA: Fixed stupid index bug.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2744
diff
changeset
|
13 |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 protected String [] columnNames; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 protected TDoubleArrayList [] columns; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 public Parameters() { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 public Parameters(String [] columnNames) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 if (columnNames == null || columnNames.length < 1) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 throw new IllegalArgumentException("columnNames too short."); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 this.columnNames = columnNames; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 columns = new TDoubleArrayList[columnNames.length]; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 for (int i = 0; i < columns.length; ++i) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 columns[i] = new TDoubleArrayList(); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 public int columnIndex(String name) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 for (int i = 0; i < columnNames.length; ++i) { |
2993
70469e3d34b9
FixA: Made Delta W/t calculation finally work
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2785
diff
changeset
|
33 if (columnNames[i].equals(name)) { |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 return i; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 return -1; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
40 public int newRow() { |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 int N = columns[0].size(); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 for (int i = 0; i < columns.length; ++i) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 columns[i].add(Double.NaN); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
48 return N; |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
3010
05a3fe8800b3
FixA: Store Chi^2 of fitting into result, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2993
diff
changeset
|
51 public double get(int row, int index) { |
05a3fe8800b3
FixA: Store Chi^2 of fitting into result, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2993
diff
changeset
|
52 return columns[index].getQuick(row); |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 public double get(int i, String columnName) { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 int index = columnIndex(columnName); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 return index >= 0 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 ? columns[index].getQuick(i) |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 : Double.NaN; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
3010
05a3fe8800b3
FixA: Store Chi^2 of fitting into result, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2993
diff
changeset
|
62 public void set(int row, int index, double value) { |
05a3fe8800b3
FixA: Store Chi^2 of fitting into result, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2993
diff
changeset
|
63 columns[index].setQuick(row, value); |
05a3fe8800b3
FixA: Store Chi^2 of fitting into result, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2993
diff
changeset
|
64 } |
05a3fe8800b3
FixA: Store Chi^2 of fitting into result, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2993
diff
changeset
|
65 |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
66 public void set(int i, String columnName, double value) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
67 int idx = columnIndex(columnName); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
68 if (idx >= 0) { |
2785
f87fcedbfa82
FixA: Fixed stupid index bug.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2744
diff
changeset
|
69 columns[idx].setQuick(i, value); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
70 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
71 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2695
diff
changeset
|
72 |
3011
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
73 public boolean set(int row, int [] indices, double [] values) { |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
74 boolean invalid = false; |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
75 for (int i = 0; i < indices.length; ++i) { |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
76 double v = values[i]; |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
77 if (Double.isNaN(v)) { |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
78 invalid = true; |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
79 } |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
80 else { |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
81 columns[indices[i]].setQuick(row, v); |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
82 } |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
83 } |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
84 return invalid; |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
85 } |
ab81ffd1343e
FixA: Reactivated rewrite of the outlier checks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3010
diff
changeset
|
86 |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 public int size() { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 return columns[0].size(); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 public int getNumberColumns() { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 return columnNames.length; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 public String [] getColumnNames() { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 return columnNames; |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 public void removeNaNs() { |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 W.removeNaNs(columns); |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 } |
2744
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
102 |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
103 public int [] columnIndices(String [] columns) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
104 int [] indices = new int[columns.length]; |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
105 for (int i = 0; i < columns.length; ++i) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
106 indices[i] = columnIndex(columns[i]); |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
107 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
108 return indices; |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
109 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
110 |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
111 public void get(int row, int [] columnIndices, double [] values) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
112 for (int i = 0; i < columnIndices.length; ++i) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
113 int index = columnIndices[i]; |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
114 values[i] = index >= 0 && index < columns.length |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
115 ? columns[index].getQuick(row) |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
116 : Double.NaN; |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
117 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
118 } |
3027
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
119 |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
120 public int binarySearch(String columnName, double value) { |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
121 return binarySearch(columnIndex(columnName), value); |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
122 } |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
123 |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
124 public int binarySearch(int columnIndex, double value) { |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
125 TDoubleArrayList column = columns[columnIndex]; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
126 return column.binarySearch(value); |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
127 } |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
128 |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
129 public int binarySearch(String columnName, double value, double epsilon) { |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
130 return binarySearch(columnIndex(columnName), value, epsilon); |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
131 } |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
132 |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
133 public int binarySearch(int columnIndex, double value, double epsilon) { |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
134 if (epsilon < 0d) epsilon = -epsilon; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
135 double vl = value - epsilon; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
136 double vh = value + epsilon; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
137 |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
138 TDoubleArrayList column = columns[columnIndex]; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
139 int lo = 0, hi = column.size()-1; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
140 while (hi >= lo) { |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
141 int mid = (lo+hi) >> 1; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
142 double v = column.getQuick(mid); |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
143 if (v < vl) hi = mid - 1; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
144 else if (v > vh) lo = mid + 1; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
145 else return mid; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
146 } |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
147 |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
148 return -1; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
149 } |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
150 |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
151 public boolean isSorted(String columnName) { |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
152 return isSorted(columnIndex(columnName)); |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
153 } |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
154 |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
155 public boolean isSorted(int columnIndex) { |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
156 TDoubleArrayList column = columns[columnIndex]; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
157 for (int i = 1, N = column.size(); i < N; ++i) { |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
158 if (column.getQuick(i-1) > column.getQuick(i)) { |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
159 return false; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
160 } |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
161 } |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
162 return true; |
52aac4941d2a
FixA: Added binary search methods for parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3011
diff
changeset
|
163 } |
2695
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 } |
ae0742f92cd5
Added model to store fitting results into cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |