Permalink
Browse files

minor change

  • Loading branch information...
1 parent 4b81b98 commit 5da915adf9e3ae96812e65c34b4c208fef34c9b6 @karussell committed May 1, 2012
View
@@ -1,2 +1,3 @@
target/
*~
+deploy-*.sh
@@ -17,7 +17,7 @@
*
* @author Peter Karich
*/
-class DoubleVector extends AbstractCollection implements VectorInterface {
+class DoubleVector extends AbstractCollection implements DoubleVectorInterface {
private boolean maxIsInvalid = true;
private boolean minIsInvalid = true;
@@ -13,6 +13,11 @@
*/
public interface HistogrammInterface extends VectorInterface {
+ /**
+ * @return sum of all entries
+ */
+ double getSum();
+
/**
* This method returns the root mean squared error of all added values. <br>
* The definition is RMSError = sqrt[ sum_i_to_n((x_i - x_mean)^2) / n] <br>
@@ -4,7 +4,6 @@
* Created on 21. Mai 2007, 14:13
* This stands under Public domain
*/
-
package de.genvlin.core.data;
/**
@@ -13,94 +12,108 @@
* @author Peter Karich
*/
class HistogrammVector extends DataVector implements HistogrammInterface {
-
+
/**
* Creates a new instance of HistogrammVector
*/
HistogrammVector(ID id) {
super(id, null);
}
-
+
public double getRMSError() {
int size = size();
- if(size == 0) {
+ if (size == 0) {
return 0;
}
double mean = getMean();
-
+
double result = 0;
double tmp;
Number n;
int noOfNonNullValues = size;
-
- for(int i = 0; i < size; i++) {
+
+ for (int i = 0; i < size; i++) {
n = get(i);
- if(n != null) {
+ if (n != null) {
tmp = n.doubleValue() - mean;
result += tmp * tmp;
} else {
noOfNonNullValues--;
}
}
- if(noOfNonNullValues > 0) {
- return Math.sqrt(result/noOfNonNullValues);
+ if (noOfNonNullValues > 0) {
+ return Math.sqrt(result / noOfNonNullValues);
} else {
return 0;
}
}
-
+
public double getRMS() {
int size = size();
- if(size == 0) {
+ if (size == 0) {
return 0;
}
-
+
double result = 0;
double tmp;
int noOfNonNullValues = size;
Number n;
-
- for(int i = 0; i < size; i++) {
+
+ for (int i = 0; i < size; i++) {
n = get(i);
- if(n != null) {
+ if (n != null) {
tmp = n.doubleValue();
result += tmp * tmp;
} else {
noOfNonNullValues--;
}
}
-
- if(noOfNonNullValues > 0) {
- return Math.sqrt(result/size);
+
+ if (noOfNonNullValues > 0) {
+ return Math.sqrt(result / size);
} else {
return 0;
}
}
-
+
public double getMean() {
//TODO PERFORMANCE: we can sum + substract on every add/remove call
int size = size();
- if(size == 0) {
+ if (size == 0) {
return 0;
}
-
+
double result = 0;
Number n;
int noOfNonNullValues = size;
-
- for(int i = 0; i < size; i++) {
+
+ for (int i = 0; i < size; i++) {
n = get(i);
- if(n != null) {
+ if (n != null) {
result += n.doubleValue();
} else {
- noOfNonNullValues --;
+ noOfNonNullValues--;
}
}
-
- if(noOfNonNullValues > 0) {
+
+ if (noOfNonNullValues > 0) {
return result / noOfNonNullValues;
} else {
return 0;
}
}
+
+ public double getSum() {
+ double sum = 0;
+ int size = size();
+ if (size == 0)
+ return 0;
+ Number n;
+ for (int i = 0; i < size; i++) {
+ n = get(i);
+ if (n != null)
+ sum += n.doubleValue();
+ }
+ return sum;
+ }
}
@@ -10,6 +10,8 @@
/** This is the factory of pool's, vector's and xyvector's. Or you
* specific IDData if you want implement. Get the singleton instance
* via getDefault().
+ *
+ * WARNING: not thread safe!
*
* @author Peter Karich
*/
@@ -40,8 +40,14 @@
*/
public Number set(int i, Number n);
+ /**
+ * @return the minimal entry in this object
+ */
public Number getMin();
+ /**
+ * @return the maximal entry in this object
+ */
public Number getMax();
/**
@@ -159,6 +159,14 @@ public void removeVectorListener(CollectionListener vl) {
x.removeVectorListener(vl);
y.removeVectorListener(vl);
}
+
+ public VectorInterface getX() {
+ return x;
+ }
+
+ public VectorInterface getY() {
+ return y;
+ }
/** The Iterator on Point.Double.
*/
@@ -54,5 +54,9 @@
public double getXDouble(int index);
- public double getYDouble(int index);
+ public double getYDouble(int index);
+
+ VectorInterface getX();
+
+ VectorInterface getY();
}
Oops, something went wrong.

0 comments on commit 5da915a

Please sign in to comment.