Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F386377
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Size
17 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/include/rosa/deluxe/CrossReliability.h b/include/rosa/deluxe/CrossReliability.h
index 8d34ffd..396e3c4 100644
--- a/include/rosa/deluxe/CrossReliability.h
+++ b/include/rosa/deluxe/CrossReliability.h
@@ -1,246 +1,240 @@
#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
+/// \todo there is 1 exception that needs to be handled correctly.
+/// \note the default search function is extremely slow maby this could be done
+/// via template for storage class and the functions/methods to efficiently find
+/// the correct LinearFunction
//===----------------------------------------------------------------------===//
// nedded headers
#include <type_traits> //assert
#include <vector>
// for static methods
#include <algorithm>
#include <numeric>
+#include <string>
-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;
- }
+// LinearFunction
+#include "rosa/agent/LinearFunctions.hpp"
- 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;
- }
+#include "CrossReliability_helper_file.h"
- void createPossibleScore(Type Score, Type Reliability) {
- PossibleScores.push_back(new std::pair<Type, Type>(Score, Reliability));
- }
- std::size_t getNumberOfPossibleScores() { return PossibleScores.size(); }
+template <typename Type> class CrossReliabilityModule {
-protected:
- Type crossReliabilityParameter = 1;
+ using LinearFunction = typename rosa::agent::LinearFunction<Type, Type>;
+ using ReliableAgent = typename ReliableAgent<Type>;
+
+ struct Functionblock {
+ bool exists = false;
+ std::string nameA;
+ std::string nameB;
+ LinearFunction *Funct;
+ };
-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));
+ /// adds a Function to the module
+ /// \param nameA
+ /// \param nameB these parameters have to be unique
+ /// \param Function should be uniquely owned by the Module and will be deleted
+ /// upon Deletion of the object
+ void addCrossReliabilityProfile(std::string nameA, std::string nameB,
+ LinearFunction *Function);
+ /// sets the cross Reliability Parameter
+ void setcrossReliabilityParameter(Type val) {
+ crossReliabilityParameter = val;
+ }
- std::vector<ReliableAgent *> Slaves;
- ReliableAgent *Master;
+ /// Deconstructor deletes all stored LinearFunctions !
+ ~CrossReliabilityModule() {
+ for (auto tmp : Functions)
+ delete tmp.Funct;
+ }
-private:
+protected:
//--------------------------------------------------------------------------------
// 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
+ /// \note im currently using getScore(0) this isn't correct maxi uses
+ /// getPossibleScoreCount() which returns possibleScoreCount.
+ /// possibleScoreCount isn't reset/set/inc inside or outside the use of this
+ /// function
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
-
+ /// evalues the absolute distance between two values
Type AbsuluteValue(Type A, Type B) { return ((A - B) < 0) ? B - A : A - B; }
+ /// evaluest the corisponding LinearFunction thith the score difference
+ /// \param nameA
+ /// \param nameB these two parameters are the unique identifiers
+ /// for the LinerFunction \note it doesn't matter if they are swapped
+ Type getCrossReliabilityFromProfile(std::string nameA, std::string nameB,
+ Type scoreDifference) {
+ Functionblock block = searchFunction(Functions, nameA, nameB);
+ if (!block.exists)
+ throw "does not exist"; // exceptions are disabled in rosa Todo : handle
+ // this right
+ return block.Funct->operator()(scoreDifference);
+ }
+
+ //--------------------------------------------------------------------------------
+ // stored Data
+
+ Type crossReliabilityParameter = 1;
+
+ /// this could be changed to use a template
+ /// template <typename Type , typename storagecontainer> class
+ /// CrossReliabilityModule [...]
+ /// storagecontainer<string,string,LinearFunction*> Functions;
+ std::vector<Functionblock> Functions;
+
+ /// verry inefficient searchFunction
+ Functionblock (*searchFunction)(std::vector<Functionblock> vect,
+ const std::string nameA,
+ const std::string nameB) =
+ [](std::vector<Functionblock> vect, const std::string nameA,
+ const std::string nameB) -> Functionblock {
+ for (Functionblock tmp : vect) {
+ if (tmp.nameA == nameA && tmp.nameB == nameB)
+ return tmp;
+ if (tmp.nameA == nameB && tmp.nameB == nameA)
+ return tmp;
+ }
+ return Functionblock();
+ };
+
//--------------------------------------------------------------------------------
// pre defined combination methods
public:
+ /// predefined combination method
static Type CONJUNCTION(std::vector<Type> values) {
static_assert(std::is_arithmetic<Type>::value); // sanitny check
return *std::min_element(values.begin(), values.end());
}
+
+ /// predefined combination method
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();
}
+
+ /// predefined combination method
static Type DISJUNCTION(std::vector<Type> values) {
static_assert(std::is_arithmetic<Type>::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 <typename Type> Type CrossReliabilityFunctionGetY(Type value) {
- return value;
+template <typename Type>
+inline void CrossReliabilityModule<Type>::addCrossReliabilityProfile(
+ std::string nameA, std::string nameB, LinearFunction *Function) {
+ Functions.push_back({true, nameA, nameB, Function});
}
/*
The following things are needed inside this method
- getScore
-- crossReliabilityParameter
-- AbsuluteValue
-- CrossReliabilityFunctionGetY
+- ReliableAgent
*/
template <typename Type>
-inline Type ReliableAgent<Type>::CrossReliability(
- ReliableAgent<Type> *mainAgent,
- std::vector<ReliableAgent<Type> *> SlaveAgents,
+inline Type CrossReliabilityModule<Type>::CrossReliability(
+ ReliableAgent *mainAgent, std::vector<ReliableAgent *> 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(
+ Type crossReliabilityFromProfile = getCrossReliabilityFromProfile(
+ mainAgent->getName(), SlaveAgent->getName(),
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
+- ReliableAgent
*/
template <typename Type>
-inline Type ReliableAgent<Type>::CrossConfidence(
+inline Type CrossReliabilityModule<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)));
+ Type crossReliabilityFromProfile = getCrossReliabilityFromProfile(
+ mainAgent->getName(), SlaveAgent->getName(),
+ AbsuluteValue(mainAgent->getScore(0), 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
diff --git a/include/rosa/deluxe/CrossReliability_helper_file.h b/include/rosa/deluxe/CrossReliability_helper_file.h
new file mode 100644
index 0000000..66bf5bd
--- /dev/null
+++ b/include/rosa/deluxe/CrossReliability_helper_file.h
@@ -0,0 +1,152 @@
+#pragma once
+//===-- rosa/delux/CrossReliability_helper_file.h ----------------*- C++
+//-*-===//
+//
+// The RoSA Framework
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file rosa/delux/CrossReliability_helper_file.h
+///
+/// \author Daniel Schnoell
+///
+/// \date 2019
+///
+/// \brief This file shouldn't exist when everything is finished. It is only a
+/// temporary part to hava all needed references and it also contains source
+/// code for test compiling
+//===----------------------------------------------------------------------===//
+
+#ifdef __fake__LinearFunction
+namespace rosa {
+namespace agent {
+template <typename A, typename B> class LinearFunction {
+public:
+ virtual A operator()(B val) = 0;
+};
+template <typename A, typename B>
+class testFunction : public LinearFunction<A, B> {
+public:
+ virtual A operator()(B val) { return val; }
+};
+} // namespace agent
+} // namespace rosa
+#endif
+
+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(); }
+ void setName(std::string nam) { Name = nam; }
+ std::string getName() { return Name; }
+
+protected:
+ Type crossReliabilityParameter = 1;
+
+private:
+ std::string Name;
+ std::vector<std::pair<Type, Type> *>
+ PossibleScores; // first: Score second: Reliability or Confidence
+ //--------------------------------------------------------------------------------
+ // ReliableAgent
+public:
+ std::vector<ReliableAgent *> Slaves;
+ ReliableAgent *Master;
+
+private:
+};
+
+/*
+//test file include correct path
+
+#define __fake__LinearFunction
+#include "CrossReliability.h"
+#include <iostream>
+
+class tester :public ReliableAgent<double>, public
+CrossReliabilityModule<double>
+{
+public:
+ // pure testmethod
+ void makeReliability(
+ double Method(std::vector<double> values)) {
+ std::cout << "score"
+ << "\tCR\t";
+ for (std::size_t tmp = 0; tmp < 10; tmp++)
+ std::cout << "\t" << ((double)tmp) / 10;
+ std::cout << "\n";
+ for ( auto 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,
+((double)tmp) / 10); std::cout << "\n";
+ }
+ }
+
+
+};
+
+int main(void)
+{
+ std::vector<tester* > Slaves;
+ std::size_t size = 20;
+ for (std::size_t a = 0; a < size; a++)
+ {
+ auto tmp = new tester();
+ tmp->createPossibleScore(((double)a) / size,
+ ((double)a) / size);
+ tmp->setName(std::to_string(a));
+ Slaves.push_back(tmp);
+ }
+
+ tester Master;
+ Master.Slaves.insert(Master.Slaves.begin(), Slaves.begin(),
+ Slaves.end());
+
+ for (std::size_t a = 0; a < size; a++)
+ {
+ for (std::size_t b = 0; b < size; b++)
+ {
+ Master.addCrossReliabilityProfile(std::to_string(a),
+std::to_string(b),new rosa::agent::testFunction<double,double>());
+ }
+ }
+
+ Master.makeReliability(tester::AVERAGE);
+
+
+
+
+
+ //cleanup
+ for (auto tmp : Slaves)
+ delete tmp;
+ Slaves.clear();
+ Master.Slaves.clear();
+
+ Master.~Master();
+
+ long q;
+ std::cin >> q;
+
+ return 0;
+}
+
+*/
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jul 3, 8:02 AM (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
157211
Default Alt Text
(17 KB)
Attached To
Mode
R20 SoC_Rosa_repo
Attached
Detach File
Event Timeline
Log In to Comment