Skip to content

Commit 7392624

Browse files
committed
adding some documentation
1 parent e99ee32 commit 7392624

23 files changed

+87
-20
lines changed

R/detect_boundary.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ detect_boundary_num <- function(x, eps = 1e-8, ...){
5858
}
5959

6060

61-
#' Detect viable domains for categorical variables
61+
#' Detect domains for categorical variables
6262
#'
63-
#' Detect viable domains for categorical variables
63+
#' Detect viable domains for categorical variables.
64+
#' A rule set may constrain a categorical variable to a subset of its values.
65+
#' `detect_boundary_cat()` finds the categories that are allowed by the rule set.
6466
#' @example ./examples/detect_boundary.R
6567
#' @param x [validate::validator()] object with rules
6668
#' @param as_df return result as data.frame (before 0.4.5)

R/detect_contradicting_if_rules.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
#' Detect infeasible if clauses
1+
#' Detect infeasible if rules
22
#'
3-
#' Detect if clauses that contradict each other. This is useful to detect if clauses that are not satistifable.
3+
#' Detect whether conditions in if-rules may generate contradictions. Strictly
4+
#' speaking these rules do not make the rule set infeasible but rather make
5+
#' the if-condition unsatisfiable. So semantically speaking these rules are
6+
#' contradicting, because the writer of the rule set did not have the intention
7+
#' to make the condition forbidden. See examples for more details.
48
#'
59
#' @param x A validator object.
610
#' @param ... Additional arguments passed to `detect_if_clauses`.

R/detect_fixed_variables.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Detect fixed variables
22
#'
3-
#' Detects variables that have a fixed value in the rule set.
3+
#' Detects variables that are constrained by the rule set to have one fixed value.
44
#' To simplify a rule set, these variables can be substituted with their value.
55
#' @example ./examples/detect_fixed_variables.R
66
#' @seealso [simplify_fixed_variables()]

R/feasible.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#' An infeasible rule set cannot be satisfied by any data because of internal
44
#' contradictions. This function checks whether the record-wise linear,
55
#' categorical and conditional rules in a rule set are consistent.
6+
#' Note that is it always wise to also check `detect_contradicting_if_rules()`.
67
#'
78
#' @example ./examples/feasible.R
89
#' @param x `validator` object with validation rules.
@@ -29,6 +30,11 @@ is_feasible <- function(x, ...){
2930
#' Make an infeasible system feasible, by removing the minimum (weighted) number of rules, such that the remaining
3031
#' rules are not conflicting.
3132
#' This function uses [detect_infeasible_rules()] for determining the rules to be removed.
33+
#' Note that this may not result in your desired system, because some rules may be more important.
34+
#' This can be mediated by supplying weights for the rules. Default weight is 1.
35+
#'
36+
#' Also `make_feasible()` does not check for contradictions in `if` rules, so it is wise to also check
37+
#' `detect_contradicting_if_rules()` after making the system feasible.
3238
#' @export
3339
#' @param x [validate::validator()] object with the validation rules.
3440
#' @param ... passed to [detect_infeasible_rules()]
@@ -71,7 +77,8 @@ detect_infeasible_rules <- function(x, weight = numeric(), ...){
7177
mr <- fix_cat_domain(mr)
7278

7379
nms <- mr |> sapply(\(x) x$rule)
74-
w_inf <- nms[grepl("^\\.domain.", nms)] |> sapply(\(x) Inf)
80+
# meaning: all rules that start with a dot are "hard rules"
81+
w_inf <- nms[grepl("^\\.", nms)] |> sapply(\(x) Inf)
7582
weight <- c(weight, w_inf)
7683

7784
is_equality <- sapply(mr, function(m){

R/mip_lpsolve.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#' @param rules mip rules
77
#' @param objective function
88
#' @param eps accuracy for equality/inequality
9+
#' @keywords internal
910
translate_mip_lp <- function( rules
1011
, objective=NULL
1112
, eps = 1e-3

R/redundancy.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#' Detect redundant rules without removing.
1+
#' Detect redundant rules
22
#'
3-
#' Detect redundancies in a rule set.
3+
#' Detect redundancies in a rule set, but do not remove the rules.
4+
#' A rule in a ruleset can be redundant if it is implied by another rule
5+
#' or by a combination of rules. See the examples for more information.
46
#'
57
#' @note For removal of duplicate rules, simplify
68
#' @example ./examples/redundancy.R
@@ -28,7 +30,7 @@ detect_redundancy <- function(x, ...){
2830

2931
#' Remove redundant rules
3032
#'
31-
#' Simplify a rule set by removing redundant rules
33+
#' Simplify a rule set by removing redundant rules, i.e. rules that are implied by other rules.
3234
#' @export
3335
#' @example ./examples/redundancy.R
3436
#' @param x [validate::validator()] object with validation rules.

R/simplify_rules.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#' \item [remove_redundancy()]: remove redundant rules.
1010
#' }
1111
#' For more control, these methods can be called separately.
12+
#'
13+
#' Note that it is wise to call [detect_contradicting_if_rules()]
14+
#' before calling this function.
1215
#' @example ./examples/simplify_rules.R
1316
#' @export
1417
#' @param .x [validate::validator()] object with the rules to be simplified.

R/soft-rule.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ eps_min <- suffix("_eps_min")
4141
#' @param values named list of values.
4242
#' @param weights named numeric of equal length as values.
4343
#' @param ... not used
44+
#' @keywords internal
4445
expect_values <- function(values, weights, ...){
4546
if (missing(weights)){
4647
weights <- rep(1, length(values))

R/substitute_values.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ NULL
44

55
#' substitute a value in a rule set
66
#'
7-
#' Substitute values into expression, thereby simplifying the rule set.
7+
#' Substitute values / fill in a value for one ore more variables, thereby
8+
#' simplifying the rule set.
89
#' Rules that evaluate to TRUE because of the substitution are removed.
910
#' @example ./examples/substitute_values.R
1011
#' @param .x `validator` object with rules

R/validatetools-package.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#'
1414
#' \itemize{
1515
#' \item [is_infeasible()] checks a rule set for feasibility. An infeasible system must be corrected to be useful.
16+
#' \item [detect_infeasible_rules()] detects which rules cause infeasibility.
17+
#' \item [detect_contradicting_if_rules()] detects which `if` rules are conflicting.
1618
#' \item [detect_boundary_num()] shows for each numerical variable the allowed range of values.
1719
#' \item [detect_boundary_cat()] shows for each categorical variable the allowed range of values.
1820
#' \item [detect_fixed_variables()] shows variables whose value is fixated by the rule set.

0 commit comments

Comments
 (0)