Skip to content

Commit

Permalink
minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter committed May 1, 2012
1 parent 4b81b98 commit 5da915a
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 89 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
target/
*~
deploy-*.sh
2 changes: 1 addition & 1 deletion src/main/java/de/genvlin/core/data/DoubleVector.java
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/de/genvlin/core/data/HistogrammInterface.java
Expand Up @@ -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>
Expand Down
69 changes: 41 additions & 28 deletions src/main/java/de/genvlin/core/data/HistogrammVector.java
Expand Up @@ -4,7 +4,6 @@
* Created on 21. Mai 2007, 14:13
* This stands under Public domain
*/

package de.genvlin.core.data;

/**
Expand All @@ -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;
}
}
2 changes: 2 additions & 0 deletions src/main/java/de/genvlin/core/data/MainPool.java
Expand Up @@ -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
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/de/genvlin/core/data/VectorInterface.java
Expand Up @@ -40,8 +40,14 @@ public interface VectorInterface extends CollectionInterface {
*/
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();

/**
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/de/genvlin/core/data/XYVector.java
Expand Up @@ -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.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/de/genvlin/core/data/XYVectorInterface.java
Expand Up @@ -54,5 +54,9 @@ public interface XYVectorInterface extends BoundedXYCollectionInterface {

public double getXDouble(int index);

public double getYDouble(int index);
public double getYDouble(int index);

VectorInterface getX();

VectorInterface getY();
}

0 comments on commit 5da915a

Please sign in to comment.