Skip to content

Commit 88a0146

Browse files
authored
Merge pull request #2 from JoshuaKento/codex/add-readme.md-to-root-directory-05s46v
Add documentation comments to Mamdani inference components
2 parents cba1ec7 + 7a9db4a commit 88a0146

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# rust-fuzzylogic
22

3+
34
A Rust crate that provides building blocks for authoring fuzzy inference systems.
45
The project aims to make it easy to describe linguistic variables, membership functions, and rule
56
bases while keeping room for experimentation with multiple aggregation operators and inference

src/aggregate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
//Agregation acros sets of rules
1+
// Aggregation utilities for combining rule outputs across consequents.
22

33
use crate::{mamdani::Rule, prelude::*, variable::Variable};
44
use std::{borrow::Borrow, collections::HashMap, hash::Hash};
55

6+
/// Combine two membership sample vectors by taking the pointwise maximum.
67
pub fn elements_max(data: &mut Vec<Float>, src: &Vec<Float>) {
78
for (d, s) in data.iter_mut().zip(src) {
89
*d = d.max(*s)
910
}
1011
}
1112

13+
/// Aggregate the contributions of all rules into output membership functions.
1214
pub fn aggregation<KI, KV>(
1315
rules: Vec<Rule>,
1416
input: &HashMap<KI, Float>,

src/defuzz.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
//Possible Defuzz methods => Bisecctor of Area, Centroid, ...
1+
// Defuzzification utilities for collapsing aggregated membership values.
22
use crate::{prelude::*, variable::Variable};
33
use std::{borrow::Borrow, collections::HashMap, hash::Hash};
44

5+
/// Defuzzify aggregated membership samples using the centroid of area method.
56
pub fn defuzzification<KV>(
67
myu: HashMap<String, Vec<Float>>,
78
vars: &HashMap<KV, Variable>,

src/mamdani.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//mamdani style Implication and Consequent/Rule Behaviour
1+
// Mamdani-style implication and rule behavior primitives.
22

33
use std::{borrow::Borrow, collections::HashMap, hash::Hash};
44

@@ -11,18 +11,21 @@ use crate::{
1111
variable::Variable,
1212
};
1313

14+
/// Implication modes supported by a Mamdani rule.
1415
pub enum Implication {
1516
Clip,
1617
Product,
1718
}
1819

20+
/// Output clause of a fuzzy rule referencing a linguistic variable and term.
1921
pub struct Consequent {
2022
pub var: String,
2123
pub term: String,
2224
//pub weight: Float,
2325
//pub imp: Implication,
2426
}
2527

28+
/// Full fuzzy rule pairing an antecedent with one or more consequents.
2629
pub struct Rule {
2730
pub antecedent: Antecedent,
2831
pub consequent: Vec<Consequent>,
@@ -31,6 +34,7 @@ pub struct Rule {
3134
//Mamdani Inference Engine
3235
#[cfg(feature = "inference-mamdani")]
3336
impl Rule {
37+
/// Evaluate the antecedent against crisp input values to obtain activation.
3438
pub fn activation<KI, KV>(
3539
&self,
3640
input: &HashMap<KI, Float>,
@@ -43,6 +47,7 @@ impl Rule {
4347
eval_antecedent(&self.antecedent, input, vars)
4448
}
4549

50+
/// Apply the selected implication operator to produce discretized membership outputs.
4651
pub fn implicate<KV>(
4752
&self,
4853
alpha: Float,

src/rulespace.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ use crate::{
1010
variable::Variable,
1111
};
1212

13-
//#[derive()]
13+
// Container for fuzzy variables, rules, and intermediate membership data.
1414
pub struct RuleSpace {
1515
pub vars: HashMap<String, Variable>,
1616
pub myu: HashMap<String, Vec<Float>>,
1717
pub rules: Vec<Rule>,
1818
}
1919

2020
impl RuleSpace {
21+
/// Create a rule space with the supplied variables and rules.
2122
pub fn new(self, vars: HashMap<String, Variable>, rules: Vec<Rule>) -> Self {
2223
return Self {
2324
vars: vars,
@@ -26,10 +27,12 @@ impl RuleSpace {
2627
};
2728
}
2829

30+
/// Append additional rules to the existing rule set.
2931
pub fn add_rules(mut self, rules: &mut Vec<Rule>) {
3032
self.rules.append(rules);
3133
}
3234

35+
/// Run the aggregation step for all rules with the provided crisp inputs.
3336
pub fn aggregate<KI>(
3437
&mut self,
3538
input: &HashMap<KI, Float>,
@@ -45,6 +48,7 @@ impl RuleSpace {
4548
Ok(())
4649
}
4750

51+
/// Aggregate and then defuzzify each output variable using the supplied sampler.
4852
pub fn defuzzificate<KI>(
4953
&mut self,
5054
input: &HashMap<KI, Float>,

0 commit comments

Comments
 (0)