% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/infer.R
\name{infer}
\alias{infer}
\title{Perform Mamdani or implicative fuzzy inference with given rule-base on given
dataset}
\usage{
infer(
  x,
  rules,
  partition,
  alg = c("goedel", "goguen", "lukasiewicz"),
  type = c("mamdani", "implicative"),
  parallel = FALSE
)
}
\arguments{
\item{x}{Input to the inference. It must be a numeric matrix with columns
representing fuzzy sets (truth values of predicates). Each row represents a
single case of inference. Columns should be named after predicates in rules'
antecedents. The values must be in the interval \eqn{[0, 1]}. \code{x} can also be
an object of class \code{\link[=fsets]{fsets()}} (e.g., created by using the \code{\link[=fcut]{fcut()}} or \code{\link[=lcut]{lcut()}}
functions).}

\item{rules}{A rule-base (a.k.a. linguistic description) either in the form
of the \code{\link[=farules]{farules()}} object or as a list of character vectors where
each element is a fuzzy set name (a predicate) and thus each such vector
forms a rule. The first element of each rule is the consequent predicate,
and the remaining elements are antecedent predicates.}

\item{partition}{A numeric matrix (or a \code{\link[=fsets]{fsets()}} object) with columns that
are consequents in \code{rules}. The column names of \code{partition} must correspond
to consequent predicate names used in \code{rules}. Each row represents a point in the
output domain.}

\item{alg}{The algebra to use for the inference. It can be either a character
string (\code{"goedel"}, \code{"goguen"}, or \code{"lukasiewicz"}) or an instance of the
\code{\link[=algebra]{algebra()}} class.}

\item{type}{The type of inference to use. It can be either \code{"mamdani"} or
\code{"implicative"}.}

\item{parallel}{Whether the processing should be run in parallel or not.
Parallelization is implemented using the \code{\link[foreach:foreach]{foreach::foreach()}}
package. The parallel environment must be set properly in advance, e.g., with
the \code{\link[doMC:registerDoMC]{doMC::registerDoMC()}} function.}
}
\value{
A numeric matrix of inferred membership degrees. The rows of the
result correspond to rows of the \code{x} argument, the columns of the result
correspond to rows of the \code{partition} argument.
}
\description{
Take a set of rules (a rule-base) and perform Mamdani or implicative
inference on each row of a given matrix (or the \code{\link[=fsets]{fsets()}} object) of truth
values.
}
\details{
Perform Mamdani or implicative fuzzy inference with given rule-base \code{rules}
on each row of input \code{x}. Columns of \code{x} are truth values of predicates that
appear in the antecedent part of \code{rules}. The \code{partition} matrix determines
the shape of predicates in consequents: each row represents a point in the
output fuzzy set for which membership degrees are computed.

For both inference types, the predicates in the antecedent part of rules are
combined using a t-norm (\code{alg$pt}) of the given algebra \code{alg} (see also the
\code{fire()} function).

For the Mamdani inference (\code{type = "mamdani"}), the antecedent firing
degrees are combined with the consequent partition using a t-norm (\code{alg$pt})
of the selected algebra \code{alg}, and the resulting fuzzy sets are aggregated
with a t-conorm (\code{alg$ps}).

For the implicative inference (\code{type = "implicative"}), the antecedent
firing degrees are combined with the consequent partition using a residuum
(\code{alg$r}) of the selected algebra \code{alg}, and the resulting fuzzy sets are
aggregated with a t-norm (\code{alg$pi}).
}
\examples{
# Create rules: first element is the consequent, the rest are antecedents
rules <- list(
    c("High",   "temp_high",   "pressure_high"),
    c("Medium", "temp_medium", "pressure_medium"),
    c("Low",    "temp_low")
)

# Create input data (fuzzy set membership degrees)
# (Alternatively, fcut() or lcut() functions can be used)
x <- matrix(
    c(0.9, 0.8, 0.2, 0.3, 0.1,
      0.1, 0.2, 0.4, 0.5, 0.8),
    nrow = 2,
    byrow = TRUE
)
colnames(x) <- c("temp_high", "pressure_high",
                  "temp_medium", "pressure_medium", "temp_low")

# Create output partition
# (Alternatively, fcut() or lcut() functions can be used)
partition <- matrix(
    c(1.0, 0.2, 0.0,
      0.8, 0.5, 0.1,
      0.4, 1.0, 0.4,
      0.1, 0.5, 0.8,
      0.0, 0.1, 1.0),
    nrow = 5,
    byrow = TRUE
)
colnames(partition) <- c("Low", "Medium", "High")

# Mamdani inference with Goedel algebra
infer(x, rules, partition, alg = "goedel", type = "mamdani")

# Implicative inference with Lukasiewicz algebra
infer(x, rules, partition, alg = "lukasiewicz", type = "implicative")

}
\seealso{
\code{\link[=pbld]{pbld()}}, \code{\link[=fire]{fire()}}, \code{\link[=aggregateConsequents]{aggregateConsequents()}}, \code{\link[=defuzz]{defuzz()}}, \code{\link[=algebra]{algebra()}}, \code{\link[=farules]{farules()}}, \code{\link[=lcut]{lcut()}}
}
\author{
Michal Burda
}
\keyword{models}
\keyword{robust}
