Implemented class ADDVerifier#728
Open
unfadingDawn wants to merge 4 commits into
Open
Conversation
c1bc49a to
cb1e34f
Compare
cb1e34f to
63294a0
Compare
py-cyber
requested changes
May 30, 2026
py-cyber
left a comment
Collaborator
There was a problem hiding this comment.
That's enough for now, maybe I'll look again later
| @@ -0,0 +1,91 @@ | |||
| #include "core/algorithms/dd/add_verifier/add_verifier.h" | |||
|
|
|||
| #include "core/algorithms/dd/dd_verifier/dd_verifier.h" | |||
Collaborator
There was a problem hiding this comment.
Its does not suppose to be here because u have it in header. I write it only because i want u to fix CMakeLists.txt (read about PUBLIC in wiki)
| void CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const &lhs); | ||
| virtual void CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs); | ||
|
|
||
| void VerifyDD(); |
Collaborator
There was a problem hiding this comment.
why didn't this virtual?
Comment on lines
+29
to
+30
| void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) { | ||
| double min_dist = -1.; |
Collaborator
There was a problem hiding this comment.
Suggested change
| void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) { | |
| double min_dist = -1.; | |
| void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) { | |
| if (lhs.empty()) { | |
| error_ = 0.0; // or 1.0 idk | |
| return; | |
| } | |
| double min_dist = -1.; |
Comment on lines
+71
to
+89
| void ADDVerifier::CheckCorrectnessDd() const { | ||
| auto check_constraint = [](auto const& constraint) { | ||
| if (constraint.constraint.upper_bound < constraint.constraint.lower_bound) { | ||
| throw std::invalid_argument("Invalid constraint bounds for column: " + | ||
| constraint.column_name); | ||
| } | ||
| if (constraint.constraint.lower_bound < 0 || constraint.constraint.upper_bound < 0) { | ||
| throw std::invalid_argument("Constraint bounds cannot be negative for column: " + | ||
| constraint.column_name); | ||
| } | ||
| }; | ||
|
|
||
| std::ranges::for_each(dd_.left, check_constraint); | ||
| std::ranges::for_each(dd_.right, check_constraint); | ||
| if (dd_.right.size() > 1) { | ||
| throw std::invalid_argument( | ||
| "The RHS of an ADD must have a differential function on a single attribute."); | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
i suggest do all exceptions in begins of methods so it will not waste time
Comment on lines
+29
to
+42
| void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) { | ||
| double min_dist = -1.; | ||
| for (auto const& pair : lhs) { | ||
| auto curr_constraint = dd_.right.cbegin(); | ||
| for (auto const column_index : rhs_column_indices_) { | ||
| double const dif = CalculateDistance(column_index, pair); | ||
| if (!curr_constraint->constraint.Contains(dif)) { | ||
| highlights_.emplace_back(column_index, pair, dif); | ||
| ++num_error_rhs_; | ||
| } | ||
| min_dist = min_dist == -1 ? dif : std::min(min_dist, dif); | ||
| ++curr_constraint; | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
i believe -O3 optimize this but probably u should change
Suggested change
| void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) { | |
| double min_dist = -1.; | |
| for (auto const& pair : lhs) { | |
| auto curr_constraint = dd_.right.cbegin(); | |
| for (auto const column_index : rhs_column_indices_) { | |
| double const dif = CalculateDistance(column_index, pair); | |
| if (!curr_constraint->constraint.Contains(dif)) { | |
| highlights_.emplace_back(column_index, pair, dif); | |
| ++num_error_rhs_; | |
| } | |
| min_dist = min_dist == -1 ? dif : std::min(min_dist, dif); | |
| ++curr_constraint; | |
| } | |
| } | |
| void ADDVerifier::CheckDFOnRhs(std::vector<std::pair<std::size_t, std::size_t>> const& lhs) { | |
| double min_dist = std::numeric_limits<double>::max(); | |
| for (auto const& pair : lhs) { | |
| auto curr_constraint = dd_.right.cbegin(); | |
| for (auto const column_index : rhs_column_indices_) { | |
| double const dif = CalculateDistance(column_index, pair); | |
| if (!curr_constraint->constraint.Contains(dif)) { | |
| highlights_.emplace_back(column_index, pair, dif); | |
| ++num_error_rhs_; | |
| } | |
| min_dist = std::min(min_dist, dif); | |
| ++curr_constraint; | |
| } | |
| } |
| auto curr_constraint = dd_.right.cbegin(); | ||
| for (auto const column_index : rhs_column_indices_) { | ||
| double const dif = CalculateDistance(column_index, pair); | ||
| if (dif == min_dist) { |
Collaborator
There was a problem hiding this comment.
i don't know about that, we should compare double like (dif - min_dist < epsilon)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implemented class ADDVerifier.
Implemented tests and Python bindings for this class.
Implemented code of the ADD validation example on Python.