-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from koosvary/Release_0.2.0
Release 0.2.0
- Loading branch information
Showing
33 changed files
with
1,089 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,7 @@ gradle-app.setting | |
*.iml | ||
*.ipr | ||
*.iws | ||
|
||
api/out | ||
cli/out | ||
client/out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
api/src/main/java/org/iconic/ea/data/preprocessing/Smooth.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.iconic.ea.data.preprocessing; | ||
|
||
import java.util.ArrayList; | ||
import java.lang.*; | ||
|
||
public class Smooth { | ||
private static int N = 2; // N is the number of neighboring data points on either side of the value | ||
|
||
/** | ||
* <p> | ||
* Smooths the values of an Array. Alternatively known as "Moving Average Filtering". | ||
* </p> | ||
* | ||
* <p> | ||
* Given an array of values, the function will take the 'N' neighbouring values on either side of the index, take | ||
* the sum of all these values, then update the value of the index to the average of the sum. | ||
* </p> | ||
* | ||
* <p> | ||
* If the span window is outside of the Array bounds, the window will become the minimum reach of both sides. | ||
* </p> | ||
* | ||
* @param values the array that will be smoothed | ||
*/ | ||
public static ArrayList<Number> apply(ArrayList<Number> values) { | ||
ArrayList<Number> newValues = new ArrayList<>(); | ||
|
||
for (int i = 0; i < values.size(); i++) { | ||
// The index of the lowest span from the point | ||
int lowerBound = Math.max(0, i - N); | ||
|
||
// The size of the lowest span | ||
int lowerBoundRange = i - lowerBound; | ||
|
||
// The index of the highest span from the point | ||
int upperBound = Math.min(values.size() - 1, i + N); | ||
|
||
// The size of the highest span | ||
int upperBoundRange = upperBound - i; | ||
|
||
// The smallest span of reach for both sides | ||
int span = Math.min(lowerBoundRange, upperBoundRange); | ||
|
||
// Find the sum of all values in the span | ||
Double sum = 0.0; | ||
for (int j = i - span; j <= i + span; j++) { | ||
sum += values.get(j).doubleValue(); | ||
} | ||
|
||
// Average of the span size | ||
newValues.add( 1.0 / (2.0 * span + 1.0) * sum ); | ||
} | ||
|
||
// Update the old values to the new values | ||
for (int i = 0; i < values.size(); i++) { | ||
values.set(i, newValues.get(i)); | ||
} | ||
|
||
return newValues; | ||
} | ||
|
||
/** | ||
* <p> | ||
* Sets the window size of values to use when smoothing the array of data. | ||
* </p> | ||
* | ||
* @param neighbourSize the number of neighbours on either side of each point to be used for smoothing | ||
*/ | ||
public void setNeighbourSize(int neighbourSize) { | ||
this.N = neighbourSize; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
api/src/test/java/org/iconic/ea/operator/primitive/ConstantTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.iconic.ea.operator.primitive; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.ArrayList; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* Test class for {@link org.iconic.ea.operator.primitive.Constant} | ||
* @author Scott Walker | ||
*/ | ||
class ConstantTest { | ||
@DisplayName("Test constants using doubles") | ||
@MethodSource("doubleListProvider") | ||
@ParameterizedTest | ||
void constantDoublesTest(final double arg, final double expected) { | ||
final FunctionalPrimitive<Double, Double> constant = new Constant<>(arg); | ||
final double delta = 0.001; | ||
final double actual = constant.apply(new ArrayList<>()); | ||
|
||
assertEquals(expected, actual, delta); | ||
} | ||
|
||
/** | ||
* <p>Returns a stream of two identical doubles</p> | ||
* | ||
* @return a stream of double n-tuples | ||
*/ | ||
private static Stream<Arguments> doubleListProvider() { | ||
return Stream.of( | ||
Arguments.of(1.0, 1.0), | ||
Arguments.of(0.0, 0.0), | ||
Arguments.of(10.0, 10.0) | ||
); | ||
} | ||
} |
Oops, something went wrong.