Hello Stefan!
Sorry for taking so long to keep you updated, a lot of things have happened.
Taking into account the approach you suggested to me of the state-machine I started working on it, taking as reference the one that you also suggested. So in order to make it work, I need to define the hysteresis time and the prediction. For the first, how should it look like?
Regarding the prediction, I know that in OpenEMS there’s already the simple prediction component, but since I wanted to add something new, I looked at the WEKA time series forecasting API. I was able to get a generation data for one month, every 15 minutes, and I wanted to forecast 2 days ahead with that data. Using the time series forecaster I was able to get this result:
I might need to change the x-axis to show the actual dates. But the last 192 results are the prediction. The error is quite high for the last results but I think more than that is not possible without some Machine Learning. Anyway, since I was able to get this result, and also run it with the code in eclipse I decided to integrate it. I read how to integrate an external library to OSGi, but I had no luck, first I tried creating the .bnd file containing the following information:
-classpath: timeseriesforecasting1.1.27.jar
-output: timeseriesforecasting-1.1.27.jar
Export-Package: *;-split-package:=merge-last;-noimport:=true
Import-Package: *
Bundle-Version: 1.1.27
Bundle-Name: Time Series Forecasting
Bundle-SymbolicName:
But after that, I don’t know what to do, and it does not seem like it became a bundle. What am I missing?
Below is the code for the forecasting provided as an example from WEKA, I modified some lines to use the mathematical model that fits the best and other numbers of prediction.
package io.openems.edge.forecaster;
import java.io.*;
import java.util.List;
import weka.core.Instances;
import weka.classifiers.functions.SMOreg;
import weka.classifiers.evaluation.NumericPrediction;
import weka.classifiers.timeseries.WekaForecaster;
//import weka.classifiers.timeseries.core.TSLagMaker;
/**
* Example of using the time series forecasting API. To compile and
* run the CLASSPATH will need to contain:
*
* weka.jar (from your weka distribution)
* pdm-timeseriesforecasting-ce-TRUNK-SNAPSHOT.jar (from the time series package)
* jcommon-1.0.14.jar (from the time series package lib directory)
* jfreechart-1.0.13.jar (from the time series package lib directory)
*/
public class TimeSeriesForecaster {
public static void main(String[] args) {
try {
// path
String pathToWindData = weka.core.WekaPackageManager.PACKAGES_DIR.toString()
+ File.separator + "timeseriesForecasting" + File.separator + "sample-data"
+ File.separator + "wind.arff";
// load the data
Instances wind = new Instances(new BufferedReader(new FileReader(pathToWindData)));
// new forecaster
WekaForecaster forecaster = new WekaForecaster();
// set the targets we want to forecast. This method calls
// setFieldsToLag() on the lag maker object for us
forecaster.setFieldsToForecast("capacity (kW)");
// default underlying classifier is SMOreg (SVM)
forecaster.setBaseForecaster(new SMOreg());
forecaster.getTSLagMaker().setTimeStampField("Date"); // date time stamp
forecaster.getTSLagMaker().setMinLag(1);
forecaster.getTSLagMaker().setMaxLag(3); // monthly data
// add a month of the year indicator field
//forecaster.getTSLagMaker().setAddMonthOfYear(true);
// add a quarter of the year indicator field
//forecaster.getTSLagMaker().setAddQuarterOfYear(true);
// build the model
forecaster.buildForecaster(wind, System.out);
// prime the forecaster with enough recent historical data
// to cover up to the maximum lag.
forecaster.primeForecaster(wind);
// forecast for 2 days
List<List<NumericPrediction>> forecast = forecaster.forecast(192, System.out);
// output the predictions. Outer list is over the steps; inner list is over
// the targets
for (int i = 0; i < 192; i++) {
List<NumericPrediction> predsAtStep = forecast.get(i);
for (int j = 0; j < 1; j++) {
NumericPrediction predForTarget = predsAtStep.get(j);
System.out.print("" + predForTarget.predicted() + " ");
}
System.out.println();
}
// we can continue to use the trained forecaster for further forecasting
// by priming with the most recent historical data (as it becomes available).
// At some stage it becomes prudent to re-build the model using current
// historical data.
} catch (Exception ex) {
ex.printStackTrace();
}
}
}