Rule

Struct Rule 

Source
pub struct Rule { /* private fields */ }

Implementations§

Source§

impl Rule

Source

pub fn new_or(relations: Vec<i32>, weight: f64) -> Self

Source

pub fn new_and(relations: Vec<i32>, weight: f64) -> Self

Examples found in repository?
examples/function_approximation.rs (line 54)
11fn main() {
12    let x1 = 0.0;
13    let x2 = 0.25;
14    let x3 = 0.5;
15    let x4 = 0.75;
16    let x5 = 1.0;
17    let original_function = |x| x * (1.0 - x);
18    let y15 = original_function(x1);
19    let y24 = original_function(x2);
20    let y3 = original_function(x3);
21
22    let mut fis = TSKFIS::new(SNorms::Max, TNorms::Min, TSKDefuzzifiers::Mean);
23
24    let mut x: InputVariable = InputVariable::new("X".to_string(), (0.0, 1.0));
25    x.add_membership(MembershipFunction::new(
26        "x1".to_string(),
27        MFKind::Gaussian(Gaussian::new(x1, 0.09)),
28    ));
29    x.add_membership(MembershipFunction::new(
30        "x2".to_string(),
31        MFKind::Gaussian(Gaussian::new(x2, 0.09)),
32    ));
33    x.add_membership(MembershipFunction::new(
34        "x3".to_string(),
35        MFKind::Gaussian(Gaussian::new(x3, 0.09)),
36    ));
37    x.add_membership(MembershipFunction::new(
38        "x4".to_string(),
39        MFKind::Gaussian(Gaussian::new(x4, 0.09)),
40    ));
41    x.add_membership(MembershipFunction::new(
42        "x5".to_string(),
43        MFKind::Gaussian(Gaussian::new(x5, 0.09)),
44    ));
45    fis.add_input(x);
46
47    let mut y: TSKOutputVariable = TSKOutputVariable::new("Y".to_string());
48    y.add_constant_membership(y15);
49    y.add_constant_membership(y24);
50    y.add_constant_membership(y3);
51
52    fis.add_output(y);
53
54    fis.add_rule(Rule::new_and(vec![0, 0], 1.0));
55    fis.add_rule(Rule::new_and(vec![1, 1], 1.0));
56    fis.add_rule(Rule::new_and(vec![2, 2], 1.0));
57    fis.add_rule(Rule::new_and(vec![3, 1], 1.0));
58    fis.add_rule(Rule::new_and(vec![4, 0], 1.0));
59    
60    let out: Vec<f64> = fis.compute_outputs(vec![0.6]);
61    println!("{:?}", out);
62}
More examples
Hide additional examples
examples/speed_control.rs (line 86)
14fn main() {
15    let mut v1 = InputVariable::new("speed".to_string(), (0.0, 140.0));
16    v1.add_membership(MF::new(
17        "S".to_string(),
18        MFKind::Triangle(Triangle::new(-58.3, 0.0, 58.3)),
19    ));
20    v1.add_membership(MF::new(
21        "M".to_string(),
22        MFKind::Triangle(Triangle::new(11.67, 70.0, 128.3)),
23    ));
24    v1.add_membership(MF::new(
25        "L".to_string(),
26        MFKind::Triangle(Triangle::new(81.67, 140.0, 198.3)),
27    ));
28
29    let mut v2 = InputVariable::new("Distance".to_string(), (0.0, 50.0));
30    v2.add_membership(MF::new(
31        "S".to_string(),
32        MFKind::Triangle(Triangle::new(-20.83, 0.0, 20.83)),
33    ));
34    v2.add_membership(MF::new(
35        "M".to_string(),
36        MFKind::Triangle(Triangle::new(4.168, 25.0, 45.82)),
37    ));
38    v2.add_membership(MF::new(
39        "L".to_string(),
40        MFKind::Triangle(Triangle::new(29.17, 50.0, 70.82)),
41    ));
42
43    let mut o1 = OutputVariable::new(String::from("Acceleration"), (-1.0, 1.0), 100);
44    o1.add_membership(MembershipRange::new_gaussian(
45        o1.get_universe(),
46        "NB".to_string(),
47        -1.0,
48        0.2123,
49    ));
50    o1.add_membership(MembershipRange::new_gaussian(
51        o1.get_universe(),
52        "NS".to_string(),
53        -0.5,
54        0.2123,
55    ));
56    o1.add_membership(MembershipRange::new_gaussian(
57        o1.get_universe(),
58        "ZR".to_string(),
59        0.0,
60        0.2123,
61    ));
62    o1.add_membership(MembershipRange::new_gaussian(
63        o1.get_universe(),
64        "PS".to_string(),
65        0.5,
66        0.2123,
67    ));
68    o1.add_membership(MembershipRange::new_gaussian(
69        o1.get_universe(),
70        "PB".to_string(),
71        1.0,
72        0.2123,
73    ));
74
75    let mut fis = MamdaniFIS::new(
76        SNorms::Max,
77        TNorms::Min,
78        Implications::Min,
79        Aggregations::Max,
80        Defuzzifiers::Bisection,
81    );
82    fis.add_input(v1);
83    fis.add_input(v2);
84    fis.add_output(o1);
85
86    fis.add_rule(Rule::new_and(vec![0, 0, 2], 1.0));
87    fis.add_rule(Rule::new_and(vec![0, 1, 3], 1.0));
88    fis.add_rule(Rule::new_and(vec![0, 2, 4], 1.0));
89
90    fis.add_rule(Rule::new_and(vec![1, 0, 1], 1.0));
91    fis.add_rule(Rule::new_and(vec![1, 1, 2], 1.0));
92    fis.add_rule(Rule::new_and(vec![1, 2, 3], 1.0));
93
94    fis.add_rule(Rule::new_and(vec![2, 0, 0], 1.0));
95    fis.add_rule(Rule::new_and(vec![2, 1, 1], 1.0));
96    fis.add_rule(Rule::new_and(vec![2, 2, 2], 1.0));
97
98    let output = fis.compute_outputs(vec![40.0, 43.0]);
99    println!("output is: {:#?}", output);
100}
Source

pub fn get_rules(&self) -> &[i32]

Source

pub fn get_kind(&self) -> &Kind

Source

pub fn get_weight(&self) -> f64

Source

pub fn get_input_rules(&self, input_size: usize) -> &[i32]

Source

pub fn get_output_rules(&self, input_size: usize) -> &[i32]

Trait Implementations§

Source§

impl Debug for Rule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Rule

§

impl RefUnwindSafe for Rule

§

impl Send for Rule

§

impl Sync for Rule

§

impl Unpin for Rule

§

impl UnwindSafe for Rule

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.