Code Monkey home page Code Monkey logo

fuzzylite's Introduction

fuzzylite 7.0 (in progress)

A Fuzzy Logic Control Library in C++

fuzzylite

by Juan Rada-Vilela, PhD

License: GPL v3
License: Paid

Linux Medium Build
macOS Medium Build
Windows Medium Build

Coverage Status

The FuzzyLite Libraries for Fuzzy Logic Control refer to fuzzylite (C++), pyfuzzylite (Python), and jfuzzylite (Java).

The goal of the FuzzyLite Libraries is to easily design and efficiently operate fuzzy logic controllers following an object-oriented programming model with minimal dependency on external libraries.

fuzzylite is dual-licensed under the GNU GPL 3.0 and under a proprietary license for commercial purposes.

You are strongly encouraged to support the development of the FuzzyLite Libraries by purchasing a license of QtFuzzyLite.

QtFuzzyLite is the best graphical user interface available to easily design and directly operate fuzzy logic controllers in real time. Available for Windows, Mac, and Linux, its goal is to significantly speed up the design of your fuzzy logic controllers, while providing a very useful, functional and beautiful user interface. Please, download it and check it out for free at fuzzylite.com/downloads.

Visit fuzzylite.com/documentation

(6) Controllers: Mamdani, Takagi-Sugeno, Larsen, Tsukamoto, Inverse Tsukamoto, Hybrid

(25) Linguistic terms: (5) Basic: Triangle, Trapezoid, Rectangle, Discrete, SemiEllipse. (8) Extended: Bell, Cosine, Gaussian, GaussianProduct, PiShape, SigmoidDifference, SigmoidProduct, Spike. (7) Edges: Arc, Binary, Concave, Ramp, Sigmoid, SShape, ZShape. (3) Functions: Constant, Linear, Function. (2) Special: Aggregated, Activated.

(7) Activation methods: General, Proportional, Threshold, First, Last, Lowest, Highest.

(9) Conjunction and Implication (T-Norms): Minimum, AlgebraicProduct, BoundedDifference, DrasticProduct, EinsteinProduct, HamacherProduct, NilpotentMinimum, LambdaNorm, FunctionNorm.

(11) Disjunction and Aggregation (S-Norms): Maximum, AlgebraicSum, BoundedSum, DrasticSum, EinsteinSum, HamacherSum, NilpotentMaximum, NormalizedSum, UnboundedSum, LambdaNorm, FunctionNorm.

(7) Defuzzifiers: (5) Integral: Centroid, Bisector, SmallestOfMaximum, LargestOfMaximum, MeanOfMaximum. (2) Weighted: WeightedAverage, WeightedSum.

(7) Hedges: Any, Not, Extremely, Seldom, Somewhat, Very, Function.

(3) Importers: FuzzyLite Language fll, Fuzzy Inference System fis, Fuzzy Control Language fcl.

(7) Exporters: C++, Java, FuzzyLite Language fll, FuzzyLite Dataset fld, R script, Fuzzy Inference System fis, Fuzzy Control Language fcl.

(30+) Examples of Mamdani, Takagi-Sugeno, Tsukamoto, and Hybrid controllers from fuzzylite, Octave, and Matlab, each included in the following formats: C++, Java, fll, fld, R, fis, and fcl.

FuzzyLite Language

#File: ObstacleAvoidance.fll
Engine: ObstacleAvoidance
InputVariable: obstacle
  enabled: true
  range: 0.000 1.000
  lock-range: false
  term: left Ramp 1.000 0.000
  term: right Ramp 0.000 1.000
OutputVariable: mSteer
  enabled: true
  range: 0.000 1.000
  lock-range: false
  aggregation: Maximum
  defuzzifier: Centroid 100
  default: nan
  lock-previous: false
  term: left Ramp 1.000 0.000
  term: right Ramp 0.000 1.000
RuleBlock: mamdani
  enabled: true
  conjunction: none
  disjunction: none
  implication: AlgebraicProduct
  activation: General
  rule: if obstacle is left then mSteer is right
  rule: if obstacle is right then mSteer is left
//File: ObstacleAvoidance.cpp
#include <fl/Headers.h>

fl::Engine* engine = fl::FllImporter().fromFile("ObstacleAvoidance.fll");

C++

//File: ObstacleAvoidance.cpp
#include <fl/Headers.h>

using namespace fuzzylite;

Engine* engine = new Engine;
engine->setName("ObstacleAvoidance");
engine->setDescription("");

InputVariable* obstacle = new InputVariable;
obstacle->setName("obstacle");
obstacle->setDescription("");
obstacle->setEnabled(true);
obstacle->setRange(0.000, 1.000);
obstacle->setLockValueInRange(false);
obstacle->addTerm(new Ramp("left", 1.000, 0.000));
obstacle->addTerm(new Ramp("right", 0.000, 1.000));
engine->addInputVariable(obstacle);

OutputVariable* mSteer = new OutputVariable;
mSteer->setName("mSteer");
mSteer->setDescription("");
mSteer->setEnabled(true);
mSteer->setRange(0.000, 1.000);
mSteer->setLockValueInRange(false);
mSteer->setAggregation(new Maximum);
mSteer->setDefuzzifier(new Centroid(100));
mSteer->setDefaultValue(fl::nan);
mSteer->setLockPreviousValue(false);
mSteer->addTerm(new Ramp("left", 1.000, 0.000));
mSteer->addTerm(new Ramp("right", 0.000, 1.000));
engine->addOutputVariable(mSteer);

RuleBlock* mamdani = new RuleBlock;
mamdani->setName("mamdani");
mamdani->setDescription("");
mamdani->setEnabled(true);
mamdani->setConjunction(fl::null);
mamdani->setDisjunction(fl::null);
mamdani->setImplication(new AlgebraicProduct);
mamdani->setActivation(new General);
mamdani->addRule(Rule::parse("if obstacle is left then mSteer is right", engine));
mamdani->addRule(Rule::parse("if obstacle is right then mSteer is left", engine));
engine->addRuleBlock(mamdani);
using namespace fuzzylite;

std::string status;
if (not engine->isReady(&status))
    throw Exception("[engine error] engine is not ready:\n" + status, FL_AT);

InputVariable* obstacle = engine->getInputVariable("obstacle");
OutputVariable* steer = engine->getOutputVariable("steer");

for (int i = 0; i <= 50; ++i){
    scalar location = obstacle->getMinimum() + i * (obstacle->range() / 50);
    obstacle->setValue(location);
    engine->process();
    FL_LOG("obstacle.input = " << Op::str(location) << 
        " => " << "steer.output = " << Op::str(steer->getValue()));
}

Once you have an engine written in C++, you can compile it to create an executable file which links to the fuzzylite library. The linking can be either static or dynamic. Basically, the differences between static and dynamic linking are the following.

Static linking includes the fuzzylite library into your executable file, hence increasing its size, but the executable no longer needs to have access to the fuzzylite library files.

Dynamic linking does not include the fuzzylite library into your executable file, hence reducing its size, but the executable needs to have access to the fuzzylite shared library file. When using dynamic linking, make sure that the shared library files are either in the same directory as the executable, or are reachable via environmental variables:

rem Windows:
set PATH="\path\to\fuzzylite\release\bin;%PATH%"
#Unix:
export LD_LIBRARY_PATH="/path/to/fuzzylite/release/bin/:$LD_LIBRARY_PATH"

Windows

The commands to compile your engine in Windows are the following:

C++11 (default)

rem static linking:
cl.exe ObstacleAvoidance.cpp fuzzylite-static.lib /Ipath/to/fuzzylite /EHsc /MD
rem dynamic linking:
cl.exe ObstacleAvoidance.cpp fuzzylite.lib /Ipath/to/fuzzylite /DFL_IMPORT_LIBRARY /EHsc /MD 

C++98

rem static linking:
cl.exe ObstacleAvoidance.cpp fuzzylite-static.lib /Ipath/to/fuzzylite /DFL_CPP98=ON /EHsc /MD
rem dynamic linking:
cl.exe ObstacleAvoidance.cpp fuzzylite.lib /Ipath/to/fuzzylite /DFL_IMPORT_LIBRARY /DFL_CPP98=ON /EHsc /MD 

Unix

The commands to compile your engine in Unix are the following:

C++11 (default)

#static linking
g++ ObstacleAvoidance.cpp -o ObstacleAvoidance -I/path/to/fuzzylite -L/path/to/fuzzylite/release/bin -lfuzzylite-static --std=c++11
#dynamic linking
g++ ObstacleAvoidance.cpp -o ObstacleAvoidance -I/path/to/fuzzylite -L/path/to/fuzzylite/release/bin -lfuzzylite -Wno-non-literal-null-conversion

C++98

#static linking
g++ ObstacleAvoidance.cpp -o ObstacleAvoidance -I/path/to/fuzzylite -L/path/to/fuzzylite/release/bin -lfuzzylite-static -DFL_CPP98=ON
#dynamic linking
g++ ObstacleAvoidance.cpp -o ObstacleAvoidance -I/path/to/fuzzylite -L/path/to/fuzzylite/release/bin -lfuzzylite -DFL_CPP98=ON -Wno-non-literal-null-conversion

Alternatively, you can use CMake to build your project linking to fuzzylite. Please, refer to the example application available at examples/application.

You can build the fuzzylite library from source using CMake (cmake.org).

Check .github/workflows for details.

Unix

cmake -B build/ -G"Unix Makefiles"  .
cmake --build build/ --parallel
ctest --test-dir build/

Windows

cmake -B build/ -G"NMake Makefiles" .
cmake --build build/
ctest --test-dir build/

Building Options

The following building options available:

-DFL_USE_FLOAT=ON builds the binaries using the fl::scalar data type as a float instead of double. By default, the binaries are built using -DFL_USE_FLOAT=OFF. If fuzzylite is built with -DFL_USE_FLOAT=ON, then the applications linking to fuzzylite also need to specify this compilation flag.

-DFL_CPP98=ON builds binaries using C++98 features instead of C++11. By default, the binaries are built using -DFL_CPP98=OFF. If you use C++98, you will not be able to benchmark the performance of your engine using the Benchmark class, and you will not be able to run any of the tests.

-DFL_BACKTRACE=OFF disables the backtrace information in case of errors. By default, the binaries are built using -DFL_BACKTRACE=ON. In Windows, the backtrace information requires the external library dbghelp, which is generally available in your system.

Documentation

The source code of fuzzylite is very well documented using doxygen formatting, and the documentation is available at fuzzylite.com/documentation. If you want to generate the documentation locally, you can produce the html documentation from the file Doxyfile using the command line: doxygen Doxyfile. The documentation will be created in the documentation folder.

After building from source, the following are the relevant binaries that will be created in Release mode. In Debug mode, the file names end with -debug (e.g., fuzzylite-debug.exe).

Windows

  • console application: fuzzylite.exe
  • shared library: fuzzylite.dll, fuzzylite.lib
  • static library: fuzzylite-static.lib

Linux

  • console application: fuzzylite
  • shared library: libfuzzylite.so
  • static library: libfuzzylite-static.a

Mac

  • console application: fuzzylite
  • shared library: libfuzzylite.dylib
  • static library: libfuzzylite-static.a

Console

The console application of fuzzylite allows you to import and export your engines. Its usage can be obtained executing the console binary. In addition, the console can be set in interactive mode. The FuzzyLite Interactive Console allows you to evaluate a given controller by manually providing the input values. The interactive console is triggered by specifying an input file and an output format. For example, to interact with the ObstacleAvoidance controller, the interactive console is launched as follows:

fuzzylite -i ObstacleAvoidance.fll -of fld

All contributions are welcome, provided they follow the following guidelines:

  • Source code is consistent with standards in the library
  • Contribution is properly documented and tested, raising issues where appropriate
  • Contribution is licensed under the FuzzyLite License

If you are using the FuzzyLite Libraries, please cite the following reference in your article:

Juan Rada-Vilela. The FuzzyLite Libraries for Fuzzy Logic Control, 2018. URL https://fuzzylite.com.

Or using bibtex:

@misc{fl::fuzzylite,
    author={Juan Rada-Vilela},
    title={The FuzzyLite Libraries for Fuzzy Logic Control},
    url={https://fuzzylite.com},
    year={2018}
}

fuzzylite® is a registered trademark of FuzzyLite Limited
jfuzzylite™ is a trademark of FuzzyLite Limited
pyfuzzylite™ is a trademark of FuzzyLite Limited
QtFuzzyLite™ is a trademark of FuzzyLite Limited

fuzzylite's People

Contributors

alexvins avatar amdmi3 avatar cjxd avatar jcrada avatar josch avatar mixaill avatar sguazt avatar vmarkovtsev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fuzzylite's Issues

Please honor CMAKE_CXX_FLAGS and CMAKE_SHARED_LINKER_FLAGS

Instead of overwriting CMAKE_CXX_FLAGS and CMAKE_SHARED_LINKER_FLAGS, please honor their previously set values and just append to them. This is for example important to pass hardening flags to the build. The following patch fixes the issue:

--- a/fuzzylite/CMakeLists.txt
+++ b/fuzzylite/CMakeLists.txt
@@ -53,12 +53,12 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY bin)
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)

 if(UNIX)
-    set(CMAKE_CXX_FLAGS "-pedantic -Werror -Wall -Wextra")
+    set(CMAKE_CXX_FLAGS "-pedantic -Werror -Wall -Wextra ${CMAKE_CXX_FLAGS}")
     set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
     set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")

     if(NOT APPLE)
-        set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined") #To avoid undefined methods in library
+        set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined ${CMAKE_SHARED_LINKER_FLAGS}") #To avoid undefined methods in library
     endif()
 endif()

Enhanced antecedents in fuzzy rules

Currently, the fuzzy rules allow only antecedents of the form Variable is [hedge]* Term. To enhance the antecedents, the goal is to be able to incorporate functions. For example, if 0.5 * Variable is [hedge]* Term multiplies the activation of the proposition by 0.5.

Threshold in First and Last activation methods

The First and Last activation methods should have a threshold value in order to activate the first and last rule (respectively) whose activation degree is greater than the given threshold.

Activation methods in rule blocks

After having renamed the Activation operators to Implication operators, the next step is to introduce Activation methods to Rule Blocks. An activation method determines the activation degrees of the rules and determines whether the rules are activated. For example, the Threshold activation method consists of activating only those rules whose activation degrees are higher than a given threshold.

As such, it is now important to highlight the difference between Implication and Activation: Implication refers to the TNorm, and Activation refers to a method to activate rules.

Run tests automatically with travis

Currently travis only compiles the code, it does not run the tests. This have caused broken tests to be included in the develop branch (discussed in issue #57 ).

Coverity test and issues

Coverity is a plugin for static code analysis freely available for github repositories. Issues should be addressed.

ImEx: Activation methods

The new activation methods need to be properly exported to C++ and Java. In addition, [Fis|Fcl]Exporter need to stop exporting fuzzylite features not available in Matlab or FCL in order to avoid errors in such tools when importing their respective files produced by fuzzylite.

test hardcodes path

Hi,

in fuzzylite/test/BenchmarkTest.cpp the path to the test data is hardcoded as ../../examples/ this will break the test if they are not run from a path two levels deeper into the source than the examples directory. CMake supports out-of-source builds and if the "wrong" path is picked, then running the tests will fail.

This for example fails under Debian where CMake projects are by default built inside a subdirectory of the toplevel directory.

is scalar and float interchangeable ?

hello
Can I use float instead of scalar in input variables ?
I tried it and it works. I want to know in which cases It doesn't work ?
If they are interchangeable so, why using non-standard type ?

Use compiler instead of CMake to define FL_[PLATFORM]

When Fuzzylite used as a third party library FL_WINDOWS, FL_UNIX, FL_APPLE definitions can not be not defined!

I propose to add this code to fuzzylite.h

#ifdef _WIN32
#define FL_WINDOWS
#endif

#if defined(unix) || defined(__unix__) || defined(__unix)
#define FL_UNIX
#endif

#ifdef __APPLE__
#define FL_APPLE
#endif

Evaluate adding a header-only library

A header only library contains all the headers and sources in a single file, thereby facilitating the use of the library. It would be interesting to evaluate the possibilities of doing so.

Allow to set the installation path for the shared library

On Debian and its derivative, shared libraries are not installed into /usr/lib but into /usr/lib/ depending on their architecture because of multiarch.

Please modify your CMakeLists.txt so that it allows the caller to specify where to install the library to. The following patch should do:

--- a/fuzzylite/CMakeLists.txt
+++ b/fuzzylite/CMakeLists.txt
@@ -119,11 +119,14 @@ set_target_properties(fl-bin PROPERTIES
 #target_link_libraries(fl-bin fl-shared ${FL_LIBS})
 target_link_libraries(fl-bin fl-static ${FL_LIBS})

+if(NOT CMAKE_INSTALL_LIBDIR)
+    set(CMAKE_INSTALL_LIBDIR lib)
+endif()

 install(TARGETS fl-bin fl-shared fl-static
         RUNTIME DESTINATION bin
-        LIBRARY DESTINATION lib
-        ARCHIVE DESTINATION lib
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
         )

 install(DIRECTORY fl/ DESTINATION include/fl)

Please link with -lrt for clock_gettime

Hi,

fuzzylite/src/Console.cpp uses clock_gettime which needs to be linked with -lrt for glibc versions before 2.17. Ubuntu Precise 12.04 LTS uses eglibc 2.15 so it needs this linker flag. The following patch fixes it:

--- a/fuzzylite/CMakeLists.txt
+++ b/fuzzylite/CMakeLists.txt
@@ -107,7 +107,7 @@ set_target_properties(fl-shared PROPERTIES COMPILE_DEFINITIONS "FL_EXPORT_LIBRAR
 if (UNIX)
 set_target_properties(fl-shared PROPERTIES COMPILE_FLAGS "-fPIC")
 endif()
-target_link_libraries(fl-shared ${FL_LIBS})
+target_link_libraries(fl-shared ${FL_LIBS} rt)

 add_library(fl-static STATIC ${fl-headers} ${fl-sources})
 set_target_properties(fl-static PROPERTIES OUTPUT_NAME fuzzylite-static)
@@ -123,7 +123,7 @@ set_target_properties(fl-bin PROPERTIES OUTPUT_NAME fuzzylite IMPORT_PREFIX tmp-
 set_target_properties(fl-bin PROPERTIES DEBUG_POSTFIX d)
 #set_target_properties(fl-bin PROPERTIES COMPILE_DEFINITIONS "FL_IMPORT_LIBRARY")
 #target_link_libraries(fl-bin fl-shared ${FL_LIBS})
-target_link_libraries(fl-bin fl-static ${FL_LIBS})
+target_link_libraries(fl-bin fl-static ${FL_LIBS} rt)


 install(TARGETS fl-bin fl-shared fl-static

Shared library calls exit()

The fuzzylite shared library calls exit() in fuzzylite/src/Exception.cpp. This should not happen in a shared library and instead an appropriate error code should be returned to the calling program.

Fails to build from source with MSVC

When compiling with MSVC, the following errors occur:

1>fuzzylite\src\imex\FldExporter.cpp(171): error C2039: 'max' : is not a member of 'std'
1>fuzzylite\src\imex\FldExporter.cpp(171): error C3861: 'max': identifier not found
1>fuzzylite\src\imex\FldExporter.cpp(188): error C2039: 'max' : is not a member of 'std'
1>fuzzylite\src\imex\FldExporter.cpp(188): error C3861: 'max': identifier not found
1>fuzzylite\src\norm\s\NilpotentMaximum.cpp(35): error C2039: 'max' : is not a member of 'std'
1>fuzzylite\src\norm\s\NilpotentMaximum.cpp(35): error C3861: 'max': identifier not found

The fix for this is to #include <algorithm>. The problem was discovered through vcmi and is discussed here vcmi/vcmi#48 and here vcmi/vcmi#49

Pull request #12 fixes this and other issues.

Please allow to set CMAKE_VERBOSE_MAKEFILE

As it currently is, the build will always be non-verbose. But verbose builds are important for automatic analyzers of build logs. So it is important that CMAKE_VERBOSE_MAKEFILE can be set from the outside. The following patch fixes the issue:

--- a/fuzzylite/CMakeLists.txt
+++ b/fuzzylite/CMakeLists.txt
@@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 2.8)

 project(fuzzylite CXX)

-set(CMAKE_VERBOSE_MAKEFILE false)
+if(NOT CMAKE_VERBOSE_MAKEFILE)
+    set(CMAKE_VERBOSE_MAKEFILE false)
+endif()

 set(FL_VERSION 5.0)
 add_definitions(-DFL_VERSION="${FL_VERSION}")

fuzzylite builds a shared library without versioned SONAME

The shared library created after compiling fuzzylite has an SONAME that does not contain any versioning information, either after the .so or before it and set off by a hyphen. It cannot
therefore be represented in the shlibs system, and if linked by binaries its interface cannot safely change. There is no backward-compatible way to migrate programs linked against it to a
new ABI.

Thus in effect, I cannot currently package fuzzylite for Debian, nor can applications reasonable use fuzzylite as a shared library.

Here is a good guide on the topic: http://www.netfort.gr.jp/~dancer/column/libpkg-guide/libpkg-guide.html

Please do not statically link fuzzylite binary on non-win32

On unix systems it is preferred to dynamically link binaries. Please consider the following patch:

--- a/fuzzylite/CMakeLists.txt
+++ b/fuzzylite/CMakeLists.txt
@@ -135,8 +135,11 @@ set_target_properties(fl-bin PROPERTIES
 set_target_properties(fl-bin PROPERTIES OUTPUT_NAME fuzzylite IMPORT_PREFIX tmp-) #To prevent LNK1149 in Windows
 set_target_properties(fl-bin PROPERTIES DEBUG_POSTFIX d)
 #set_target_properties(fl-bin PROPERTIES COMPILE_DEFINITIONS "FL_IMPORT_LIBRARY")
-#target_link_libraries(fl-bin fl-shared ${FL_LIBS})
-target_link_libraries(fl-bin fl-static ${FL_LIBS})
+if (WIN32)
+    target_link_libraries(fl-bin fl-static ${FL_LIBS})
+else()
+    target_link_libraries(fl-bin fl-shared ${FL_LIBS})
+endif()

 if(NOT CMAKE_INSTALL_LIBDIR)
     set(CMAKE_INSTALL_LIBDIR lib)

Undefined behavior in va_start, compilation error

clang 4.0.0:

/tmp/fuzzylite/fuzzylite/./fl/Operation.h:1044:24: error: passing an object that undergoes default argument promotion to 'va_start' has undefined behavior [-Werror,-Wvarargs]
        va_start(args, first);
                       ^
/tmp/fuzzylite/fuzzylite/./fl/Operation.h:1039:19: note: parameter of type 'float' is declared here
            float first, ...) {
                  ^

export-examples and benchmarks of fuzzylite not working

Hi,

doing fuzzylite export-examples and fuzzylite benchmarks benchmarks does not work because fuzzylite/src/Console.cpp hardcodes the path /home/jcrada/Development/fl/fuzzylite/examples/original which does not exist on my system.

UnboundedSum SNorm -- UnboundedDifference TNorm

Currently, fuzzylite treats sum and probor SNorms as the same norm in fis files. However, the sum is a sum defined as $a+b$ and the probor is the AlgebraicSum defined as $a + b - (a * b)$. As suggested by @sguazt in #48 , this needs to change.

The solution is to create a new UnboundedSum that provides $a+b$. The following classes need to be updated:

  • FclExporter: return "USUM"
  • FclImporter: create UnboundedSum on "USUM"
  • FisImporter: Split sum and probor into UnboundedSum and AlgebraicSum, respectively
  • FisExporter: Export sum and probor accordingly.
  • SNormFactory: Add UnboundedSum to the factory.

Likewise, the UnboundedDifference TNorm should be implemented, and the respective classes need to be changed.

some bugs

Hello
When I forgot to define A's membership function in the following code, the result was exception without significant error message.
Also, I think it's a good idea to add in the documentation a list of supported membership functions with parameters (it was difficult for me to guess
that the two parameters of ZShape were [start .. end], instead of [center .. delta] like in pyfuzzy. In reality, I didn't guess, I was obliged to read ZShape.cpp)
finally, comments between (**), on fcl, doesn't work. is there a way to add comments ?
I don't know "OR:MAX;" doesn't work and I must use "OR : MAX;" ?
I didn't explore your code yet ( I'm too busy this days :( ), but I don't think that a syntactical parser (like YACC) is used inside.
if it is true, it's a good true to think about it. Adding this features will be easier.

I have a question about license, If I use your software as shared library, is that allowed ?

FUNCTION_BLOCK IMP
    VAR_INPUT
        A :  REAL;
    END_VAR
    VAR_OUTPUT
         RES : REAL;
    END_VAR

    FUZZIFY A
        RANGE := (0.000 .. 1.000);
        TERM  CRTE:=  ;
    END_FUZZIFY


    DEFUZZIFY RES
        RANGE :=(0.000..100.00)
        TERM B:= 0;
        TERM M:= 1;
        TERM H:= 100;
        DEFAULT := 0;
        METHOD : COGS;
    END_DEFUZZIFY

    RULEBLOCK first
        OR : MAX;
        AND : MIN;
        RULE 0: if A is CRTE then  RES is B;
    END_RULEBLOCK

END_FUNCTION_BLOCK
~$./fuzzylite -i test1.fcl -o a.cpp
/src/Exception.cpp [173]:[unexpected signal 11] Segmentation fault
BACKTRACE:
/usr/lib/libfuzzylite.so.5.0(_ZN2fl9Exception11btCallStackEv+0x196) [0x7f66c61e45a6]
/usr/lib/libfuzzylite.so.5.0(_ZN2fl9Exception13signalHandlerEi+0x1dc) [0x7f66c61e5dfc]
/lib/x86_64-linux-gnu/libc.so.6(+0x36d40) [0x7f66c5afad40]
/usr/lib/libfuzzylite.so.5.0(_ZNK2fl11FclImporter9parseTermERKSsPKNS_6EngineE+0x798) [0x7f66c62140c8]
/usr/lib/libfuzzylite.so.5.0(_ZNK2fl11FclImporter14processFuzzifyERKSsPNS_6EngineE+0x733) [0x7f66c620e5d3]
/usr/lib/libfuzzylite.so.5.0(_ZNK2fl11FclImporter12processBlockERKSsS2_PNS_6EngineE+0xc7) [0x7f66c6207217]
/usr/lib/libfuzzylite.so.5.0(_ZNK2fl11FclImporter10fromStringERKSs+0x1be1) [0x7f66c6211b91]
/usr/lib/libfuzzylite.so.5.0(_ZN2fl7Console7processERKSsRSoS2_S2_RKSt3mapISsSsSt4lessISsESaISt4pairIS1_SsEEE+0xa5) [0x7f66c61c8255]
/usr/lib/libfuzzylite.so.5.0(_ZN2fl7Console7processERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE+0x508) [0x7f66c61c99a8]
/usr/lib/libfuzzylite.so.5.0(_ZN2fl7Console4mainEiPPc+0x43) [0x7f66c61be4a3]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f66c5ae5ec5]
./fuzzylite() [0x400b80]

{at /src/Exception.cpp::signalHandler() [line:141]}

BACKTRACE:
/usr/lib/libfuzzylite.so.5.0(_ZN2fl9Exception11btCallStackEv+0x196) [0x7f66c61e45a6]
/usr/lib/libfuzzylite.so.5.0(_ZN2fl9Exception14catchExceptionERKSt9exception+0x195) [0x7f66c61e54d5]
/usr/lib/libfuzzylite.so.5.0(_ZN2fl9Exception13signalHandlerEi+0x36e) [0x7f66c61e5f8e]
/lib/x86_64-linux-gnu/libc.so.6(+0x36d40) [0x7f66c5afad40]
/usr/lib/libfuzzylite.so.5.0(_ZNK2fl11FclImporter9parseTermERKSsPKNS_6EngineE+0x798) [0x7f66c62140c8]
/usr/lib/libfuzzylite.so.5.0(_ZNK2fl11FclImporter14processFuzzifyERKSsPNS_6EngineE+0x733) [0x7f66c620e5d3]
/usr/lib/libfuzzylite.so.5.0(_ZNK2fl11FclImporter12processBlockERKSsS2_PNS_6EngineE+0xc7) [0x7f66c6207217]
/usr/lib/libfuzzylite.so.5.0(_ZNK2fl11FclImporter10fromStringERKSs+0x1be1) [0x7f66c6211b91]
/usr/lib/libfuzzylite.so.5.0(_ZN2fl7Console7processERKSsRSoS2_S2_RKSt3mapISsSsSt4lessISsESaISt4pairIS1_SsEEE+0xa5) [0x7f66c61c8255]
/usr/lib/libfuzzylite.so.5.0(_ZN2fl7Console7processERKSt3mapISsSsSt4lessISsESaISt4pairIKSsSsEEE+0x508) [0x7f66c61c99a8]
/usr/lib/libfuzzylite.so.5.0(_ZN2fl7Console4mainEiPPc+0x43) [0x7f66c61be4a3]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f66c5ae5ec5]
./fuzzylite() [0x400b80]

Travis should use cached docker images

I saw your builds on Travis take great amount of time. I'd like to suggest a way of improving their performance.

On each job of a build you build a docker image, which doesn't vary a lot – all but the compiler are the same. I'd like to suggest you use docker hub to have automated builds and only download the image instead of building it each time.

Depending on how messy you're willing to get, you can set it up so that you can have base system (all but the compiler) built and only install compiler on travis, or you can create a directory per each of the compilers and have docker hub build all of them for you (this would involve specifying compiler as tag of the image).

Hub will build an image for you whenever there is a new commit in the repo, so worst case scenario you would be one commit behind on the image freshness, this can be worked around (say by using another repo; pushing a dummy commit to trigger rebuild on hub or manually triggering build).

Right now it takes 6 minutes to build the image, while the whole job takes 11 minutes: https://travis-ci.org/fuzzylite/fuzzylite/jobs/194574656#L106. For comparison, pulling a pre-built image with all required packages takes only 30s: https://travis-ci.org/OpenRCT2/OpenRCT2/jobs/202723200#L266.

It would be really kind of you to conserve the (finite and limited) resources Travis offers.

See https://hub.docker.com/.

Delay while building

I'm curious as to why we are waiting 3 seconds before we start the build?
Tt doesn't seem to serve any purpose and only slows down the development cycle.

Create unit tests using Catch

Unit tests are an important part of development to ensure the operation of the software does not break over time. While the results of the fuzzylite library are thoroughly and accurately tested in over 30 (Mamdani and Takagi-Sugeno) examples against the results obtained with the Matlab fuzzy logic toolbox, the fuzzylite library lacks formal unit tests. An effort should be made to progressively create unit tests for each class in the library.

My research suggests that Catch (github.com/philsquared/Catch) is the most appropriate framework to develop the unit tests given that (1) the tests are very easy to create, read, and incorporate, (2) Catch can be used as a header-only library, thereby only requiring the inclusion of a header file, and (3) Catch is free, open source, and has a GPL compatible open source license (Boost Software License - Version 1.0).

Documentation

The headers need to be documented using Doxygen and Javadoc.

Change debug postfix of binaries

In fuzzylite 5, the binaries are appended a d to indicate they are built in debug mode.
In fuzzylite 6, the d changes to debug for the sake of clarity. As such, the names of the debug binaries are in version 6 are:

fuzzylite-debug
fuzzylite-tests-debug
libfuzzylite-debug.[dylib, so]
libfuzzylite-static-debug.a

Remove hedges from Rule

In order to simplify the Rule class, the map of hedges should be removed, forcing every antecedent and consequent to create their own instances of the hedge via the HedgeFactory.

Names of variables in [Cpp|Java]Exporter

Currently, all the variable names get exported as "[input|output]Variable#" in order to avoid dealing with valid names in their respective target languages. However, it would be great to export the variable names too.

`Function::load(formula)` resets map of variables

The method Function::load(formula) calls Function::unload(), which resets the variables map.

The problem is that the following code would not work:

Function f; f.variables["y"] = 0.0; f.load("2*y"); //Throws exception: variable 'y' not registered

The solution is to remove the call to unload() from load(), leaving the reset of the variables map to the developer, if necessary. Normally, the developer will not care about the map of variables unless he/she is using custom function variables, something that seems has not been possible with the current code.

Default projects

Create default projects in NetBeans, Eclipse, Visual Studio, and Xcode to utilise the fuzzylite library

Make members private

Perhaps, the members of classes should be private (instead of protected, as generally the case) and should be accessible via getters and setters.

Simplify TakagiSugeno defuzzification

TakagiSugeno fuzzy aggregation (formerly referred to as accumulation) and implication (formerly referred to as activation) operators are useless in Matlab for the defuzzification of output variables. However, for design (and experimental) purposes, fuzzylite versions 4.0 and 5.0 have attempted to reuse these fuzzy operators in TakagiSugeno controllers. The result of such a redesign is that the typical defuzzification of TakagiSugeno controllers can be achieved only when setting the implication and aggregation operators to fl::null. Otherwise, the defuzzification utilises these fuzzy operators to compute the aggregation and implication with them.

Mathematically, the typical TakagiSugeno defuzzification is given by $y = \dfrac{\sum_i w_iz_i}{\sum_i w_i}$, where $w_i$ is the activation degree of term $i$, and $z_i = \mu_i(w_i)$. With the fuzzy implication and aggregation operators, the typical sum and multiplication are performed utilising the respective implication and aggregation operators.

Hence, when Matlab's examples arbitrary select any implication and aggregation operators (producing the same results because these are not used), fuzzylite actually uses these operators and hence produces different results.

In summary, to achieve the typical defuzzification of TakagiSugeno, it is necessary to set the implication and aggregation operators to fl::null.

It remains to be decided whether this operation in fuzzylite is useful. Any comments on this are more than welcome.

Some information on the topic can be found at:

http://fuzzylite.github.io/fuzzylite/d7/dde/classfl_1_1_weighted_average.html

http://www.fuzzylite.com/cpp/#Weighted_Defuzzifiers

doxygen files in git

There is doxygen documentation in git, for example documentation/ui/header.html and documentation/ui/footer.html. Autogenerated files should be kept in git.

Create CMake package for fuzzylite

In order to use fuzzylite from a new CMake project, it would be ideal for fuzzylite to provide a fuzzylite.cmake file such that it could be imported by using from new project:

find_package (fuzzylite) 
if (FL_FOUND) 
  include_directories(${FL_INCLUDE_DIRS})
  target_link_libraries (project-binary ${FL_LIBRARIES})
endif (FL_FOUND)

Add support for negation in Function using `-`

Currently, to negate a value in the Function term is necessary to utilise symbol ~. Ideally, the Shunting-Yard algorithm would automatically identify when - is utilised for subtraction and when for negation.

Utilise iterators instead of std::size_t

In most places, the containers like std::vector are accessed by their indices utilising std::size_t. This generates warnings in 64 bit compilers under windows, not to mention that reduces the portability.

To address this, the code should utilise instead:
for (std::vector<T>::iterator it = x.begin(); it != x.end() ;++it)
and
for (std::vector<T>::size_type i = 0; i < x.size(); ++i)

could the -Wunused-variable warnings be solved?

Hi,

with gcc-5 one gets multiple warnings of the following sort:

/tmp/fuzzylite/fuzzylite/./fl/fuzzylite.h:119:18: warning: ‘fl::inf’ defined but not used [-Wunused-variable]
     const scalar inf = std::numeric_limits<scalar>::infinity();
                  ^

Since they are emitted by nearly every single compilation unit, they needlessly clutter the build log. Could something be done to remove the warning? For example by adding an __attribute__(unused)?

Fails to compile with gcc 6 due to deprecated std::auto_ptr

Hi,

I was made aware that fuzzylite fails to build from source with gcc 6 on Debian:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=811880

The reason seems to be that std::auto_ptr got deprecated in gcc 6 because it is deprecated in the C++0x standard. Instead, std::unique_ptr or std::shared_ptr should be used as appropriate. A good summary can be found in the following stackoverflow question:

http://stackoverflow.com/questions/2404115/is-auto-ptr-deprecated

Since gcc will probably not drop std::auto_ptr, one solution might be to just compile fuzzylite without -Wdeprecated-declarations.

The other, more long term solution would be to repace std::auto_ptr by the appropriate smart pointer.

Thanks!

cheers, josch

Bug on NormalizedSum

The computation of the NormalizedSum is not correct due to the missing aggrupation of terms $(a+b)$ within parenthesis.

Add lockValueInRange in InputVariable

Refactoring OutputVariable::lockValueInRange to make it available to InputVariables would allow lock the range on the input values, too. As such, when evaluating the Antecedent of a Rule, if the input value is beyond the range of the variable, the input value is truncated to its respective limit, thereby strictly limiting the output values to the range of the input values.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.