Skip to content

Commit

Permalink
Updated examples + test (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrada authored Nov 30, 2023
1 parent 70eb457 commit 20a52d5
Show file tree
Hide file tree
Showing 21 changed files with 68 additions and 154 deletions.
21 changes: 4 additions & 17 deletions fuzzylite/examples/mamdani/laundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ def __init__(self) -> None:
fl.Discrete(
"normal",
fl.array(
[
fl.array([3.0, 0.0]),
fl.array([4.0, 1.0]),
fl.array([6.0, 0.0]),
]
[fl.array([3.0, 0.0]), fl.array([4.0, 1.0]), fl.array([6.0, 0.0])]
),
),
],
Expand All @@ -44,11 +40,7 @@ def __init__(self) -> None:
fl.Discrete(
"low",
fl.array(
[
fl.array([0.0, 1.0]),
fl.array([2.0, 0.8]),
fl.array([5.0, 0.0]),
]
[fl.array([0.0, 1.0]), fl.array([2.0, 0.8]), fl.array([5.0, 0.0])]
),
),
fl.Discrete(
Expand Down Expand Up @@ -116,16 +108,11 @@ def __init__(self) -> None:
fl.Discrete(
"short",
fl.array(
[
fl.array([0.0, 1.0]),
fl.array([10.0, 1.0]),
fl.array([20.0, 0.0]),
]
[fl.array([0.0, 1.0]), fl.array([10.0, 1.0]), fl.array([20.0, 0.0])]
),
),
fl.Discrete(
"long",
fl.array([fl.array([10.0, 0.0]), fl.array([20.0, 1.0])]),
"long", fl.array([fl.array([10.0, 0.0]), fl.array([20.0, 1.0])])
),
],
),
Expand Down
10 changes: 2 additions & 8 deletions fuzzylite/examples/mamdani/matlab/mam21.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,14 @@ def __init__(self) -> None:
minimum=-5.0,
maximum=5.0,
lock_range=False,
terms=[
fl.Bell("small", -5.0, 5.0, 8.0),
fl.Bell("big", 5.0, 5.0, 8.0),
],
terms=[fl.Bell("small", -5.0, 5.0, 8.0), fl.Bell("big", 5.0, 5.0, 8.0)],
),
fl.InputVariable(
name="velocity",
minimum=-5.0,
maximum=5.0,
lock_range=False,
terms=[
fl.Bell("small", -5.0, 5.0, 2.0),
fl.Bell("big", 5.0, 5.0, 2.0),
],
terms=[fl.Bell("small", -5.0, 5.0, 2.0), fl.Bell("big", 5.0, 5.0, 2.0)],
),
],
output_variables=[
Expand Down
10 changes: 2 additions & 8 deletions fuzzylite/examples/mamdani/matlab/mam22.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,14 @@ def __init__(self) -> None:
minimum=-5.0,
maximum=5.0,
lock_range=False,
terms=[
fl.Bell("small", -5.0, 5.0, 8.0),
fl.Bell("big", 5.0, 5.0, 8.0),
],
terms=[fl.Bell("small", -5.0, 5.0, 8.0), fl.Bell("big", 5.0, 5.0, 8.0)],
),
fl.InputVariable(
name="velocity",
minimum=-5.0,
maximum=5.0,
lock_range=False,
terms=[
fl.Bell("small", -5.0, 5.0, 2.0),
fl.Bell("big", 5.0, 5.0, 2.0),
],
terms=[fl.Bell("small", -5.0, 5.0, 2.0), fl.Bell("big", 5.0, 5.0, 2.0)],
),
],
output_variables=[
Expand Down
5 changes: 1 addition & 4 deletions fuzzylite/examples/mamdani/octave/investment_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ def __init__(self) -> None:
minimum=20.0,
maximum=100.0,
lock_range=False,
terms=[
fl.ZShape("Young", 30.0, 90.0),
fl.SShape("Old", 30.0, 90.0),
],
terms=[fl.ZShape("Young", 30.0, 90.0), fl.SShape("Old", 30.0, 90.0)],
),
fl.InputVariable(
name="RiskTolerance",
Expand Down
20 changes: 4 additions & 16 deletions fuzzylite/examples/takagi_sugeno/matlab/slbb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,28 @@ def __init__(self) -> None:
minimum=-1.5,
maximum=1.5,
lock_range=False,
terms=[
fl.Bell("in1mf1", -1.5, 1.5, 2.0),
fl.Bell("in1mf2", 1.5, 1.5, 2.0),
],
terms=[fl.Bell("in1mf1", -1.5, 1.5, 2.0), fl.Bell("in1mf2", 1.5, 1.5, 2.0)],
),
fl.InputVariable(
name="in2",
minimum=-1.5,
maximum=1.5,
lock_range=False,
terms=[
fl.Bell("in2mf1", -1.5, 1.5, 2.0),
fl.Bell("in2mf2", 1.5, 1.5, 2.0),
],
terms=[fl.Bell("in2mf1", -1.5, 1.5, 2.0), fl.Bell("in2mf2", 1.5, 1.5, 2.0)],
),
fl.InputVariable(
name="in3",
minimum=-0.2,
maximum=0.2,
lock_range=False,
terms=[
fl.Bell("in3mf1", -0.2, 0.2, 2.0),
fl.Bell("in3mf2", 0.2, 0.2, 2.0),
],
terms=[fl.Bell("in3mf1", -0.2, 0.2, 2.0), fl.Bell("in3mf2", 0.2, 0.2, 2.0)],
),
fl.InputVariable(
name="in4",
minimum=-0.4,
maximum=0.4,
lock_range=False,
terms=[
fl.Bell("in4mf1", -0.4, 0.4, 2.0),
fl.Bell("in4mf2", 0.4, 0.4, 2.0),
],
terms=[fl.Bell("in4mf1", -0.4, 0.4, 2.0), fl.Bell("in4mf2", 0.4, 0.4, 2.0)],
),
],
output_variables=[
Expand Down
20 changes: 4 additions & 16 deletions fuzzylite/examples/takagi_sugeno/matlab/slcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,28 @@ def __init__(self) -> None:
minimum=-0.3,
maximum=0.3,
lock_range=False,
terms=[
fl.Bell("in1mf1", -0.3, 0.3, 2.0),
fl.Bell("in1mf2", 0.3, 0.3, 2.0),
],
terms=[fl.Bell("in1mf1", -0.3, 0.3, 2.0), fl.Bell("in1mf2", 0.3, 0.3, 2.0)],
),
fl.InputVariable(
name="in2",
minimum=-1.0,
maximum=1.0,
lock_range=False,
terms=[
fl.Bell("in2mf1", -1.0, 1.0, 2.0),
fl.Bell("in2mf2", 1.0, 1.0, 2.0),
],
terms=[fl.Bell("in2mf1", -1.0, 1.0, 2.0), fl.Bell("in2mf2", 1.0, 1.0, 2.0)],
),
fl.InputVariable(
name="in3",
minimum=-3.0,
maximum=3.0,
lock_range=False,
terms=[
fl.Bell("in3mf1", -3.0, 3.0, 2.0),
fl.Bell("in3mf2", 3.0, 3.0, 2.0),
],
terms=[fl.Bell("in3mf1", -3.0, 3.0, 2.0), fl.Bell("in3mf2", 3.0, 3.0, 2.0)],
),
fl.InputVariable(
name="in4",
minimum=-3.0,
maximum=3.0,
lock_range=False,
terms=[
fl.Bell("in4mf1", -3.0, 3.0, 2.0),
fl.Bell("in4mf2", 3.0, 3.0, 2.0),
],
terms=[fl.Bell("in4mf1", -3.0, 3.0, 2.0), fl.Bell("in4mf2", 3.0, 3.0, 2.0)],
),
],
output_variables=[
Expand Down
32 changes: 10 additions & 22 deletions fuzzylite/examples/takagi_sugeno/matlab/slcpp1.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,34 @@ def __init__(self) -> None:
aggregation=None,
defuzzifier=fl.WeightedAverage(type="TakagiSugeno"),
terms=[
fl.Linear("outmf1", [168.4, 31.0, -188.05, -49.25, -1.0, -2.7, 0.0, 0.0]),
fl.Linear(
"outmf1",
[168.4, 31.0, -188.05, -49.25, -1.0, -2.7, 0.0, 0.0],
"outmf2", [233.95, 47.19, -254.52, -66.58, -1.0, -2.74, 0.0, 0.0]
),
fl.Linear(
"outmf2",
[233.95, 47.19, -254.52, -66.58, -1.0, -2.74, 0.0, 0.0],
"outmf3", [342.94, 74.73, -364.37, -95.23, -1.0, -2.78, 0.0, 0.0]
),
fl.Linear(
"outmf3",
[342.94, 74.73, -364.37, -95.23, -1.0, -2.78, 0.0, 0.0],
"outmf4", [560.71, 130.67, -582.96, -152.24, -1.0, -2.81, 0.0, 0.0]
),
fl.Linear(
"outmf4",
[560.71, 130.67, -582.96, -152.24, -1.0, -2.81, 0.0, 0.0],
),
fl.Linear(
"outmf5",
[1213.88, 300.19, -1236.9, -322.8, -1.0, -2.84, 0.0, 0.0],
"outmf5", [1213.88, 300.19, -1236.9, -322.8, -1.0, -2.84, 0.0, 0.0]
),
fl.Linear("outmf6", [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
fl.Linear(
"outmf7",
[-1399.12, -382.95, 1374.63, 358.34, -1.0, -2.9, 0.0, 0.0],
"outmf7", [-1399.12, -382.95, 1374.63, 358.34, -1.0, -2.9, 0.0, 0.0]
),
fl.Linear(
"outmf8",
[-746.07, -213.42, 720.9, 187.84, -1.0, -2.93, 0.0, 0.0],
"outmf8", [-746.07, -213.42, 720.9, 187.84, -1.0, -2.93, 0.0, 0.0]
),
fl.Linear(
"outmf9",
[-528.52, -157.46, 502.68, 130.92, -1.0, -2.96, 0.0, 0.0],
"outmf9", [-528.52, -157.46, 502.68, 130.92, -1.0, -2.96, 0.0, 0.0]
),
fl.Linear(
"outmf10",
[-419.87, -129.89, 393.38, 102.41, -1.0, -2.98, 0.0, 0.0],
"outmf10", [-419.87, -129.89, 393.38, 102.41, -1.0, -2.98, 0.0, 0.0]
),
fl.Linear(
"outmf11",
[-354.77, -113.68, 327.65, 85.27, -1.0, -3.01, 0.0, 0.0],
"outmf11", [-354.77, -113.68, 327.65, 85.27, -1.0, -3.01, 0.0, 0.0]
),
],
)
Expand Down
12 changes: 2 additions & 10 deletions fuzzylite/examples/takagi_sugeno/matlab/sltbu_fl.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@ def __init__(self) -> None:
terms=[fl.ZShape("near", 1.0, 2.0), fl.SShape("far", 1.0, 2.0)],
),
fl.InputVariable(
name="control1",
minimum=-0.785,
maximum=0.785,
lock_range=False,
terms=[],
name="control1", minimum=-0.785, maximum=0.785, lock_range=False, terms=[]
),
fl.InputVariable(
name="control2",
minimum=-0.785,
maximum=0.785,
lock_range=False,
terms=[],
name="control2", minimum=-0.785, maximum=0.785, lock_range=False, terms=[]
),
],
output_variables=[
Expand Down
10 changes: 2 additions & 8 deletions fuzzylite/examples/takagi_sugeno/matlab/sugeno1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ def __init__(self) -> None:
minimum=-5.0,
maximum=5.0,
lock_range=False,
terms=[
fl.Gaussian("low", -5.0, 4.0),
fl.Gaussian("high", 5.0, 4.0),
],
terms=[fl.Gaussian("low", -5.0, 4.0), fl.Gaussian("high", 5.0, 4.0)],
)
],
output_variables=[
Expand All @@ -27,10 +24,7 @@ def __init__(self) -> None:
default_value=fl.nan,
aggregation=None,
defuzzifier=fl.WeightedAverage(type="TakagiSugeno"),
terms=[
fl.Linear("line1", [-1.0, -1.0]),
fl.Linear("line2", [1.0, -1.0]),
],
terms=[fl.Linear("line1", [-1.0, -1.0]), fl.Linear("line2", [1.0, -1.0])],
)
],
rule_blocks=[
Expand Down
5 changes: 1 addition & 4 deletions fuzzylite/examples/terms/bell.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def __init__(self) -> None:
default_value=fl.nan,
aggregation=fl.Maximum(),
defuzzifier=fl.Centroid(),
terms=[
fl.Bell("left", 0.333, 0.167, 3.0),
fl.Bell("right", 0.666, 0.167, 3.0),
],
terms=[fl.Bell("left", 0.333, 0.167, 3.0), fl.Bell("right", 0.666, 0.167, 3.0)],
)
],
rule_blocks=[
Expand Down
5 changes: 1 addition & 4 deletions fuzzylite/examples/terms/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def __init__(self) -> None:
default_value=fl.nan,
aggregation=fl.Maximum(),
defuzzifier=fl.Centroid(),
terms=[
fl.Binary("left", 0.666, -fl.inf),
fl.Binary("right", 0.333, fl.inf),
],
terms=[fl.Binary("left", 0.666, -fl.inf), fl.Binary("right", 0.333, fl.inf)],
)
],
rule_blocks=[
Expand Down
5 changes: 1 addition & 4 deletions fuzzylite/examples/terms/concave.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def __init__(self) -> None:
default_value=fl.nan,
aggregation=fl.Maximum(),
defuzzifier=fl.Centroid(),
terms=[
fl.Concave("left", 0.333, 0.0),
fl.Concave("right", 0.666, 1.0),
],
terms=[fl.Concave("left", 0.333, 0.0), fl.Concave("right", 0.666, 1.0)],
)
],
rule_blocks=[
Expand Down
5 changes: 1 addition & 4 deletions fuzzylite/examples/terms/cosine.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def __init__(self) -> None:
default_value=fl.nan,
aggregation=fl.Maximum(),
defuzzifier=fl.Centroid(),
terms=[
fl.Cosine("left", 0.333, 0.666),
fl.Cosine("right", 0.666, 0.666),
],
terms=[fl.Cosine("left", 0.333, 0.666), fl.Cosine("right", 0.666, 0.666)],
)
],
rule_blocks=[
Expand Down
5 changes: 1 addition & 4 deletions fuzzylite/examples/terms/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def __init__(self) -> None:
default_value=fl.nan,
aggregation=fl.Maximum(),
defuzzifier=fl.Centroid(),
terms=[
fl.Gaussian("left", 0.333, 0.143),
fl.Gaussian("right", 0.666, 0.143),
],
terms=[fl.Gaussian("left", 0.333, 0.143), fl.Gaussian("right", 0.666, 0.143)],
)
],
rule_blocks=[
Expand Down
5 changes: 1 addition & 4 deletions fuzzylite/examples/terms/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def __init__(self) -> None:
default_value=fl.nan,
aggregation=None,
defuzzifier=fl.WeightedAverage(type="TakagiSugeno"),
terms=[
fl.Linear("left", [0.0, 0.333]),
fl.Linear("right", [0.0, 0.666]),
],
terms=[fl.Linear("left", [0.0, 0.333]), fl.Linear("right", [0.0, 0.666])],
)
],
rule_blocks=[
Expand Down
5 changes: 1 addition & 4 deletions fuzzylite/examples/terms/rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def __init__(self) -> None:
default_value=fl.nan,
aggregation=fl.Maximum(),
defuzzifier=fl.Centroid(),
terms=[
fl.Rectangle("left", 0.0, 0.666),
fl.Rectangle("right", 0.333, 1.0),
],
terms=[fl.Rectangle("left", 0.0, 0.666), fl.Rectangle("right", 0.333, 1.0)],
)
],
rule_blocks=[
Expand Down
5 changes: 1 addition & 4 deletions fuzzylite/examples/terms/semi_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def __init__(self) -> None:
default_value=fl.nan,
aggregation=fl.Maximum(),
defuzzifier=fl.Centroid(),
terms=[
fl.SemiEllipse("left", 0.0, 0.666),
fl.SemiEllipse("right", 0.333, 1.0),
],
terms=[fl.SemiEllipse("left", 0.0, 0.666), fl.SemiEllipse("right", 0.333, 1.0)],
)
],
rule_blocks=[
Expand Down
Loading

0 comments on commit 20a52d5

Please sign in to comment.