psteitz 2004/01/28 22:26:14
Modified: math/src/java/org/apache/commons/math/random
EmpiricalDistributionImpl.java
Log:
Replaced unnecessary bin search with direct computation.
Revision Changes Path
1.15 +6 -17
jakarta-commons/math/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
Index: EmpiricalDistributionImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- EmpiricalDistributionImpl.java 25 Jan 2004 21:30:41 -0000 1.14
+++ EmpiricalDistributionImpl.java 29 Jan 2004 06:26:14 -0000 1.15
@@ -213,23 +213,12 @@
String str = null;
double val = 0.0d;
while ((str = in.readLine()) != null) {
- val = new Double(str).doubleValue();
-
- // Find bin and add value to binStats for the bin
- boolean found = false;
- int i = 0;
- while (!found) {
- if (i >= binCount) {
- throw new RuntimeException("bin alignment error");
- }
- if (val <= binUpperBounds[i]) {
- found = true;
- SummaryStatistics stats = (SummaryStatistics)binStats.get(i);
- stats.addValue(val);
- }
- i++;
- }
+ val = Double.parseDouble(str);
+ SummaryStatistics stats =
+ (SummaryStatistics) binStats.get(Math.max((int)Math.ceil((val - min) /
delta) - 1, 0));
+ stats.addValue(val);
}
+
in.close();
in = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]