diff --git a/include/rosa/deluxe/CrossReliability.h b/include/rosa/deluxe/CrossReliability.h index c87c809..8d34ffd 100644 --- a/include/rosa/deluxe/CrossReliability.h +++ b/include/rosa/deluxe/CrossReliability.h @@ -1,245 +1,246 @@ #pragma once //===-- rosa/delux/CrossReliability.h ---------------------------*- C++ -*-===// // // The RoSA Framework // //===----------------------------------------------------------------------===// /// /// \file rosa/delux/CrossReliability.h /// /// \author Daniel Schnoell /// /// \date 2019 /// /// \brief This file is temporarly for the functions/methods CrossConfidence and /// CrossReliability. /// \todo As soon as a Delux Reliabl Agent exist modify to this or add it to the /// Agent. /// \note This file includes things that are just to make the relationships /// clearer of the methods/functions //===----------------------------------------------------------------------===// // nedded headers #include //assert #include // for static methods #include #include template class ReliableAgent { //------------------------------------------------------------------------------ // Reliability or Confidence public: // at=0 should be the most reliable score Type getReliability(std::size_t at) { return PossibleScores.at(at)->second; } void setReliability(std::size_t at, Type Reliability) { this->Reliability = PossibleScores.at(at)->second; } Type getScore(std::size_t at) { return PossibleScores.at(at)->first; } void setScore(std::size_t at, Type Score) { this->Reliability = PossibleScores.at(at)->first; } void createPossibleScore(Type Score, Type Reliability) { PossibleScores.push_back(new std::pair(Score, Reliability)); } std::size_t getNumberOfPossibleScores() { return PossibleScores.size(); } protected: Type crossReliabilityParameter = 1; private: std::vector *> PossibleScores; // first: Score second: Reliability or Confidence //-------------------------------------------------------------------------------- // ReliableAgent public: /// This is purely a testfunction void makeReliability(double Method(std::vector values)); std::vector Slaves; ReliableAgent *Master; private: //-------------------------------------------------------------------------------- // Relevvant methods /// Calculets the CrossReliability /// \param mainagent pointer of the relevant SlaveAgent /// \param SlaveAgents pointers to all Slave Agents of the /// \note all the given Agents need to have at least 1 possibleScore /// \param Method a function pointer to the used combination method Type CrossReliability(ReliableAgent *MainAgent, std::vector SlaveAgents, Type Method(std::vector values)); /// Calculets the CrossReliability /// \param mainagent pointer of the relevant SlaveAgent /// \param SlaveAgents pointers to all Slave Agents of the /// \note all the given Agents need to have at least 1 possibleScore /// \param Method a function pointer to the used combination method /// \param TheoreticalValue uses this value instead of the MainAgents score /// needed for playing "what if" Type CrossConfidence(ReliableAgent *mainAgent, std::vector SlaveAgents, Type Method(std::vector values), Type TheoreticalValue); //-------------------------------------------------------------------------------- // helper functions Type AbsuluteValue(Type A, Type B) { return ((A - B) < 0) ? B - A : A - B; } //-------------------------------------------------------------------------------- // pre defined combination methods public: static Type CONJUNCTION(std::vector values) { static_assert(std::is_arithmetic::value); // sanitny check return *std::min_element(values.begin(), values.end()); } static Type AVERAGE(std::vector values) { static_assert(std::is_arithmetic::value); // sanitny check return std::accumulate(values.begin(), values.end(), 0.0) / values.size(); } static Type DISJUNCTION(std::vector values) { static_assert(std::is_arithmetic::value); // sanitny check return *std::max_element(values.begin(), values.end()); } //------------------------------------------------------------------------------- }; +/// This would be an Function block and should be costomizable for each agent-agent "cross" template Type CrossReliabilityFunctionGetY(Type value) { return value; } /* The following things are needed inside this method - getScore - crossReliabilityParameter - AbsuluteValue - CrossReliabilityFunctionGetY */ template inline Type ReliableAgent::CrossReliability( ReliableAgent *mainAgent, std::vector *> SlaveAgents, Type Method(std::vector values)) { static_assert(std::is_arithmetic::value); // sanitny check Type crossReliabiability; std::vector values; for (ReliableAgent *SlaveAgent : SlaveAgents) { if (SlaveAgent == mainAgent) continue; if (mainAgent->getScore(0) == SlaveAgent->getScore(0)) crossReliabiability = 1; else crossReliabiability = 1 / (crossReliabilityParameter * AbsuluteValue(mainAgent->getScore(0), SlaveAgent->getScore(0))); // profile reliability Type crossReliabilityFromProfile = CrossReliabilityFunctionGetY( AbsuluteValue(mainAgent->getScore(0), SlaveAgent->getScore(0))); values.push_back( std::max(crossReliabiability, crossReliabilityFromProfile)); } return Method(values); } /* The following things are needed inside this method - getScore - crossReliabilityParameter - AbsuluteValue - CrossReliabilityFunctionGetY */ template inline Type ReliableAgent::CrossConfidence( ReliableAgent *mainAgent, std::vector SlaveAgents, Type Method(std::vector values), Type TheoreticalValue) { Type crossReliabiability; std::vector values; for (ReliableAgent *SlaveAgent : SlaveAgents) { if (SlaveAgent == mainAgent) continue; if (TheoreticalValue == SlaveAgent->getScore(0)) crossReliabiability = 1; else crossReliabiability = 1 / (crossReliabilityParameter * AbsuluteValue(TheoreticalValue, SlaveAgent->getScore(0))); // profile reliability Type crossReliabilityFromProfile = CrossReliabilityFunctionGetY( AbsuluteValue(TheoreticalValue, SlaveAgent->getScore(0))); values.push_back( std::max(crossReliabiability, crossReliabilityFromProfile)); } return Method(values); } // pure testmethod template inline void ReliableAgent::makeReliability( double Method(std::vector values)) { std::cout << "score" << "\tCR\t"; for (std::size_t tmp = 0; tmp < 10; tmp++) std::cout << "\t" << ((Type)tmp) / 10; std::cout << "\n"; for (ReliableAgent *mainagent : Slaves) { std::cout << mainagent->getScore(0) << "\t" // carefull not fale save << CrossReliability(mainagent, Slaves, Method) << "\t"; for (std::size_t tmp = 0; tmp < 10; tmp++) std::cout << "\t" << CrossConfidence(mainagent, Slaves, Method, ((Type)tmp) / 10); std::cout << "\n"; } } /* //test file include correct path #include int main(void) { std::vector* > Slaves; std::size_t size=20; for (std::size_t a = 0; a < size; a++) { auto tmp = new ReliableAgent(); tmp->createPossibleScore(((double)a) / size, ((double)a)/size); Slaves.push_back(tmp); } ReliableAgent Master; Master.Slaves.insert(Master.Slaves.begin(), Slaves.begin(), Slaves.end()); Master.makeReliability(ReliableAgent::AVERAGE); //cleanup for (auto tmp : Slaves) delete tmp; Slaves.clear(); Master.Slaves.clear(); return 0; } */ \ No newline at end of file