Example usage for weka.classifiers.timeseries AbstractForecaster primeForecaster

List of usage examples for weka.classifiers.timeseries AbstractForecaster primeForecaster

Introduction

In this page you can find the example usage for weka.classifiers.timeseries AbstractForecaster primeForecaster.

Prototype

public abstract void primeForecaster(Instances insts) throws Exception;

Source Link

Document

Supply the (potentially) trained model with enough historical data, up to and including the current time point, in order to produce a forecast.

Usage

From source file:adams.flow.transformer.WekaPrimeForecaster.java

License:Open Source License

/**
 * Executes the flow item.//from  www .ja  va 2s. c  om
 *
 * @return      null if everything is fine, otherwise error message
 */
@Override
protected String doExecute() {
    String result;
    Instances data;
    Instance inst;
    AbstractForecaster cls;

    result = null;

    try {
        cls = getForecasterInstance();
        if (cls == null)
            result = "Failed to obtain forecaster!";

        if (result == null) {
            if ((m_InputToken != null) && (m_InputToken.getPayload() instanceof Instances)) {
                data = (Instances) m_InputToken.getPayload();
                cls.primeForecaster(data);
                m_OutputToken = new Token(new WekaModelContainer(cls, new Instances(data, 0), data));
            } else if ((m_InputToken != null) && (m_InputToken.getPayload() instanceof Instance)) {
                inst = (Instance) m_InputToken.getPayload();
                data = inst.dataset();
                if (cls instanceof IncrementallyPrimeable) {
                    ((IncrementallyPrimeable) cls).primeForecasterIncremental(inst);
                    m_OutputToken = new Token(new WekaModelContainer(cls, new Instances(data, 0), data));
                } else {
                    result = m_Forecaster.getValue() + " (= " + cls.getClass().getName()
                            + ") does not implement " + IncrementallyPrimeable.class.getName()
                            + "! Cannot prime incrementally!";
                }
            }
        }
    } catch (Exception e) {
        m_OutputToken = null;
        result = handleException("Failed to process data:", e);
    }

    if (m_OutputToken != null)
        updateProvenance(m_OutputToken);

    return result;
}