I’m a master’s student working on a project of an EMS. Right now I’m working with a power forecasting feature. After searching I found WEKA machine learning software that can help me doing the forecast. (Weka 3 - Data Mining with Open Source Machine Learning Software in Java). It was tested and it works properly, but now I need to integrate it to OpenEMS.
Also, I saw some licences issues since WEKA is licenced as GPL which might be incompatible with OpenEMS EPL. Does anyone know about this issue and how can I deal with it?
After that, I try to rebuild the project but it doesn’t work, saying that I have a compilation/path problem and also a “circular dependency error”
I also saw that in some cases it is needed to modify/create a manifest file, but I don’t know how this process is done. Does anyone knows how to do this or any other ways to solve this problem?
I’m using basically the same example, adapted to my data and different parameters, like the algorithm for the prediction. Maybe it is because of the path from the .arff file? (My arff file is in: User>wekafile>packages>sample-data)
Here below my code. Nonetheless, I’ll suggest using the sample data that weak provides downloadable from the package URL link(Waikato Environment for Knowledge Analysis (WEKA)), since mine has been modified and requires some other changes.
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;
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();
}
}
}
Another issue that might be stopping it from running is the format of the .arff file. I’ll show below a screenshot of how should the header look like:
I spent again a few hours trying to one-by-one integrate the required dependencies into OSGi. This is a tedious task… maybe this work-in-process helps you somehow. I don’t know when I have again time for this.
I’ll check it, and I can do it if you can tell me how exactly is the process to integrate the required dependencies into OSGi. Basically that’s been the reason for me to not do it. Is there a guide/tutorial for it?
I am not really an OSGi expert either. It proved to be a very good framework for the dynamic models and dependency injection in OpenEMS; but dependencies are always a problem. It might be best to ask the experts for the best approach: https://bnd.discourse.group/
For the actual deployment in your case, it might be the best to run a separate python executable or a web service (e.g. via a docker container) that does the actual prediction.