diff --git a/Bachelor_application.iml b/Bachelor_application.iml index 06a8fa9ccd7558c365b321eced705ef4f63de40c..f8154df5a6a0bb9048b52fc21433f278efd739cf 100644 --- a/Bachelor_application.iml +++ b/Bachelor_application.iml @@ -54,5 +54,6 @@ <orderEntry type="library" name="Maven: com.google.auto.value:auto-value-annotations:1.9" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" /> <orderEntry type="library" name="Maven: joda-time:joda-time:2.10.14" level="project" /> + <orderEntry type="library" name="Maven: org.jblas:jblas:1.2.4" level="project" /> </component> </module> \ No newline at end of file diff --git a/pom.xml b/pom.xml index 51648b17b7224b51ee9052b3b136ff9a1d2b888a..e6c30632be74fa49f90a30a1c7e6dfa33c7d6844 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,12 @@ <artifactId>joda-time</artifactId> <version>2.10.14</version> </dependency> + <dependency> + <groupId>org.jblas</groupId> + <artifactId>jblas</artifactId> + <version>1.2.4</version> + </dependency> + </dependencies> <properties> diff --git a/src/main/java/com/application/GUI/LineChartFunctionality.java b/src/main/java/com/application/GUI/LineChartFunctionality.java index a72f2b9f35504939bca003656fe0d3157375dbc0..e68a03d0ef2fc42cb12737f470226075885266cb 100644 --- a/src/main/java/com/application/GUI/LineChartFunctionality.java +++ b/src/main/java/com/application/GUI/LineChartFunctionality.java @@ -11,10 +11,11 @@ import org.apache.commons.math3.distribution.TDistribution; import org.apache.commons.math3.exception.MathIllegalArgumentException; import org.apache.commons.math3.stat.descriptive.SummaryStatistics; import org.apache.commons.math3.stat.regression.SimpleRegression; +import org.jblas.DoubleMatrix; +import org.jblas.Solve; import java.util.*; -import static com.application.DB.Constants.ADJUST_REGRESSION; import static com.application.DB.Constants.CONFIDENCE_INTERVAL; public class LineChartFunctionality { @@ -258,6 +259,7 @@ public class LineChartFunctionality { // Connect the data to a series //System.out.println(simpleRegression.predict(i)); //regressionSeries.getData().add(new XYChart.Data<String, Number>(String.valueOf(i), simpleRegression.predict(i))); + /* regressionSeries.getData().add(new XYChart.Data<String, Number>( String.valueOf(i), getNonLinearRegression( @@ -270,6 +272,12 @@ public class LineChartFunctionality { i, getDataPointsXAxis() ))); + + */ + regressionSeries.getData().add(new XYChart.Data<String, Number>( + String.valueOf(i), + getCubicNonLinearRegression(confidenceIntervalData,i) + )); } updateLineChart(regressionSeries); //lineChart.setOpacity(1); @@ -378,10 +386,100 @@ public class LineChartFunctionality { System.out.println("Beta: " + beta); //System.out.println(p_t); + + return p_t; } + + /** + * Third degree cubic non-linear regression + * + * n = + * + * sumT1 = + * sumT2 = + * sumT3 = + * sumT4 = + * + * sumY = + * sumYxT1= + * sumYxT2 = + * @param confidenceIntervalData Data to process + * @return + */ + public static double getCubicNonLinearRegression(Map<Integer, ArrayList<Double>> confidenceIntervalData, int index){ + + double n = confidenceIntervalData.size(); + //double n = getDataPointsYAxis(); + //System.out.println(n); + + double sumT1 = 0; + double sumT2 = 0; + double sumT3 = 0; + double sumT4 = 0; + + double sumY = 0; + double sumYxT1 = 0; + double sumYxT2 = 0; + + + + for (Map.Entry<Integer, ArrayList<Double>> entry : confidenceIntervalData.entrySet()) { + + sumT1 += entry.getKey(); + sumT2 += Math.pow(entry.getKey(),2); + sumT3 += Math.pow(entry.getKey(),3); + sumT4 += Math.pow(entry.getKey(),4); + + for (int j = 0; j < entry.getValue().size(); j++) { + + sumY += entry.getValue().get(j); + sumYxT1 += entry.getValue().get(j) * entry.getKey(); + sumYxT2 += entry.getValue().get(j) * Math.pow(entry.getKey(), 2); + } + } + + + + +/* + for (Map.Entry<Integer, ArrayList<Double>> entry : confidenceIntervalData.entrySet()) { + + + + for (int j = 0; j < entry.getValue().size(); j++) { + + sumT1 += Math.pow(entry.getValue().get(j), 1); + sumT2 += Math.pow(entry.getValue().get(j), 2); + sumT3 += Math.pow(entry.getValue().get(j), 3); + sumT4 += Math.pow(entry.getValue().get(j), 4); + + sumY += entry.getKey(); + sumYxT1 += entry.getKey() * entry.getValue().get(j); + sumYxT2 += entry.getKey() * Math.pow(entry.getValue().get(j), 2); + } + } + + */ + + + + DoubleMatrix firstMatrix = new DoubleMatrix(new double[][]{{n,sumT1,sumT2},{sumT1,sumT2,sumT3},{sumT2,sumT3,sumT4}}); + DoubleMatrix secondMatrix = new DoubleMatrix( new double[]{sumY, sumYxT1, sumYxT2}); + + + DoubleMatrix solvedMatrix = Solve.solve(firstMatrix,secondMatrix); + + //System.out.println(solvedMatrix); + + //return ((solvedMatrix.get(0)) + (solvedMatrix.get(1) * index) + (solvedMatrix.get(2) * Math.pow(index, 2))); + //return ((solvedMatrix.get(1) * index) + (solvedMatrix.get(2) * Math.pow(index, 2)))*(-1); + return ((solvedMatrix.get(1) * index) + (solvedMatrix.get(2) * Math.pow(index, 2))); + + } + public static int getDataPointsXAxis() { return dataPointsXAxis; } diff --git a/src/main/resources/com.application/GUI/graphStyles.css b/src/main/resources/com.application/GUI/graphStyles.css index 7cff0ac3c21e2302932681fd0aa6e95d79e5c0f1..fbc50cdb17da7664837fcf7e3b83160e96b07869 100644 --- a/src/main/resources/com.application/GUI/graphStyles.css +++ b/src/main/resources/com.application/GUI/graphStyles.css @@ -5,7 +5,7 @@ } .chart-earlier-data-line { - -fx-stroke-width: 5px; + -fx-stroke-width: 1px; -fx-effect: null; } diff --git a/target/classes/com.application/GUI/graphStyles.css b/target/classes/com.application/GUI/graphStyles.css index 7cff0ac3c21e2302932681fd0aa6e95d79e5c0f1..fbc50cdb17da7664837fcf7e3b83160e96b07869 100644 --- a/target/classes/com.application/GUI/graphStyles.css +++ b/target/classes/com.application/GUI/graphStyles.css @@ -5,7 +5,7 @@ } .chart-earlier-data-line { - -fx-stroke-width: 5px; + -fx-stroke-width: 1px; -fx-effect: null; } diff --git a/target/classes/com/application/GUI/LineChartFunctionality.class b/target/classes/com/application/GUI/LineChartFunctionality.class index fc06715ba9dfd5d758264f91fd1228deb018f988..7fed56545a4d3c4f04d50dafc1845a293cbaba83 100644 Binary files a/target/classes/com/application/GUI/LineChartFunctionality.class and b/target/classes/com/application/GUI/LineChartFunctionality.class differ