diff options
Diffstat (limited to 'fuzzylite/fl/hedge')
-rw-r--r-- | fuzzylite/fl/hedge/Any.h | 47 | ||||
-rw-r--r-- | fuzzylite/fl/hedge/Extremely.h | 53 | ||||
-rw-r--r-- | fuzzylite/fl/hedge/Hedge.h | 56 | ||||
-rw-r--r-- | fuzzylite/fl/hedge/HedgeFunction.h | 82 | ||||
-rw-r--r-- | fuzzylite/fl/hedge/Not.h | 43 | ||||
-rw-r--r-- | fuzzylite/fl/hedge/Seldom.h | 48 | ||||
-rw-r--r-- | fuzzylite/fl/hedge/Somewhat.h | 44 | ||||
-rw-r--r-- | fuzzylite/fl/hedge/Very.h | 42 |
8 files changed, 295 insertions, 120 deletions
diff --git a/fuzzylite/fl/hedge/Any.h b/fuzzylite/fl/hedge/Any.h index c30b4c7..bf71842 100644 --- a/fuzzylite/fl/hedge/Any.h +++ b/fuzzylite/fl/hedge/Any.h @@ -1,25 +1,17 @@ /* - Author: Juan Rada-Vilela, Ph.D. - Copyright (C) 2010-2014 FuzzyLite Limited - All rights reserved + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> This file is part of fuzzylite. fuzzylite is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. + the terms of the FuzzyLite License included with the software. - fuzzylite is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - for more details. - - You should have received a copy of the GNU Lesser General Public License - along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. - - fuzzylite™ is a trademark of FuzzyLite Limited. + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + fuzzylite is a registered trademark of FuzzyLite Limited. */ #ifndef FL_ANY_H @@ -28,8 +20,20 @@ #include "fl/hedge/Hedge.h" namespace fl { - //Only this hedge has virtual methods due to its special case use. + /** + The Any class is a special Hedge that always returns `1.0`. Its + position with respect to the other hedges is last in the ordered set + (Not, Seldom, Somewhat, Very, Extremely, Any). The Antecedent of a Rule + considers Any to be a syntactically special hedge because it is not + followed by a Term (e.g., `if Variable is any then...`). Amongst hedges, + only Any has virtual methods to be overriden due to its particular case. + + @author Juan Rada-Vilela, Ph.D. + @see Hedge + @see HedgeFactory + @since 4.0 + */ class FL_API Any : public Hedge { public: Any(); @@ -37,11 +41,20 @@ namespace fl { FL_DEFAULT_COPY_AND_MOVE(Any) virtual std::string name() const FL_IOVERRIDE; + + + virtual Complexity complexity() const FL_IOVERRIDE; + + /** + Computes the hedge for the given value + @param x is irrelevant + @return `1.0` + */ virtual scalar hedge(scalar x) const FL_IOVERRIDE; virtual Any* clone() const FL_IOVERRIDE; static Hedge* constructor(); }; - } + #endif /* FL_ANY_H */ diff --git a/fuzzylite/fl/hedge/Extremely.h b/fuzzylite/fl/hedge/Extremely.h index 7ecda66..fbd617a 100644 --- a/fuzzylite/fl/hedge/Extremely.h +++ b/fuzzylite/fl/hedge/Extremely.h @@ -1,25 +1,17 @@ /* - Author: Juan Rada-Vilela, Ph.D. - Copyright (C) 2010-2014 FuzzyLite Limited - All rights reserved + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> This file is part of fuzzylite. fuzzylite is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. + the terms of the FuzzyLite License included with the software. - fuzzylite is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - for more details. - - You should have received a copy of the GNU Lesser General Public License - along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. - - fuzzylite™ is a trademark of FuzzyLite Limited. + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + fuzzylite is a registered trademark of FuzzyLite Limited. */ #ifndef FL_EXTREMELY_H @@ -29,14 +21,35 @@ namespace fl { - class FL_API Extremely : public Hedge { + /** + The Extremely class is a Hedge located fifth in the ordered set + (Not, Seldom, Somewhat, Very, Extremely, Any). + + @author Juan Rada-Vilela, Ph.D. + @see Hedge + @see HedgeFactory + @since 4.0 + */ + class FL_API Extremely FL_IFINAL : public Hedge { public: - std::string name() const; - scalar hedge(scalar x) const; - Extremely* clone() const; + std::string name() const FL_IOVERRIDE; + + Complexity complexity() const FL_IOVERRIDE; + + /** + Computes the hedge for the membership function value @f$x@f$ + @param x is a membership function value + @return @f$ + \begin{cases} + 2x^2 & \mbox{if $x \le 0.5$} \cr + 1-2(1-x)^2 & \mbox{otherwise} \cr + \end{cases}@f$ + */ + scalar hedge(scalar x) const FL_IOVERRIDE; + Extremely* clone() const FL_IOVERRIDE; static Hedge* constructor(); }; - } + #endif /* FL_EXTREMELY_H */ diff --git a/fuzzylite/fl/hedge/Hedge.h b/fuzzylite/fl/hedge/Hedge.h index 011c745..9dac17c 100644 --- a/fuzzylite/fl/hedge/Hedge.h +++ b/fuzzylite/fl/hedge/Hedge.h @@ -1,25 +1,17 @@ /* - Author: Juan Rada-Vilela, Ph.D. - Copyright (C) 2010-2014 FuzzyLite Limited - All rights reserved + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> This file is part of fuzzylite. fuzzylite is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. + the terms of the FuzzyLite License included with the software. - fuzzylite is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - for more details. - - You should have received a copy of the GNU Lesser General Public License - along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. - - fuzzylite™ is a trademark of FuzzyLite Limited. + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + fuzzylite is a registered trademark of FuzzyLite Limited. */ #ifndef FL_HEDGE_H @@ -27,10 +19,24 @@ #include "fl/fuzzylite.h" +#include "fl/Complexity.h" + #include <string> namespace fl { + /** + The Hedge class is the abstract class for hedges. Hedges are utilized + within the Antecedent and Consequent of a Rule in order to modify the + membership function of a linguistic Term. + + @author Juan Rada-Vilela, Ph.D. + @see Antecedent + @see Consequent + @see Rule + @see HedgeFactory + @since 4.0 + */ class FL_API Hedge { public: @@ -41,8 +47,28 @@ namespace fl { } FL_DEFAULT_COPY_AND_MOVE(Hedge) + /** + Returns the name of the hedge + @return the name of the hedge + */ virtual std::string name() const = 0; + + /** + Computes the estimated complexity of applying the hedge + @return the estimated complexity of applying the hedge + */ + virtual Complexity complexity() const = 0; + /** + Computes the hedge for the membership function value @f$x@f$ + @param x is a membership function value + @return the hedge of @f$x@f$ + */ virtual scalar hedge(scalar x) const = 0; + + /** + Creates a clone of the hedge + @return a clone of the hedge. + */ virtual Hedge* clone() const = 0; }; diff --git a/fuzzylite/fl/hedge/HedgeFunction.h b/fuzzylite/fl/hedge/HedgeFunction.h new file mode 100644 index 0000000..bc8930d --- /dev/null +++ b/fuzzylite/fl/hedge/HedgeFunction.h @@ -0,0 +1,82 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_HEDGEFUNCTION_H +#define FL_HEDGEFUNCTION_H + +#include "fl/hedge/Hedge.h" + +#include "fl/term/Function.h" + +namespace fl { + + /** + The HedgeFunction class is a customizable Hedge via Function, which + computes any function based on the @f$x@f$ value. This hedge is not + registered with the HedgeFactory due to issues configuring the formula + within. To register the hedge, a static method with the + constructor needs to be manually created and registered. Please, check the + file `test/hedge/HedgeFunction.cpp` for further details. + + @author Juan Rada-Vilela, Ph.D. + @see Function + @see Hedge + @see HedgeFactory + @since 6.0 + */ + + class FL_API HedgeFunction FL_IFINAL : public Hedge { + private: + Function _function; + public: + explicit HedgeFunction(const std::string& formula = ""); + + std::string name() const FL_IOVERRIDE; + + /** + Returns the reference to the Function + @return the reference to the Function + */ + Function& function(); + + /** + Loads the function with the given formula + @param formula is a valid formula in infix notation + */ + void setFormula(const std::string& formula); + /** + Returns the formula loaded into the function + @return the formula loaded into the function + */ + std::string getFormula() const; + + Complexity complexity() const FL_IOVERRIDE; + + /** + Computes the hedge for the membership function value @f$x@f$ utilizing + the given function via HedgeFunction::setFormula() + @param x is a membership function value + @return the evaluation of the function + */ + scalar hedge(scalar x) const FL_IOVERRIDE; + HedgeFunction* clone() const FL_IOVERRIDE; + + static Hedge* constructor(); + }; +} + +#endif /* FL_HEDGEFUNCTION_H */ + diff --git a/fuzzylite/fl/hedge/Not.h b/fuzzylite/fl/hedge/Not.h index 161fefd..e981ac9 100644 --- a/fuzzylite/fl/hedge/Not.h +++ b/fuzzylite/fl/hedge/Not.h @@ -1,25 +1,17 @@ /* - Author: Juan Rada-Vilela, Ph.D. - Copyright (C) 2010-2014 FuzzyLite Limited - All rights reserved + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> This file is part of fuzzylite. fuzzylite is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. + the terms of the FuzzyLite License included with the software. - fuzzylite is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - for more details. - - You should have received a copy of the GNU Lesser General Public License - along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. - - fuzzylite™ is a trademark of FuzzyLite Limited. + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + fuzzylite is a registered trademark of FuzzyLite Limited. */ #ifndef FL_NOT_H @@ -29,14 +21,31 @@ namespace fl { - class FL_API Not : public Hedge { + /** + The Not class is a Hedge located first in the ordered set + (Not, Seldom, Somewhat, Very, Extremely, Any). + + @author Juan Rada-Vilela, Ph.D. + @see Hedge + @see HedgeFactory + @since 4.0 + */ + class FL_API Not FL_IFINAL : public Hedge { public: std::string name() const FL_IOVERRIDE; + + Complexity complexity() const FL_IOVERRIDE; + + /** + Computes the hedge for the membership function value @f$x@f$ + @param x is a membership function value + @return @f$1-x@f$ + */ scalar hedge(scalar x) const FL_IOVERRIDE; Not* clone() const FL_IOVERRIDE; static Hedge* constructor(); }; - } + #endif /* FL_NOT_H */ diff --git a/fuzzylite/fl/hedge/Seldom.h b/fuzzylite/fl/hedge/Seldom.h index a2a96c2..0bbedbf 100644 --- a/fuzzylite/fl/hedge/Seldom.h +++ b/fuzzylite/fl/hedge/Seldom.h @@ -1,25 +1,17 @@ /* - Author: Juan Rada-Vilela, Ph.D. - Copyright (C) 2010-2014 FuzzyLite Limited - All rights reserved + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> This file is part of fuzzylite. fuzzylite is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. + the terms of the FuzzyLite License included with the software. - fuzzylite is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - for more details. - - You should have received a copy of the GNU Lesser General Public License - along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. - - fuzzylite™ is a trademark of FuzzyLite Limited. + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + fuzzylite is a registered trademark of FuzzyLite Limited. */ #ifndef FL_SELDOM_H @@ -29,14 +21,36 @@ namespace fl { - class FL_API Seldom : public Hedge { + /** + The Seldom class is a Hedge located second in the ordered set + (Not, Seldom, Somewhat, Very, Extremely, Any). + + @author Juan Rada-Vilela, Ph.D. + @see Hedge + @see HedgeFactory + @since 4.0 + */ + class FL_API Seldom FL_IFINAL : public Hedge { public: std::string name() const FL_IOVERRIDE; + + Complexity complexity() const FL_IOVERRIDE; + + /** + Computes the hedge for the membership function value @f$x@f$ + @param x is a membership function value + @return @f$ + \begin{cases} + \sqrt{0.5x} & \mbox{if $x \le 0.5$} \cr + 1-\sqrt{0.5(1-x)} & \mbox{otherwise}\cr + \end{cases} + @f$ + */ scalar hedge(scalar x) const FL_IOVERRIDE; Seldom* clone() const FL_IOVERRIDE; static Hedge* constructor(); }; - } + #endif /* FL_SELDOM_H */ diff --git a/fuzzylite/fl/hedge/Somewhat.h b/fuzzylite/fl/hedge/Somewhat.h index 89a14a6..ccd21ec 100644 --- a/fuzzylite/fl/hedge/Somewhat.h +++ b/fuzzylite/fl/hedge/Somewhat.h @@ -1,25 +1,17 @@ /* - Author: Juan Rada-Vilela, Ph.D. - Copyright (C) 2010-2014 FuzzyLite Limited - All rights reserved + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> This file is part of fuzzylite. fuzzylite is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. + the terms of the FuzzyLite License included with the software. - fuzzylite is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - for more details. - - You should have received a copy of the GNU Lesser General Public License - along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. - - fuzzylite™ is a trademark of FuzzyLite Limited. + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + fuzzylite is a registered trademark of FuzzyLite Limited. */ #ifndef FL_SOMEWHAT_H @@ -29,14 +21,32 @@ namespace fl { - class FL_API Somewhat : public Hedge { + /** + The Somewhat class is a Hedge located third in the ordered set + (Not, Seldom, Somewhat, Very, Extremely, Any). + + @author Juan Rada-Vilela, Ph.D. + @see Hedge + @see HedgeFactory + @since 4.0 + */ + class FL_API Somewhat FL_IFINAL : public Hedge { public: std::string name() const FL_IOVERRIDE; + + + Complexity complexity() const FL_IOVERRIDE; + + /** + Computes the hedge for the membership function value @f$x@f$ + @param x is a membership function value + @return @f$\sqrt{x}@f$ + */ scalar hedge(scalar x) const FL_IOVERRIDE; Somewhat* clone() const FL_IOVERRIDE; static Hedge* constructor(); }; - } + #endif /* FL_SOMEWHAT_H */ diff --git a/fuzzylite/fl/hedge/Very.h b/fuzzylite/fl/hedge/Very.h index bcfe5e4..b80c994 100644 --- a/fuzzylite/fl/hedge/Very.h +++ b/fuzzylite/fl/hedge/Very.h @@ -1,25 +1,17 @@ /* - Author: Juan Rada-Vilela, Ph.D. - Copyright (C) 2010-2014 FuzzyLite Limited - All rights reserved + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> This file is part of fuzzylite. fuzzylite is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. + the terms of the FuzzyLite License included with the software. - fuzzylite is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - for more details. - - You should have received a copy of the GNU Lesser General Public License - along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. - - fuzzylite™ is a trademark of FuzzyLite Limited. + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + fuzzylite is a registered trademark of FuzzyLite Limited. */ #ifndef FL_VERY_H @@ -29,14 +21,30 @@ namespace fl { - class FL_API Very : public Hedge { + /** + The Very class is a Hedge located fourth in the ordered set + (Not, Seldom, Somewhat, Very, Extremely, Any). + + @author Juan Rada-Vilela, Ph.D. + @see Hedge + @see HedgeFactory + @since 4.0 + */ + class FL_API Very FL_IFINAL : public Hedge { public: std::string name() const FL_IOVERRIDE; + + Complexity complexity() const FL_IOVERRIDE; + + /** + Computes the hedge for the membership function value @f$x@f$ + @param x is a membership function value + @return @f$x^2@f$ + */ scalar hedge(scalar x) const FL_IOVERRIDE; Very* clone() const FL_IOVERRIDE; static Hedge* constructor(); }; - } #endif /* FL_VERY_H */ |