Expand description
Defuzzification: reduce aggregated membership samples to crisp outputs.
This module implements centroid-of-area (center of gravity) defuzzification
over discretized membership samples produced by aggregation. For each output
variable, the aggregated membership vector μ[i] is paired with the grid of
x-coordinates derived from the variable’s domain and the vector length, and
the crisp output is computed as:
x* = (Σ x[i] · μ[i]) / (Σ μ[i]), where i = 0..N-1 and N ≥ 2.
Notes
- The x-grid spacing is
step = (max - min) / (N - 1)so both domain endpoints are always sampled. - If the sum Σ μ[i] is numerically zero, the result will follow IEEE-754
semantics (e.g.,
NaNorinf) since no special handling is applied. Ensure that your aggregated membership carries non-zero mass.
Example
use std::collections::HashMap;
use rust_fuzzylogic::prelude::*;
use rust_fuzzylogic::membership::triangular::Triangular;
use rust_fuzzylogic::term::Term;
use rust_fuzzylogic::variable::Variable;
use rust_fuzzylogic::defuzz::defuzzification;
// Suppose aggregation produced a single output variable "fan" with N samples
let sampler_n = 5usize;
let mut agg: HashMap<String, Vec<Float>> = HashMap::new();
agg.insert("fan".into(), vec![0.0, 0.2, 0.6, 0.2, 0.0]);
// The corresponding variable domain is needed to build x[i]
let mut fan = Variable::new(0.0, 10.0).unwrap();
fan.insert_term("high", Term::new("high", Triangular::new(5.0, 7.5, 10.0).unwrap())).unwrap();
let mut vars: HashMap<&str, Variable> = HashMap::new();
vars.insert("fan", fan);
// Compute centroid for each aggregated output variable
let crisp = defuzzification(&agg, &vars).unwrap();
assert!(crisp["fan"] >= 0.0 && crisp["fan"] <= 10.0);Functions§
- defuzzification
- Defuzzify aggregated membership samples using the centroid-of-area method.