Skip to content

Commit

Permalink
Adding constrain model
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Nov 3, 2023
1 parent eecdcd8 commit 36e0410
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
50 changes: 50 additions & 0 deletions include/barry/models/defm/counters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,56 @@ inline void rules_dont_become_zero(
return;
}

/**
* @brief Overall functional gains
* @param support Support of a model.
* @param pos Position of the focal statistic.
* @param lb Lower bound
* @param ub Upper bound
* @details
* @return (void) adds a rule limiting the support of the model.
*/
inline void rule_constrain_support(
DEFMSupport * support,
size_t pos,
double lb,
double ub
)
{

DEFM_RULEDYN_LAMBDA(tmp_rule)
{

if (data() < data.lb)
return false;
else if (data() > data.ub)
return false;
else
return true;

};


support->get_rules_dyn()->add_rule(
tmp_rule,
DEFMRuleDynData(
support->get_current_stats(),
pos, lb, ub
),
support->get_counters()->get_names()[pos] +
"' within [" + std::to_string(lb) + ", " +
std::to_string(ub) + std::string("]"),
std::string("When the support is ennumerated, only states where the statistic '") +
support->get_counters()->get_names()[pos] +
std::to_string(pos) + "' falls within [" + std::to_string(lb) + ", " +
std::to_string(ub) + "] are included."
);

return;

}


///@}

///@}
Expand Down
18 changes: 13 additions & 5 deletions include/barry/models/defm/defm-types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,26 @@ inline void DEFMData::print() const {
*/
///@{

class DEFMRuleDynData : public DEFMRuleData {
class DEFMRuleDynData {
public:
const std::vector< double > * counts;
size_t pos;
size_t lb;
size_t ub;

DEFMRuleDynData(
const std::vector< double > * counts_,
std::vector< double > numbers_ = {},
std::vector< size_t > indices_ = {},
std::vector< bool > logical_ = {}
) : DEFMRuleData(numbers_, indices_, logical_), counts(counts_) {};
size_t pos_,
size_t lb_,
size_t ub_
) : counts(counts_), pos(pos_), lb(lb_), ub(ub_) {};

~DEFMRuleDynData() {};

const double operator()() const
{
return (*counts)[pos];
}

};

Expand Down

0 comments on commit 36e0410

Please sign in to comment.