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

Implemented pretty good non linear regression using logistic regression

parent 40a555d3
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ public final class Constants {
public static String MOISTURE_GOAL = "";
// Number of wanted drying periods
public static int NUMBER_OF_PERIODS = 3;
public static int NUMBER_OF_PERIODS = 1;
// Database ID/name
public static final String PROJECT_ID = "sf-drying-optimization";
......
......@@ -10,6 +10,7 @@ import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
import org.apache.commons.math3.stat.regression.SimpleRegression;
import java.lang.reflect.Array;
import java.util.*;
public class LineChartFunctionality {
......@@ -116,7 +117,7 @@ public class LineChartFunctionality {
index++;
}
//allSeries.add(newSeries);
//updateLineChart(newSeries);
updateLineChart(newSeries);
//lineChart.setOpacity(1);
}
......@@ -150,25 +151,6 @@ public class LineChartFunctionality {
data[index][1] = list.get(j);
index++;
}
/*
for (int j = 0; j < data[i].length; j++) {
System.out.println("data[i][j]: "+data[i][j]);
if(data[i][j] == 0.0){
double sum = 0.0;
double index = 0.0;
for (int k = 0; k < list.size(); k++) {
if(data[i][k] != 0.0){
sum += data[i][k];
index += 1;
}
}
System.out.println("sum/index: "+ sum/index);
data[i][j] = sum/index;
}
}
*/
}
......@@ -188,16 +170,46 @@ public class LineChartFunctionality {
}
}
// Finds the end datapoint at the end of each graph
int numberOfGraphs = 0;
ArrayList<Integer> endOfGraphPoints = new ArrayList<>();
for (int i = 0; i < confidenceIntervalData.size(); i++) {
ArrayList<Double> list = confidenceIntervalData.get(i);
for (int j = 0; j < list.size(); j++) {
if (numberOfGraphs < list.size()) {
numberOfGraphs = list.size();
}
if (list.size() < numberOfGraphs) {
endOfGraphPoints.add(i);
numberOfGraphs = list.size();
}
}
}
endOfGraphPoints.add(confidenceIntervalData.size());
int dataPoints = 0;
for (int i = 0; i < endOfGraphPoints.size(); i++) {
dataPoints+=endOfGraphPoints.get(i);
}
dataPoints = dataPoints/endOfGraphPoints.size();
XYChart.Series<String, Number> regressionSeries = new XYChart.Series<String, Number>();
for (int i = 0; i < confidenceIntervalData.size(); i++) {
for (int i = 0; i <= dataPoints; i++) {
// 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(confidenceIntervalData,simpleRegression.getIntercept(),simpleRegression.getSlope(),i)));
regressionSeries.getData().add(new XYChart.Data<String, Number>(
String.valueOf(i),
getNonLinearRegression(confidenceIntervalData,
simpleRegression.getIntercept(),
simpleRegression.getSlope(),
i,
dataPoints)));
}
updateLineChart(regressionSeries);
//lineChart.setOpacity(1);
......@@ -226,27 +238,32 @@ public class LineChartFunctionality {
}
public static double getNonLinearRegression(Map<Integer, ArrayList<Double>> confidenceIntervalData, double slope, double intercept, double j) {
public static double getNonLinearRegression(Map<Integer, ArrayList<Double>> confidenceIntervalData, double y0, double alpha, double j, int n) {
//return Math.exp(intercept+slope*i)/(1+Math.exp(intercept+slope*i));
double alpha = intercept/100;
double beta = alpha/(slope/100);
double maxYValue = 0.0;
double n = confidenceIntervalData.size();
double beta = 0.0;
//double n = confidenceIntervalData.size();
for (Map.Entry<Integer, ArrayList<Double>> entry : confidenceIntervalData.entrySet()) {
for (int i = 0; i < entry.getValue().size(); i++) {
if(maxYValue < entry.getValue().get(i)){
maxYValue = entry.getValue().get(i);
if(beta < entry.getValue().get(i)){
beta = entry.getValue().get(i);
}
}
}
//System.out.println("maxYValue: " + maxYValue);
//System.out.println("j*n: "+j/n);
double p_t = ((beta*maxYValue)/(maxYValue+((beta-maxYValue)*Math.exp(-alpha*(j)))));
//double p_t = ((beta*maxYValue)/(maxYValue+((beta-maxYValue)*Math.exp(-alpha*(yValue-maxYValue)))));
//double p_t = ((beta* y0)/(y0 +((beta- y0)*Math.exp(-alpha*j/n/(2*Math.PI)))))-y0; //Funker sånn halveis
double p_t = (((beta * y0))/(y0 +((beta- y0)*Math.exp(-alpha*j/n/(6.5)))))-y0; //Funker sånn halveis
//double p_t = (beta * y0)/(y0 + (beta - y0)*Math.exp(-intercept*(j/n)));
System.out.println("---------------------------");
System.out.println("y0: " + y0);
System.out.println("Alpha: " + alpha);
System.out.println("Beta: " + beta);
System.out.println(p_t);
return p_t;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment