Page MenuHomePhorge

No OneTemporary

Size
8 KB
Referenced Files
None
Subscribers
None
diff --git a/include/rosa/deluxe/CrossReliability.h b/include/rosa/deluxe/CrossReliability.h
index ef40c7b..c87c809 100644
--- a/include/rosa/deluxe/CrossReliability.h
+++ b/include/rosa/deluxe/CrossReliability.h
@@ -1,3 +1,245 @@
#pragma once
-///This file is temporarly for the functions CrossConfidence and CrossReliability
-///Todo: As soon as a Delux Reliabl Agent exist modify to this or add it to the Agent
\ No newline at end of file
+//===-- 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 <type_traits> //assert
+#include <vector>
+// for static methods
+#include <algorithm>
+#include <numeric>
+
+template <typename Type> 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<Type, Type>(Score, Reliability));
+ }
+ std::size_t getNumberOfPossibleScores() { return PossibleScores.size(); }
+
+protected:
+ Type crossReliabilityParameter = 1;
+
+private:
+ std::vector<std::pair<Type, Type> *>
+ PossibleScores; // first: Score second: Reliability or Confidence
+ //--------------------------------------------------------------------------------
+ // ReliableAgent
+public:
+ /// This is purely a testfunction
+ void makeReliability(double Method(std::vector<double> values));
+
+ std::vector<ReliableAgent *> 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<ReliableAgent *> SlaveAgents,
+ Type Method(std::vector<Type> 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<ReliableAgent *> SlaveAgents,
+ Type Method(std::vector<Type> 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<Type> values) {
+ static_assert(std::is_arithmetic<Type>::value); // sanitny check
+ return *std::min_element(values.begin(), values.end());
+ }
+ static Type AVERAGE(std::vector<Type> values) {
+ static_assert(std::is_arithmetic<Type>::value); // sanitny check
+ return std::accumulate(values.begin(), values.end(), 0.0) / values.size();
+ }
+ static Type DISJUNCTION(std::vector<Type> values) {
+ static_assert(std::is_arithmetic<Type>::value); // sanitny check
+ return *std::max_element(values.begin(), values.end());
+ }
+ //-------------------------------------------------------------------------------
+};
+
+template <typename Type> Type CrossReliabilityFunctionGetY(Type value) {
+ return value;
+}
+
+/*
+The following things are needed inside this method
+- getScore
+- crossReliabilityParameter
+- AbsuluteValue
+- CrossReliabilityFunctionGetY
+*/
+template <typename Type>
+inline Type ReliableAgent<Type>::CrossReliability(
+ ReliableAgent<Type> *mainAgent,
+ std::vector<ReliableAgent<Type> *> SlaveAgents,
+ Type Method(std::vector<Type> values)) {
+ static_assert(std::is_arithmetic<Type>::value); // sanitny check
+
+ Type crossReliabiability;
+ std::vector<Type> 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 <typename Type>
+inline Type ReliableAgent<Type>::CrossConfidence(
+ ReliableAgent *mainAgent, std::vector<ReliableAgent *> SlaveAgents,
+ Type Method(std::vector<Type> values), Type TheoreticalValue) {
+ Type crossReliabiability;
+
+ std::vector<Type> 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 <typename Type>
+inline void ReliableAgent<Type>::makeReliability(
+ double Method(std::vector<double> 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<Type> *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 <iostream>
+
+int main(void)
+{
+ std::vector<ReliableAgent<double>* > Slaves;
+ std::size_t size=20;
+ for (std::size_t a = 0; a < size; a++)
+ {
+ auto tmp = new ReliableAgent<double>();
+ tmp->createPossibleScore(((double)a) / size, ((double)a)/size);
+ Slaves.push_back(tmp);
+ }
+
+ ReliableAgent<double> Master;
+ Master.Slaves.insert(Master.Slaves.begin(), Slaves.begin(),
+Slaves.end());
+
+ Master.makeReliability(ReliableAgent<double>::AVERAGE);
+
+
+
+
+
+ //cleanup
+ for (auto tmp : Slaves)
+ delete tmp;
+ Slaves.clear();
+ Master.Slaves.clear();
+
+ return 0;
+}
+*/
\ No newline at end of file

File Metadata

Mime Type
text/x-diff
Expires
Sat, Mar 15, 12:03 PM (18 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
129080
Default Alt Text
(8 KB)

Event Timeline