Skip to content
Snippets Groups Projects
Commit 657d8e47 authored by Eilert Tunheim's avatar Eilert Tunheim
Browse files

non-functioning-cubic-regression

parent 28f5e40a
No related branches found
No related tags found
No related merge requests found
...@@ -54,5 +54,6 @@ ...@@ -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: 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: 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: joda-time:joda-time:2.10.14" level="project" />
<orderEntry type="library" name="Maven: org.jblas:jblas:1.2.4" level="project" />
</component> </component>
</module> </module>
\ No newline at end of file
...@@ -40,6 +40,12 @@ ...@@ -40,6 +40,12 @@
<artifactId>joda-time</artifactId> <artifactId>joda-time</artifactId>
<version>2.10.14</version> <version>2.10.14</version>
</dependency> </dependency>
<dependency>
<groupId>org.jblas</groupId>
<artifactId>jblas</artifactId>
<version>1.2.4</version>
</dependency>
</dependencies> </dependencies>
<properties> <properties>
......
...@@ -11,10 +11,11 @@ import org.apache.commons.math3.distribution.TDistribution; ...@@ -11,10 +11,11 @@ import org.apache.commons.math3.distribution.TDistribution;
import org.apache.commons.math3.exception.MathIllegalArgumentException; import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.stat.descriptive.SummaryStatistics; import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
import org.apache.commons.math3.stat.regression.SimpleRegression; import org.apache.commons.math3.stat.regression.SimpleRegression;
import org.jblas.DoubleMatrix;
import org.jblas.Solve;
import java.util.*; import java.util.*;
import static com.application.DB.Constants.ADJUST_REGRESSION;
import static com.application.DB.Constants.CONFIDENCE_INTERVAL; import static com.application.DB.Constants.CONFIDENCE_INTERVAL;
public class LineChartFunctionality { public class LineChartFunctionality {
...@@ -258,6 +259,7 @@ public class LineChartFunctionality { ...@@ -258,6 +259,7 @@ public class LineChartFunctionality {
// Connect the data to a series // Connect the data to a series
//System.out.println(simpleRegression.predict(i)); //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), simpleRegression.predict(i)));
/*
regressionSeries.getData().add(new XYChart.Data<String, Number>( regressionSeries.getData().add(new XYChart.Data<String, Number>(
String.valueOf(i), String.valueOf(i),
getNonLinearRegression( getNonLinearRegression(
...@@ -270,6 +272,12 @@ public class LineChartFunctionality { ...@@ -270,6 +272,12 @@ public class LineChartFunctionality {
i, i,
getDataPointsXAxis() getDataPointsXAxis()
))); )));
*/
regressionSeries.getData().add(new XYChart.Data<String, Number>(
String.valueOf(i),
getCubicNonLinearRegression(confidenceIntervalData,i)
));
} }
updateLineChart(regressionSeries); updateLineChart(regressionSeries);
//lineChart.setOpacity(1); //lineChart.setOpacity(1);
...@@ -378,10 +386,100 @@ public class LineChartFunctionality { ...@@ -378,10 +386,100 @@ public class LineChartFunctionality {
System.out.println("Beta: " + beta); System.out.println("Beta: " + beta);
//System.out.println(p_t); //System.out.println(p_t);
return 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() { public static int getDataPointsXAxis() {
return dataPointsXAxis; return dataPointsXAxis;
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
} }
.chart-earlier-data-line { .chart-earlier-data-line {
-fx-stroke-width: 5px; -fx-stroke-width: 1px;
-fx-effect: null; -fx-effect: null;
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
} }
.chart-earlier-data-line { .chart-earlier-data-line {
-fx-stroke-width: 5px; -fx-stroke-width: 1px;
-fx-effect: null; -fx-effect: null;
} }
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment