diff --git a/README.md b/README.md index b15335e..5c1a971 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,33 @@ engine = fl.Engine( ) ``` +### `float` and vectorization + +```python +# single `float` operation +engine.input_variable("obstacle").value = 0.5 +engine.process() +print("y =", engine.output_variable("mSteer").value) +# > y = 0.5 +print("ỹ =", engine.output_variable("mSteer").fuzzy_value()) +# > ỹ = 0.500/left + 0.500/right + +# vectorization +engine.input_variable("obstacle").value = fl.array([0, 0.25, 0.5, 0.75, 1.0]) +engine.process() +print("y =", repr(engine.output_variable("mSteer").value)) +# > y = array([0.6666665 , 0.62179477, 0.5 , 0.37820523, 0.3333335 ]) +print("ỹ =", repr(engine.output_variable("mSteer").fuzzy_value())) +# > ỹ = array(['0.000/left + 1.000/right', +# '0.250/left + 0.750/right', +# '0.500/left + 0.500/right', +# '0.750/left + 0.250/right', +# '1.000/left + 0.000/right'], dtype='Contributing All contributions are welcome, provided they follow the following guidelines: diff --git a/docs/index.md b/docs/index.md index 9c10e6c..6a74fa3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -173,6 +173,33 @@ each included in the following formats: `py`, `fll`, `fld`. With `fuzzylite`: `C ) ``` +### `float` and vectorization + +```python +# single `float` operation +engine.input_variable("obstacle").value = 0.5 +engine.process() +print("y =", engine.output_variable("mSteer").value) +# > y = 0.5 +print("ỹ =", engine.output_variable("mSteer").fuzzy_value()) +# > ỹ = 0.500/left + 0.500/right + +# vectorization +engine.input_variable("obstacle").value = fl.array([0, 0.25, 0.5, 0.75, 1.0]) +engine.process() +print("y =", repr(engine.output_variable("mSteer").value)) +# > y = array([0.6666665 , 0.62179477, 0.5 , 0.37820523, 0.3333335 ]) +print("ỹ =", repr(engine.output_variable("mSteer").fuzzy_value())) +# > ỹ = array(['0.000/left + 1.000/right', +# '0.250/left + 0.750/right', +# '0.500/left + 0.500/right', +# '0.750/left + 0.250/right', +# '1.000/left + 0.000/right'], dtype='Contributing All contributions are welcome, provided they follow the following guidelines: