Skip to content

Commit

Permalink
Write a very clear docstring for _feature_space
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Jun 25, 2023
1 parent 6bdbd04 commit 52be1f9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 30 deletions.
45 changes: 43 additions & 2 deletions src/dependent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,50 @@ function _reduced_echelon_form(A::AbstractMatrix)
rref(A)
end

function _feature_space(rules::AbstractVector{Rule}, A::Split, B::Split)
"""
Return a binary space which can be used to determine whether rules are linearly dependent.
For example, for the conditions
- u: ≥ 3 & B ≥ 2 (U & V)
- v: A ≥ 3 & B < 2 (U & !V)
- w: A < 3 & B ≥ 2 (!U & V)
- x: A < 3 & B < 2 (!U & !V)
For example, given the following rules:
Rule 1: x[i, 1] < 32000
Rule 5: x[i, 3] < 64
Rule 7: x[i, 1] ≥ 32000 & x[i, 3] < 64
Rule 12: x[i, 1] < 32000 & x[i, 3] < 64
and the following clauses
A: x[i, 1] < 32000
B: x[i, 3] < 64
This function generates a matrix containing a row for
- A && B (x[i, 1] < 32000 & x[i, 3] < 64)
- A && !B (x[i, 1] < 32000 & x[i, 3] ≥ 64)
- !A && B (x[i, 1] ≥ 32000 & x[i, 3] < 64)
- !A && !B (x[i, 1] ≥ 32000 & x[i, 3] ≥ 64)
and one zeroes column:
| Condition | Ones | R1 | R5 | R7 | R12 |
| ---------- | ---- | -- | -- | -- | --- |
| A && B | 1 | 1 | 1 | 0 | 0 |
| A && !B | 1 | 1 | 0 | 0 | 0 |
| !A && B | 1 | 0 | 1 | 0 | 1 |
| !A && !B | 1 | 0 | 0 | 1 | 0 |
In other words, the matrix represents which rules are implied by each syntetic datapoint
(conditions in the rows).
"""
function _feature_space(rules::AbstractVector{Rule}, A::Split, B::Split)::BitMatrix
l = length(rules)
data = BitArray(undef, 4, l + 1)
data = BitMatrix(undef, 4, l + 1)
for i in 1:4
data[i, 1] = 1
end
Expand Down
30 changes: 2 additions & 28 deletions src/tmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ Return the following conditions:
"""
function _tmp_conditions(rules::Vector{Rule})
single_conditions = _tmp_single_conditions(rules)
double_conditions = _tmp_double_conditions(rules)
return union(single_conditions, double_conditions)
# double_conditions = _tmp_double_conditions(rules)
# return union(single_conditions, double_conditions)
end

"Return whether `clause1` implies `clause2`."
Expand Down Expand Up @@ -96,32 +96,6 @@ function _tmp_implies(condition1::TreePath, condition2::TreePath)::Bool
return all(covered)
end

"""
Return a binary matrix containing the rules (rows) and the clauses from the rules (columns).
This is done by adding a column for each separate clause including `A` if the set contains `A & B`.
And also adding a column for each conjunction (&).
For example, for the rule set
Rule 1: A < 3, then ...
Rule 2: B < 2, then ...
Rule 3: A ≥ 3 & B ≥ 2, then ...
Rule 4: A ≥ 3 & B < 2, then ...
returns the following matrix (with the headers as the `conditions` vector):
| ---- | A < 3 | A ≥ 3 | B < 2 | B ≥ 2 | A ≥ 3 & B ≥ 2 | A ≥ 3 & B < 2 |
| ---- | ----- | ----- | ----- | ----- | ------------- | ------------- |
| R1 | 1 | 0 | 0 | 0 | 0 | 0 |
| R2 | 0 | 0 | 1 | 0 | 0 | 0 |
| R3 | 0 | 1 | 0 | 1 | 1 | 0 |
| R4 | 0 | 1 | 1 | 0 | 0 | 1 |
In other words, the matrix represents which syntetic datapoints (constraints in columns)
are implied by each rule (rows).
Gaussian elimination needs to know only implications (=>).
"""
function _tmp_rule_space(rules::Vector{Rule})
conditions = collect(_tmp_conditions(rules))::Vector{TreePath}
space = falses(length(rules), length(conditions))
Expand Down

0 comments on commit 52be1f9

Please sign in to comment.