pub struct FuzzyLogicEngine { /* private fields */ }Expand description
A complete fuzzy logic inference system.
§Usage
- Create an engine with
FuzzyLogicEngine::new. - Register linguistic variables with
FuzzyLogicEngine::add_variable. - Add IF-THEN rules with
FuzzyLogicEngine::add_rule. - Call
FuzzyLogicEngine::inferorFuzzyLogicEngine::evaluateto obtain a crisp output for a given set of crisp inputs.
Implementations§
Source§impl FuzzyLogicEngine
impl FuzzyLogicEngine
Sourcepub fn new(inference: InferenceMethod, defuzz: DefuzzMethod) -> Self
pub fn new(inference: InferenceMethod, defuzz: DefuzzMethod) -> Self
Create a new engine with the given inference and defuzzification strategies.
Sourcepub fn add_variable(&mut self, var: FuzzyVariable) -> Result<(), FuzzyError>
pub fn add_variable(&mut self, var: FuzzyVariable) -> Result<(), FuzzyError>
Register a linguistic variable.
§Errors
Returns FuzzyError::DuplicateVariable if a variable with the same
name already exists.
Sourcepub fn add_rule(&mut self, rule: FuzzyRule) -> Result<(), FuzzyError>
pub fn add_rule(&mut self, rule: FuzzyRule) -> Result<(), FuzzyError>
Register a fuzzy rule.
Validates that every variable and set referenced by the rule exists.
§Errors
Returns FuzzyError::VariableNotFound or FuzzyError::SetNotFound
if any reference is invalid.
Sourcepub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Return the number of registered rules.
Sourcepub fn variable_names(&self) -> Vec<&str>
pub fn variable_names(&self) -> Vec<&str>
Return the names of all registered variables.
Sourcepub fn membership_at(
&self,
variable: &str,
set: &str,
x: f64,
) -> Result<f64, FuzzyError>
pub fn membership_at( &self, variable: &str, set: &str, x: f64, ) -> Result<f64, FuzzyError>
Return the membership degree of x in a specific set of a variable.
§Errors
Returns FuzzyError::VariableNotFound or FuzzyError::SetNotFound.
Sourcepub fn fuzzify(
&self,
variable: &str,
crisp: f64,
) -> Result<Vec<(String, f64)>, FuzzyError>
pub fn fuzzify( &self, variable: &str, crisp: f64, ) -> Result<Vec<(String, f64)>, FuzzyError>
Fuzzify a crisp value for a named variable.
Returns a vector of (set_name, degree) pairs for every set defined
on the variable.
§Errors
Returns FuzzyError::VariableNotFound if the variable is unknown.
Sourcepub fn fire_rule(
&self,
rule: &FuzzyRule,
inputs: &HashMap<String, f64>,
) -> Result<f64, FuzzyError>
pub fn fire_rule( &self, rule: &FuzzyRule, inputs: &HashMap<String, f64>, ) -> Result<f64, FuzzyError>
Evaluate the antecedent of rule given a map of crisp input values.
Returns the weighted activation degree α * rule.weight.
§Errors
Returns FuzzyError::VariableNotFound or FuzzyError::SetNotFound.
Sourcepub fn infer(
&self,
inputs: &HashMap<String, f64>,
output_var: &str,
) -> Result<f64, FuzzyError>
pub fn infer( &self, inputs: &HashMap<String, f64>, output_var: &str, ) -> Result<f64, FuzzyError>
Run the complete fuzzy inference pipeline and return a crisp output
for output_var.
§Errors
FuzzyError::VariableNotFound—output_varor any input variable is missing.FuzzyError::SetNotFound— a rule references an undefined set.FuzzyError::NoRulesForOutput— no rules targetoutput_var.FuzzyError::NumericalError— all aggregate membership values are zero.
Sourcepub fn evaluate(
&mut self,
inputs: &HashMap<String, f64>,
output_var: &str,
) -> Result<f64, FuzzyError>
pub fn evaluate( &mut self, inputs: &HashMap<String, f64>, output_var: &str, ) -> Result<f64, FuzzyError>
Sourcepub fn stats(&self) -> FuzzyStats
pub fn stats(&self) -> FuzzyStats
Return a snapshot of engine statistics.
Auto Trait Implementations§
impl Freeze for FuzzyLogicEngine
impl RefUnwindSafe for FuzzyLogicEngine
impl Send for FuzzyLogicEngine
impl Sync for FuzzyLogicEngine
impl Unpin for FuzzyLogicEngine
impl UnsafeUnpin for FuzzyLogicEngine
impl UnwindSafe for FuzzyLogicEngine
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more