From 21867df8a366fee699afa32135bba10845cdbb31 Mon Sep 17 00:00:00 2001 From: FlorianLautenschlager Date: Fri, 26 Feb 2016 13:49:21 +0100 Subject: [PATCH] Incremented version. --- build.gradle | 2 +- .../timeseries/MultivariateTimeSeries.java | 65 ++----------------- 2 files changed, 8 insertions(+), 59 deletions(-) diff --git a/build.gradle b/build.gradle index 9fd72c5..16e52bc 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ allprojects { } } - version '0.3' + version '0.4' group 'de.qaware.chronix' diff --git a/src/main/java/de/qaware/chronix/timeseries/MultivariateTimeSeries.java b/src/main/java/de/qaware/chronix/timeseries/MultivariateTimeSeries.java index 01f3ea5..b976d43 100644 --- a/src/main/java/de/qaware/chronix/timeseries/MultivariateTimeSeries.java +++ b/src/main/java/de/qaware/chronix/timeseries/MultivariateTimeSeries.java @@ -26,6 +26,7 @@ import de.qaware.chronix.dt.IntList; import de.qaware.chronix.dt.LongList; +import org.apache.commons.lang3.builder.ToStringBuilder; import java.util.ArrayList; import java.util.List; @@ -73,18 +74,10 @@ public void setDimensions(IntList newLabels) { labels.addAll(newLabels); } - public double getMeasurement(int pointIndex, int valueIndex) { - return values.get(pointIndex)[valueIndex]; - } - public double[] getMeasurementVector(int pointIndex) { return values.get(pointIndex); } - public void setMeasurement(int pointIndex, int valueIndex, double newValue) { - values.get(pointIndex)[valueIndex] = newValue; - } - public void add(long time, double[] values) { if (labels.size() != values.length + 1) // labels include a label for time throw new InternalError("ERROR: The TSValues: " + values + " contains the wrong number of values. " + "expected: " + labels.size() + ", " + "found: " + values.length); @@ -96,56 +89,12 @@ public void add(long time, double[] values) { this.values.add(values); } - - public void normalize() { - // Calculate the mean of each FD. - final double[] mean = new double[this.numOfDimensions()]; - for (int col = 0; col < numOfDimensions(); col++) { - double currentSum = 0.0; - for (int row = 0; row < this.size(); row++) - currentSum += this.getMeasurement(row, col); - - mean[col] = currentSum / this.size(); - } // end for loop - - // Calculate the standard deviation of each FD. - final double[] stdDev = new double[numOfDimensions()]; - for (int col = 0; col < numOfDimensions(); col++) { - double variance = 0.0; - for (int row = 0; row < this.size(); row++) - variance += Math.abs(getMeasurement(row, col) - mean[col]); - - stdDev[col] = variance / this.size(); - } // end for loop - - - // Normalize the values in the data using the mean and standard deviation - // for each FD. => Xrc = (Xrc-Mc)/SDc - for (int row = 0; row < this.size(); row++) { - for (int col = 0; col < numOfDimensions(); col++) { - // Normalize data point. - if (stdDev[col] == 0.0) // prevent divide by zero errors - setMeasurement(row, col, 0.0); // stdDev is zero means all pts identical - else // typical case - setMeasurement(row, col, (getMeasurement(row, col) - mean[col]) / stdDev[col]); - } // end for loop - } // end for loop - } // end normalize(); - - + @Override public String toString() { - final StringBuilder outStr = new StringBuilder(); - - // Write the data for each row. - for (int r = 0; r < times.size(); r++) { - // The rest of the value on the row. - final double[] values = this.values.get(r); - for (int c = 0; c < values.length; c++) - outStr.append(values[c]); - - if (r < times.size() - 1) - outStr.append("\n"); - } - return outStr.toString(); + return new ToStringBuilder(this) + .append("labels", labels) + .append("times", times) + .append("values", values) + .toString(); } }