Learn R Programming

lfl (version 2.2.0)

fire: Evaluate rules and obtain truth-degrees

Description

Given truth degrees of predicates, compute the truth value of given list of rules.

Usage

fire(
  x,
  rules,
  tnorm = c("goedel", "goguen", "lukasiewicz"),
  onlyAnte = TRUE,
  parallel = FALSE
)

Value

If x is a matrix then the result of this function is a list of numeric vectors with truth values of each rule, i.e., each element of the resulting list corresponds to a rule and each value of the vector in the resulting list corresponds to a row of the original data matrix x.

x as a vector is treated as a single-row matrix.

Arguments

x

Truth degrees of predicates. x could be either a numeric matrix or a numeric vector. If vector is given then each named element represents a truth value of a predicate. If matrix is given then each row of the matrix is evaluated sequentially as a vector. The values must be in the interval \([0, 1]\).

rules

Either an object of S3 class farules() or a list of character vectors where each vector is a rule in a conjunctive form. Elements of these character vectors (i.e., predicate names) must correspond to the x's names (of elements resp. columns if x is a vector resp. matrix).

tnorm

A character string representing a triangular norm to be used (either "goedel", "goguen", or "lukasiewicz") or an arbitrary function that performs element-wise computation on arbitrary number of vector parameters similarly as e.g. pgoedel.tnorm(), pgoguen.tnorm() or plukas.tnorm().

onlyAnte

TRUE is useful if rules store both the antecedent and consequent and if only the antecedent-part of a rule should be included into the evaluated conjunction. Antecedent-part of a rule are all predicates in the vector starting from the 2nd position. TRUE value in this parameter causes the first element of each rule to be ignored.

If FALSE, all predicates in a rule will be included in the conjunction.

parallel

Deprecated parameter. Computation is done sequentially.

Author

Michal Burda

Details

The aim of this function is to compute the truth value of each rule in a rules list by assigning truth values to rule's predicates given by data x.

x is a numeric vector or numeric matrix of truth values of predicates. If x is vector then names(x) must correspond to the predicate names in rules. If x is a matrix then each column should represent a predicate and thus colnames(x) must correspond to predicate names in rules. Values of x are interpreted as truth values, i.e., they must be from the interval \([0, 1]\). If matrix is given, the resulting truth values are computed row-wisely.

rules may be a list of character vectors or an instance of the S3 class farules(). The character vectors in the rules list represent formulae in conjunctive form. If onlyAnte=FALSE, fire() treats the rule as a conjunction of all predicates, i.e., a conjunction of all predicates is computed. If onlyAnte=TRUE, the first element of each rule is removed prior evaluation, i.e., a conjunction of all predicates except the first are computed: this is useful if rules is a farules() object, since farules() objects save a rule's consequent as the first element (see also antecedents() and consequents() functions).

The type of conjunction to be computed can be specified with the tnorm parameter.

See Also

aggregateConsequents(), defuzz(), perceive(), pbld(), fcut(), lcut(), farules()

Examples

Run this code

# fire whole rules on a vector
x <- 1:10 / 10
names(x) <- letters[1:10]
rules <- list(c('a', 'c', 'e'),
              c('b'),
              c('d', 'a'),
              c('c', 'a', 'b'))
fire(x, rules, tnorm='goguen', onlyAnte=FALSE)

# fire antecedents of the rules on a matrix
x <- matrix(1:20 / 20, nrow=2)
colnames(x) <- letters[1:10]
rules <- list(c('a', 'c', 'e'),
              c('b'),
              c('d', 'a'),
              c('c', 'a', 'b'))
fire(x, rules, tnorm='goedel', onlyAnte=TRUE)

# the former command should be equal to
fire(x, antecedents(rules), tnorm='goedel', onlyAnte=FALSE)

Run the code above in your browser using DataLab