Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Bacheloroppgave_2022
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eilert Tunheim
Bacheloroppgave_2022
Commits
ee4980af
Commit
ee4980af
authored
2 years ago
by
Eilert Tunheim
Browse files
Options
Downloads
Patches
Plain Diff
Implemented pretty good non linear regression using logistic regression
parent
40a555d3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/com/application/DB/Constants.java
+1
-1
1 addition, 1 deletion
src/main/java/com/application/DB/Constants.java
src/main/java/com/application/GUI/LineChartFunctionality.java
+47
-30
47 additions, 30 deletions
...main/java/com/application/GUI/LineChartFunctionality.java
with
48 additions
and
31 deletions
src/main/java/com/application/DB/Constants.java
+
1
−
1
View file @
ee4980af
...
...
@@ -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"
;
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/application/GUI/LineChartFunctionality.java
+
47
−
30
View file @
ee4980af
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment