#ifndef MLPOBJECTIVES_HPP_ #define MLPOBJECTIVES_HPP_ #include #include using namespace std; #include "Objectives.hpp" /** MLP Objective types or "kinds" that we aim to support. These are * modeled as a bit field to support combinations via logical * operators. */ namespace okind{ enum MlpObjKind : int { None = 0, cwmse = 1<<1, cwmee = 1<<2, cwmae = 1<<3, cwerr = 1<<4, mse = 1<<5, mee = 1<<6, mae = 1<<7, err = 1<<8, mincwmse= 1<<9, mincwmee= 1<<10, mincwmae= 1<<11, mincwe= 1<<12, msw = 1<<13, mswnb = 1<<14, maw = 1<<15, mawnb = 1<<16, nhid = 1<<17, nnzw = 1<<18, ninput= 1<<19, vsmse = 1<<20, vsmee = 1<<21, vsmae = 1<<22, vserr = 1<<23, }; } using okind::MlpObjKind; /* Operators for the MLP objective types. */ inline MlpObjKind operator|(MlpObjKind a, MlpObjKind b){ return static_cast(static_cast(a) | static_cast(b));} inline MlpObjKind operator&(MlpObjKind a, MlpObjKind b){ return static_cast(static_cast(a) & static_cast(b));} /* ... took the above from * http://stackoverflow.com/questions/1448396/ */ namespace okind{ inline bool needsClasswiseEvaluation(MlpObjKind k){ return k & (cwmse|cwmee|cwmae|cwerr|mincwmse|mincwmee|mincwmae|mincwe); } } /** Return the mnemonic short string of an objective kind. */ string mnemonic(MlpObjKind k); /** * Objective functions for our MLP individuals. The objectives are * always in a specific order: Classwise data fitting measures first, * then layerwise measures, and then singular overall measures. * * TODO: Should this class be responsible also for evaluating the * objectives? It can combine evaluations of the many objectives into * a single run through the dataset, whereas a single objective would * not know about the others? Then, an MlpIndividual should know its * MlpObjectives.. Shouldn't be a problem? */ class MlpObjectives : public Objectives { protected: size_t _nobj; vector _objname; MlpObjKind _evokinds; protected: /** * Add an objective (or multiple class-wise objectives) if the * mnemonic is found in the list of strings */ void addKindIfInList(const vector & spl, MlpObjKind k, size_t nclasses); public: MlpObjectives() = delete; /** Create from a definition string. */ MlpObjectives(const string & defstr, size_t nclasses); virtual size_t nobj() const; virtual string name(size_t ind) const; MlpObjKind kinds() const; //virtual string symbol(size_t ind) const; }; #endif