AIToolbox
A library that offers tools for AI problem solving.
|
Go to the documentation of this file. 1 #ifndef AI_TOOLBOX_FACTORED_BANDIT_GRAPH_UTILS_HEADER_FILE
2 #define AI_TOOLBOX_FACTORED_BANDIT_GRAPH_UTILS_HEADER_FILE
39 template <
typename Maximizer,
typename Data>
45 template <
typename Maximizer,
typename Data>
63 template <
typename Maximizer>
65 template <
typename Data,
typename... Args>
84 template <
typename Maximizer>
86 template <
typename Data,
typename... Args>
87 void operator()(
typename Maximizer::Graph & graph,
const Data & d, Args && ...args) {
100 template <
typename Data>
107 template <QFRuleRange Iterable>
112 graph.
reset(A.size());
114 for (
const auto & rule : inputRules) {
115 auto & factorNode = graph.
getFactor(rule.action.first)->getData();
118 const auto it = std::lower_bound(
119 std::begin(factorNode), std::end(factorNode),
id,
120 [](
const auto & rule,
size_t rhs) {
return rule.first < rhs;}
123 if (it != std::end(factorNode) && it->first ==
id)
124 it->second.first += rule.value;
126 factorNode.emplace(it,
id,
VE::Factor{rule.value, {}});
136 graph.
reset(A.size());
138 for (
const auto & basis : qf.
bases) {
139 const auto Ai =
static_cast<size_t>(basis.values.size());
141 auto & factorNode = graph.
getFactor(basis.tag)->getData();
143 if (factorNode.empty()) {
144 factorNode.reserve(Ai);
145 for (
size_t ai = 0; ai < Ai; ++ai)
146 factorNode.emplace_back(ai,
VE::Factor{0.0, {}});
149 for (
size_t ai = 0; ai < Ai; ++ai)
150 factorNode[ai].second.first += basis.values(ai);
159 template <QFRuleRange Iterable>
164 for (
const auto & rule : inputRules) {
165 auto & factorNode = graph.
getFactor(rule.action.first)->getData();
167 if (!factorNode.size())
179 for (
const auto & basis : qf.
bases) {
180 auto & factorNode = graph.
getFactor(basis.tag)->getData();
182 if (!factorNode.size())
183 factorNode.resize(basis.values.size());
190 template <QFRuleRange Iterable>
193 for (
auto & f : graph)
194 f.getData().setZero();
196 for (
const auto & rule : inputRules) {
197 auto & factorNode = graph.getFactor(rule.action.first)->getData();
200 factorNode[id] += rule.value;
208 for (
auto & f : graph)
209 f.getData().setZero();
211 for (
const auto & basis : qf.
bases)
212 graph.getFactor(basis.tag)->getData() += basis.values;