pub struct Rule {
pub antecedent: Antecedent,
pub consequent: Vec<Consequent>,
}Expand description
Full fuzzy rule pairing an antecedent with one or more consequents.
antecedentencodes the IF-part as an expression tree of atomic predicates combined with AND/OR/NOT using the default Min–Max family.consequentlists one or more THEN-part outputs; each is evaluated over its variable domain during implication.
Fields§
§antecedent: AntecedentIF-part expressed as an Antecedent AST over input variables/terms.
consequent: Vec<Consequent>THEN-parts listing output variable/term pairs to implicate.
Implementations§
Source§impl Rule
impl Rule
Sourcepub fn activation<KI, KV>(
&self,
input: &HashMap<KI, Float>,
vars: &HashMap<KV, Variable>,
) -> Result<Float>
pub fn activation<KI, KV>( &self, input: &HashMap<KI, Float>, vars: &HashMap<KV, Variable>, ) -> Result<Float>
Evaluate the antecedent against crisp inputs to obtain activation.
Type parameters
KI: key type forinput, must borrow asstr(e.g.,&str).KV: key type forvars, must borrow asstr.
Returns the activation degree alpha ∈ [0, 1] for this rule.
Errors
FuzzyError::NotFoundif an input or variable is missing.FuzzyError::TypeMismatchif the antecedent references an unknown term.FuzzyError::OutOfBoundsif an input value lies outside a variable’s domain.
Sourcepub fn implicate<KV>(
&self,
alpha: Float,
vars: &HashMap<KV, Variable>,
sampler: &UniformSampler,
) -> Result<HashMap<String, Vec<Float>>>
pub fn implicate<KV>( &self, alpha: Float, vars: &HashMap<KV, Variable>, sampler: &UniformSampler, ) -> Result<HashMap<String, Vec<Float>>>
Apply implication to produce discretized membership outputs.
For each Consequent, this function:
- retrieves the target variable’s domain, 2) builds an evenly spaced
grid of
sampler.npoints, 3) evaluates the consequent term’s membershipμ_B(x)on that grid, and 4) applies clipping viamin(alpha, μ_B(x)).
The result is a map from variable name to the vector of sampled values.
Errors
FuzzyError::NotFoundif a variable or term cannot be found.FuzzyError::OutOfBoundsif evaluation occurs outside the domain.
Note
- The x-grid spacing is
(max - min) / (sampler.n - 1)so the vector always includes both domain endpoints.
Sourcepub fn validate<KV>(&self, vars: &HashMap<KV, Variable>) -> Result<()>
pub fn validate<KV>(&self, vars: &HashMap<KV, Variable>) -> Result<()>
Validate that this rule references only existing variables and terms.
Ensures all antecedent atoms and consequents point to variables present
in vars and that the referenced term labels exist within those
variables’ term maps. Returns Ok(()) on success, or NotFound errors
identifying the missing Var or Term.