# LFA Toolbox
LFA Toolbox is a set of tools to create, view and play with fuzzy systems. Ideal for students to play with fuzzy systems.
For example a simple example of a fuzzy system to determine if there will be
a lot of tourists given the temperature and the amount of sunshine.
* IF (temperature is hot OR sunshine is sunny), THEN (tourists is high)
* IF (temperature is warm AND sunshine is part_sunny), THEN (tourists is medium)
* IF (temperature is cold OR sunshine is cloudy), THEN (tourists is low)

## Installation
The detailed install instructions can be found here [docs/INSTALL.md](docs/INSTALL.md) but
you basically need to do:
`pip install lfa-toolbox`
## Features
* Singleton and Mamdani fuzzy system types
* Commonly used membership functions (Trap. MF, Triangle MF, Free shape MF,..)
* Multiple consequents
* Default rule
* NOT conditions
* Viewers (membership function viewer, linguistic variable viewer,...)
## Examples
### Membership functions
**TODO** hand-crafted mf + triangular mf + linPWMF + screenshot viewer
```python
from matplotlib import pyplot as plt
from lfa_toolbox.core.mf.triangular_mf import TriangularMF
from lfa_toolbox.view.mf_viewer import MembershipFunctionViewer
# Create a matplotlib plot
fig, ax = plt.subplots()
# Create a triangular membership function
temp_mf = TriangularMF(-20, 25, 40)
# You can fuzzify an input value
fuzzified_value = temp_mf.fuzzify(22.5)
print("MF has been fuzzified to {:.3f}".format(fuzzified_value))
# Or you can visualize the MF using matplotlib
mfv = MembershipFunctionViewer(temp_mf, ax=ax,
label="Temperature in celsius")
mfv.fuzzify(22.5)
plt.legend() # optionally show the legend i.e. "Temperature"
plt.show()
```
And the output will be:

Others shapes of membership functions can be created such as:

Code for this visualization is available at [/lfa_toolbox/examples/readme_examples.py](/lfa_toolbox/examples/readme_examples.py).
### Linguistic variable
**TODO** hand-crafted lv + three points lv + p points lv + screenshot viewer
You can create and visualize linguistic variables by specifing labels and
membership functions for each label.
```python
from matplotlib import pyplot as plt
from lfa_toolbox.core.lv.linguistic_variable import LinguisticVariable
from lfa_toolbox.view.lv_viewer import LinguisticVariableViewer
fig, axs = plt.subplots(3, figsize=(12, 8))
for ax in axs:
lv_temp = LinguisticVariable(
name="temperature",
ling_values_dict={
"cold": LinPWMF([17, 1], [20, 0]),
"warm": LinPWMF([17, 0], [20, 1], [26, 1], [29, 0]),
"hot": LinPWMF([26, 0], [29, 1]),
},
)
viewer = LinguisticVariableViewer(lv_temp, ax=ax)
viewer.fuzzify(26.6)
viewer.fuzzify(21.8)
fig.tight_layout()
plt.show()
```

You can also use the class `PPointsLV` to create interpretable more
conveniently.
```python
from matplotlib import pyplot as plt
from lfa_toolbox.view.lv_viewer import LinguisticVariableViewer
from lfa_toolbox.core.lv.p_points_lv import PPointsLV
fig, ax = plt.subplots()
# PPointsLV helps you create a linguistic variable that is human
# interpretable and generate automatically fuzzy labels for you.
lv = PPointsLV("Github stars", [0, 50, 300, 1000])
LinguisticVariableViewer(lv, ax=ax)
plt.show()
```

### Fuzzy System
You can create an entire fuzzy system by hand. LFA Toolbox supports Singleton
and Mamdani fuzzy systems, default rule and NOT conditions. You can see how it
works by looking at the examples here [/lfa_toolbox/examples](/lfa_toolbox/examples).
Take a look at the [`car_problem_slides`](/lfa_toolbox/examples/car_problem_slides) folder.
It shows a problem where we want to regulate the push of a pedal to maintain
the speed of a car. It starts with a Mamdani fuzzy system and gradually
simplifies it by first replacing it with a Singleton fuzzy system, then by
adding a default fuzzy rule and finally by using NOT conditions.
## Integration with Trefle
[Trefle](https://github.com/krypty/trefle) is a scikit-learn compatible
estimator implementing the FuzzyCoCo algorithm that uses a cooperative
coevolution algorithm to find and build interpretable fuzzy systems.
See [Trefle's Github](https://github.com/krypty/trefle) to learn how to
install it.
Basically after running Trefle you can save the best fuzzy system and fine tune
it with LFA Toolbox. For example you can change the values of the membership
functions or remove a too specific fuzzy rule.
See [/lfa_toolbox/examples/import_a_trefle_fuzzy_system.py](/lfa_toolbox/examples/import_a_trefle_fuzzy_system.py) example.
## Deployment and Tests
Both documentations are available in the `docs` folder.
## Credits
* Gary Marigliano (developper)
* Carlos Andrés PEÑA REYES (project manager)
* [CI4CB Team](http://iict-space.heig-vd.ch/cpn/)


LFA Toolbox is a set of tools to create, view and play with fuzzy systems. Ideal for students to play with fuzzy systems.
For example a simple example of a fuzzy system to determine if there will be
a lot of tourists given the temperature and the amount of sunshine.
* IF (temperature is hot OR sunshine is sunny), THEN (tourists is high)
* IF (temperature is warm AND sunshine is part_sunny), THEN (tourists is medium)
* IF (temperature is cold OR sunshine is cloudy), THEN (tourists is low)

## Installation
The detailed install instructions can be found here [docs/INSTALL.md](docs/INSTALL.md) but
you basically need to do:
`pip install lfa-toolbox`
## Features
* Singleton and Mamdani fuzzy system types
* Commonly used membership functions (Trap. MF, Triangle MF, Free shape MF,..)
* Multiple consequents
* Default rule
* NOT conditions
* Viewers (membership function viewer, linguistic variable viewer,...)
## Examples
### Membership functions
**TODO** hand-crafted mf + triangular mf + linPWMF + screenshot viewer
```python
from matplotlib import pyplot as plt
from lfa_toolbox.core.mf.triangular_mf import TriangularMF
from lfa_toolbox.view.mf_viewer import MembershipFunctionViewer
# Create a matplotlib plot
fig, ax = plt.subplots()
# Create a triangular membership function
temp_mf = TriangularMF(-20, 25, 40)
# You can fuzzify an input value
fuzzified_value = temp_mf.fuzzify(22.5)
print("MF has been fuzzified to {:.3f}".format(fuzzified_value))
# Or you can visualize the MF using matplotlib
mfv = MembershipFunctionViewer(temp_mf, ax=ax,
label="Temperature in celsius")
mfv.fuzzify(22.5)
plt.legend() # optionally show the legend i.e. "Temperature"
plt.show()
```
And the output will be:

Others shapes of membership functions can be created such as:

Code for this visualization is available at [/lfa_toolbox/examples/readme_examples.py](/lfa_toolbox/examples/readme_examples.py).
### Linguistic variable
**TODO** hand-crafted lv + three points lv + p points lv + screenshot viewer
You can create and visualize linguistic variables by specifing labels and
membership functions for each label.
```python
from matplotlib import pyplot as plt
from lfa_toolbox.core.lv.linguistic_variable import LinguisticVariable
from lfa_toolbox.view.lv_viewer import LinguisticVariableViewer
fig, axs = plt.subplots(3, figsize=(12, 8))
for ax in axs:
lv_temp = LinguisticVariable(
name="temperature",
ling_values_dict={
"cold": LinPWMF([17, 1], [20, 0]),
"warm": LinPWMF([17, 0], [20, 1], [26, 1], [29, 0]),
"hot": LinPWMF([26, 0], [29, 1]),
},
)
viewer = LinguisticVariableViewer(lv_temp, ax=ax)
viewer.fuzzify(26.6)
viewer.fuzzify(21.8)
fig.tight_layout()
plt.show()
```

You can also use the class `PPointsLV` to create interpretable more
conveniently.
```python
from matplotlib import pyplot as plt
from lfa_toolbox.view.lv_viewer import LinguisticVariableViewer
from lfa_toolbox.core.lv.p_points_lv import PPointsLV
fig, ax = plt.subplots()
# PPointsLV helps you create a linguistic variable that is human
# interpretable and generate automatically fuzzy labels for you.
lv = PPointsLV("Github stars", [0, 50, 300, 1000])
LinguisticVariableViewer(lv, ax=ax)
plt.show()
```

### Fuzzy System
You can create an entire fuzzy system by hand. LFA Toolbox supports Singleton
and Mamdani fuzzy systems, default rule and NOT conditions. You can see how it
works by looking at the examples here [/lfa_toolbox/examples](/lfa_toolbox/examples).
Take a look at the [`car_problem_slides`](/lfa_toolbox/examples/car_problem_slides) folder.
It shows a problem where we want to regulate the push of a pedal to maintain
the speed of a car. It starts with a Mamdani fuzzy system and gradually
simplifies it by first replacing it with a Singleton fuzzy system, then by
adding a default fuzzy rule and finally by using NOT conditions.
## Integration with Trefle
[Trefle](https://github.com/krypty/trefle) is a scikit-learn compatible
estimator implementing the FuzzyCoCo algorithm that uses a cooperative
coevolution algorithm to find and build interpretable fuzzy systems.
See [Trefle's Github](https://github.com/krypty/trefle) to learn how to
install it.
Basically after running Trefle you can save the best fuzzy system and fine tune
it with LFA Toolbox. For example you can change the values of the membership
functions or remove a too specific fuzzy rule.
See [/lfa_toolbox/examples/import_a_trefle_fuzzy_system.py](/lfa_toolbox/examples/import_a_trefle_fuzzy_system.py) example.
## Deployment and Tests
Both documentations are available in the `docs` folder.
## Credits
* Gary Marigliano (developper)
* Carlos Andrés PEÑA REYES (project manager)
* [CI4CB Team](http://iict-space.heig-vd.ch/cpn/)


Release files for lfa-toolbox 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lfa_toolbox-0.2.tar.gz | 26.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lfa_toolbox-0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 83.3 kB
Release files / lfa_toolbox-0.2.tar.gz
| Download URL | lfa_toolbox-0.2.tar.gz |
|---|---|
| Size | 26.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1081eab4c7ae6eea426a6bf5319240f5143e7072f8a1b1f5ee1f6f10d424a396
|
|
BLAKE2b-256 checksum How to use checksums |
04dd91355e83db5523b1891489e19299554f4d79a0c7fa3ab273b174c7001780
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.5
|
Release files / lfa_toolbox-0.2-py3-none-any.whl
| Download URL | lfa_toolbox-0.2-py3-none-any.whl |
|---|---|
| Size | 56.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce3d22e5c58deeef50323f990c60a3ddd3dc81f3dd3547298f6666d36213dbf3
|
|
BLAKE2b-256 checksum How to use checksums |
d7ea8b30f42528802f58b09cb8a6bb149e23b363afdc7b64113a76a7abe677dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.5
|