#include "pipeline.h"


Pipeline::Pipeline(vector<TransformerABC*> transformers, ClassifierABC* classifier) {
    _transformers = transformers;
    _classifier = classifier;

}

void
Pipeline::_fit(const Matrix<data_t>& data, const vector<label_t>& targets) {
    _transformers[0]->fit(data, targets);
    Matrix<data_t> tdata = _transformers[0]->transform(data);
    for(size_t i = 1; i < _transformers.size(); i++) {
        _transformers[i]->fit(tdata, targets);
        tdata = _transformers[i]->transform(tdata);
    }
    _classifier->fit(tdata, targets);
}


vector<label_t>
Pipeline::_predict(const Matrix<data_t>& data) const {
    Matrix<data_t> tdata = _transformers[0]->transform(data);
    for(size_t i = 1; i < _transformers.size(); i++)
        tdata = _transformers[i]->transform(tdata);
    return _classifier->predict(tdata);
}


label_t
Pipeline::_predict(const vector<data_t>& sample) const {
    vector<data_t> tsample = _transformers[0]->transform(sample);
    for(size_t i = 1; i < _transformers.size(); i++)
        tsample = _transformers[i]->transform(tsample);

    return _classifier->predict(tsample);
}






