๐Deprecated since 0.2.0: Use system::System and SystemBuilder instead
Expand description
Deprecated: RuleSpace has been superseded by system::System and
system::SystemBuilder.
As of 0.2.0, prefer building fuzzy inference systems via the System
API, which validates rules on construction and provides a cohesive
builder for variables, terms, and rules.
This module remains for backward compatibility and will be removed in a future release.
RuleSpace: orchestrate aggregation and defuzzification for a rule base.
RuleSpace bundles the fuzzy variables, rule set, and the intermediate
aggregated membership values produced during inference. It provides a
convenience API to:
- construct a rule space from variables and rules (
new), - append additional rules (
add_rules), - run aggregation only (
aggregate), and - run aggregation followed by defuzzification in one call (
defuzzify).
Typical flow
- Define input/output variables and their terms.
- Build rules from antecedents and consequents.
- Create a
RuleSpaceand calldefuzzifywith crisp inputs and a sampler.
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::antecedent::Antecedent;
use rust_fuzzylogic::mamdani::{Rule, Consequent};
use rust_fuzzylogic::rulespace::RuleSpace;
// Variables
let mut temp = Variable::new(-10.0, 10.0).unwrap();
temp.insert_term("hot", Term::new("hot", Triangular::new(0.0, 5.0, 10.0).unwrap())).unwrap();
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<String, Variable> = HashMap::new();
vars.insert("temp".into(), temp);
vars.insert("fan".into(), fan);
// Rule: IF temp IS hot THEN fan IS high
let rules = vec![Rule{
antecedent: Antecedent::Atom{ var: "temp".into(), term: "hot".into() },
consequent: vec![Consequent{ var: "fan".into(), term: "high".into() }],
}];
let sampler = UniformSampler::default();
let mut rs = RuleSpace::new(vars, rules).unwrap();
let mut input: HashMap<&str, Float> = HashMap::new();
input.insert("temp", 7.5);
// One-shot aggregate + defuzzify
let crisp = rs.defuzzify(&input, &sampler).unwrap();
assert!(crisp["fan"] >= 0.0 && crisp["fan"] <= 10.0);Structsยง
- Rule
Space Deprecated - Container for fuzzy variables, rules, and intermediate membership data.