((TSLagUser) forecaster).getTSLagMaker().setArtificialTimeStartValue(
m_primeWindowSize);
}
}
for (int i = 0; i < m_trainingData.numInstances(); i++) {
Instance current = m_trainingData.instance(i);
if (i < m_primeWindowSize) {
primeData.add(current);
} else {
if (i % 10 == 0) {
for (PrintStream p : progress) {
p.println("Evaluating on training set: processed " + i
+ " instances...");
}
}
forecaster.primeForecaster(primeData);
/*
* System.err.println(primeData); System.exit(1);
*/
List<List<NumericPrediction>> forecast = null;
if (forecaster instanceof OverlayForecaster
&& ((OverlayForecaster) forecaster).isUsingOverlayData()) {
// can only generate forecasts for remaining training data that
// we can use as overlay data
if (current != null) {
Instances overlay = createOverlayForecastData(forecaster,
m_trainingData, i, m_horizon);
forecast = ((OverlayForecaster) forecaster).forecast(m_horizon,
overlay, progress);
}
} else {
forecast = forecaster.forecast(m_horizon, progress);
}
updateEvalModules(m_predictionsForTrainingData,
m_metricsForTrainingData, forecast, i, m_trainingData);
// remove the oldest prime instance and add this one
if (m_primeWindowSize > 0 && current != null) {
primeData.remove(0);
primeData.add(current);
primeData.compactify();
}
}
}
}
if (m_trainingData != null && m_forecastFuture
/* && !m_evaluateTrainingData */) {
// generate a forecast beyond the end of the training data
for (PrintStream p : progress) {
p.println("Generating future forecast for training data...");
}
Instances primeData = new Instances(m_trainingData,
m_trainingData.numInstances() - m_primeWindowSize, m_primeWindowSize);
forecaster.primeForecaster(primeData);
// if overlay data is being used then the only way we can make a forecast
// beyond the end of the training data is if we have a held-out test set
// to
// use for the "future" overlay fields values
if (forecaster instanceof OverlayForecaster
&& ((OverlayForecaster) forecaster).isUsingOverlayData()) {
if (m_testData != null) {
Instances overlay = createOverlayForecastData(forecaster, m_testData,
0, m_horizon);
m_trainingFuture = ((OverlayForecaster) forecaster).forecast(
m_horizon, overlay, progress);
} else {
// print an error message
for (PrintStream p : progress) {
p.println("WARNING: Unable to generate a future forecast beyond the end "
+ "of the training data because there is no future overlay "
+ "data available.");
}
}
} else {
m_trainingFuture = forecaster.forecast(m_horizon);
}
}
if (m_evaluateTestData) {
for (PrintStream p : progress) {
p.println("Evaluating on test set...");
}
// set up training set prediction and eval modules
m_predictionsForTestData = new ArrayList<ErrorModule>();
m_metricsForTestData = new HashMap<String, List<TSEvalModule>>();
setupEvalModules(m_predictionsForTestData, m_metricsForTestData,
AbstractForecaster.stringToList(forecaster.getFieldsToForecast()));
Instances primeData = null;
Instances rebuildData = null;
if (m_trainingData != null) {
primeData = new Instances(m_trainingData, 0);
if (forecaster instanceof TSLagUser) {
// initialize the artificial time stamp value (if in use)
if (((TSLagUser) forecaster).getTSLagMaker()
.isUsingAnArtificialTimeIndex()) {
((TSLagUser) forecaster).getTSLagMaker()
.setArtificialTimeStartValue(m_trainingData.numInstances());
}
}
if (m_rebuildModelAfterEachTestForecastStep) {
rebuildData = new Instances(m_trainingData);
}
} else {
primeData = new Instances(m_testData, 0);
}
int predictionOffsetForTestData = 0;
if (m_trainingData == null || m_primeForTestDataWithTestData) {
if (m_primeWindowSize >= m_testData.numInstances()) {
throw new Exception("The test data needs to have at least as many "
+ "instances as the the priming window size!");
}
predictionOffsetForTestData = m_primeWindowSize;
if (predictionOffsetForTestData >= m_testData.numInstances()) {
throw new Exception(
"Priming using test data requires more instances "
+ "than are available in the test data!");
}
primeData = new Instances(m_testData, 0, m_primeWindowSize);
if (forecaster instanceof TSLagUser) {
if (((TSLagUser) forecaster).getTSLagMaker()
.isUsingAnArtificialTimeIndex()) {
double artificialTimeStampStart = 0;
if (m_primeForTestDataWithTestData) {
if (m_trainingData == null) {
artificialTimeStampStart = ((TSLagUser) forecaster)
.getTSLagMaker().getArtificialTimeStartValue();
artificialTimeStampStart += m_primeWindowSize;
((TSLagUser) forecaster).getTSLagMaker()
.setArtificialTimeStartValue(artificialTimeStampStart);
} else {
((TSLagUser) forecaster).getTSLagMaker()
.setArtificialTimeStartValue(
m_trainingData.numInstances() + m_primeWindowSize);
}
}
}
}
} else {
// use the last primeWindowSize instances from the training
// data to prime with
predictionOffsetForTestData = 0;
primeData = new Instances(m_trainingData,
(m_trainingData.numInstances() - m_primeWindowSize),
m_primeWindowSize);
}
for (int i = predictionOffsetForTestData; i < m_testData.numInstances(); i++) {
Instance current = m_testData.instance(i);
if (m_primeWindowSize > 0) {
forecaster.primeForecaster(primeData);
}
if (i % 10 == 0) {