24.09., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

ClassifierConfigurator.cpp 3.45 KB
Newer Older
Alessio Netti's avatar
Alessio Netti committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
//================================================================================
// Name        : ClassifierConfigurator.cpp
// Author      : Alessio Netti
// Contact     : info@dcdb.it
// Copyright   : Leibniz Supercomputing Centre
// Description :
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2019-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//================================================================================

#include "ClassifierConfigurator.h"

ClassifierConfigurator::ClassifierConfigurator() {
    _operatorName = "classifier";
    _baseName     = "sensor";
}

ClassifierConfigurator::~ClassifierConfigurator() {}

void ClassifierConfigurator::sensorBase(RegressorSensorBase& s, CFG_VAL config) {
    BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config)
    {
        if (boost::iequals(val.first, "target")) {
            s.setTrainingTarget(to_bool(val.second.data()));
            std::string opName = val.second.data();
        }
    }
}

void ClassifierConfigurator::operatorAttributes(ClassifierOperator& op, CFG_VAL config) {
    BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config)
    {
        if (boost::iequals(val.first, "trainingSamples"))
            op.setTrainingSamples(stoull(val.second.data()));
        else if(boost::iequals(val.first, "window"))
            op.setAggregationWindow(stoull(val.second.data()) * 1000000);
        else if(boost::iequals(val.first, "inputPath"))
            op.setInputPath(val.second.data());
        else if(boost::iequals(val.first, "outputPath"))
            op.setOutputPath(val.second.data());
        else if(boost::iequals(val.first, "getImportances"))
            op.setComputeImportances(to_bool(val.second.data()));
    }
}

bool ClassifierConfigurator::unit(UnitTemplate<RegressorSensorBase>& u) {
    if(u.isTopUnit()) {
        LOG(error) << "    " << _operatorName << ": This operator type only supports flat units!";
        return false;
    }
    bool targetSet=false;
    for(const auto& in : u.getInputs())
        if(in->getTrainingTarget()) {
            if(!targetSet)
                targetSet = true;
            else {
                LOG(error) << _operatorName << ": Only one classification target can be specified!";
                return false;
            }
        }
    if(!targetSet) {
        LOG(error) << "    " << _operatorName << ": No classification target was specified!";
        return false;
    }
    if(u.getOutputs().size()!=1) {
        LOG(error) << "    " << _operatorName << ": Only one output sensor per unit is allowed!";
        return false;
    }
    return true;
}