AIToolbox
A library that offers tools for AI problem solving.
UCVE.hpp
Go to the documentation of this file.
1 #ifndef AI_TOOLBOX_FACTORED_BANDIT_UCVE_HEADER_FILE
2 #define AI_TOOLBOX_FACTORED_BANDIT_UCVE_HEADER_FILE
3 
6 
28  class UCVE {
29  public:
30  // Estimated mean and inverse weighted counts
31  using V = Eigen::Vector2d;
32  // Tag - Vector pair
33  struct Entry {
34  V v;
36  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
37  };
38  using Factor = std::vector<Entry>;
39 
40  using Result = std::tuple<Action, V>;
42 
53  template <typename Iterable>
54  Result operator()(const Action & A, const double logtA, const Iterable & inputRules) {
55  GVE::Graph graph(A.size());
56 
57  for (const Entry & rule : inputRules) {
58  const auto & [v, a] = rule;
59  auto & factorNode = graph.getFactor(a.first)->getData();
60  const auto id = toIndexPartial(A, a);
61 
62  const auto it = std::lower_bound(
63  std::begin(factorNode),
64  std::end(factorNode),
65  id,
66  [](const auto & rule, size_t rhs) {return rule.first < rhs;}
67  );
68 
69  if (it != std::end(factorNode) && it->first == id)
70  it->second[0].v += v;
71  else
72  factorNode.emplace(it, id, Factor{{v, PartialAction()}});
73  }
74  // Start solving process.
75  return (*this)(A, logtA, graph);
76  }
77 
87  Result operator()(const Action & A, const double logtA, GVE::Graph & graph);
88  };
89 }
90 
91 #endif
AIToolbox::Factored::Bandit::UCVE::V
Eigen::Vector2d V
Definition: UCVE.hpp:31
AIToolbox::Factored::Bandit::UCVE
This class represents the UCVE process.
Definition: UCVE.hpp:28
AIToolbox::Factored::Bandit::UCVE::Factor
std::vector< Entry > Factor
Definition: UCVE.hpp:38
GenericVariableElimination.hpp
Types.hpp
AIToolbox::Factored::Bandit::UCVE::Entry::v
V v
Definition: UCVE.hpp:34
AIToolbox::Factored::toIndexPartial
size_t toIndexPartial(const PartialKeys &ids, const Factors &space, const Factors &f)
This function converts the input factor in the input space to an unique index.
AIToolbox::Factored::FactorGraph
This class offers a minimal interface to manager a factor graph.
Definition: FactorGraph.hpp:31
AIToolbox::Factored::PartialAction
PartialFactors PartialAction
Definition: Types.hpp:70
AIToolbox::Factored::GenericVariableElimination
This class represents the Variable Elimination algorithm.
Definition: GenericVariableElimination.hpp:72
AIToolbox::Factored::Bandit::UCVE::Result
std::tuple< Action, V > Result
Definition: UCVE.hpp:40
AIToolbox::Factored::Bandit::UCVE::Entry
Definition: UCVE.hpp:33
AIToolbox::Factored::FactorGraph::getFactor
FactorIt getFactor(const Variables &variables)
This function returns an iterator to a factor adjacent to the given variables.
Definition: FactorGraph.hpp:355
AIToolbox::Factored::GenericVariableElimination::Graph
FactorGraph< Rules > Graph
Definition: GenericVariableElimination.hpp:76
AIToolbox::Factored::Action
Factors Action
Definition: Types.hpp:69
AIToolbox::Factored::Bandit::UCVE::Entry::tag
PartialAction tag
Definition: UCVE.hpp:35
AIToolbox::Factored::Bandit::UCVE::operator()
Result operator()(const Action &A, const double logtA, const Iterable &inputRules)
This function is the entry point for the solving process.
Definition: UCVE.hpp:54
AIToolbox::Factored::Bandit
Definition: GraphUtils.hpp:12