diff options
Diffstat (limited to 'fuzzylite/fl/defuzzifier')
-rw-r--r-- | fuzzylite/fl/defuzzifier/Bisector.h | 47 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/Centroid.h | 48 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/Defuzzifier.h | 59 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/IntegralDefuzzifier.h | 62 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/LargestOfMaximum.h | 50 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/MeanOfMaximum.h | 49 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/SmallestOfMaximum.h | 49 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/WeightedAverage.h | 51 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/WeightedAverageCustom.h | 77 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/WeightedDefuzzifier.h | 81 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/WeightedSum.h | 51 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/WeightedSumCustom.h | 78 |
12 files changed, 529 insertions, 173 deletions
diff --git a/fuzzylite/fl/defuzzifier/Bisector.h b/fuzzylite/fl/defuzzifier/Bisector.h index 7ba8db2..046b185 100644 --- a/fuzzylite/fl/defuzzifier/Bisector.h +++ b/fuzzylite/fl/defuzzifier/Bisector.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_BISECTOR_H @@ -29,6 +21,16 @@ namespace fl { + /** + The Bisector class is an IntegralDefuzzifier that computes the bisector + of a fuzzy set represented in a Term. + + @author Juan Rada-Vilela, Ph.D. + @see Centroid + @see IntegralDefuzzifier + @see Defuzzifier + @since 4.0 + */ class FL_API Bisector : public IntegralDefuzzifier { public: explicit Bisector(int resolution = defaultResolution()); @@ -36,13 +38,26 @@ namespace fl { FL_DEFAULT_COPY_AND_MOVE(Bisector) virtual std::string className() const FL_IOVERRIDE; + + virtual Complexity complexity(const Term* term) const FL_IOVERRIDE; + + /** + Computes the bisector of a fuzzy set. The defuzzification process + integrates over the fuzzy set utilizing the boundaries given as + parameters. The integration algorithm is the midpoint rectangle + method (https://en.wikipedia.org/wiki/Rectangle_method). + + @param term is the fuzzy set + @param minimum is the minimum value of the fuzzy set + @param maximum is the maximum value of the fuzzy set + @return the @f$x@f$-coordinate of the bisector of the fuzzy set + */ virtual scalar defuzzify(const Term* term, scalar minimum, scalar maximum) const FL_IOVERRIDE; virtual Bisector* clone() const FL_IOVERRIDE; static Defuzzifier* constructor(); }; - } #endif /* FL_BISECTOR_H */ diff --git a/fuzzylite/fl/defuzzifier/Centroid.h b/fuzzylite/fl/defuzzifier/Centroid.h index 7510673..b056eac 100644 --- a/fuzzylite/fl/defuzzifier/Centroid.h +++ b/fuzzylite/fl/defuzzifier/Centroid.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_CENTROID_H @@ -29,6 +21,16 @@ namespace fl { + /** + The Centroid class is an IntegralDefuzzifier that computes the centroid + of a fuzzy set represented in a Term. + + @author Juan Rada-Vilela, Ph.D. + @see BiSector + @see IntegralDefuzzifier + @see Defuzzifier + @since 4.0 + */ class FL_API Centroid : public IntegralDefuzzifier { public: explicit Centroid(int resolution = defaultResolution()); @@ -36,12 +38,26 @@ namespace fl { FL_DEFAULT_COPY_AND_MOVE(Centroid) virtual std::string className() const FL_IOVERRIDE; + + virtual Complexity complexity(const Term* term) const FL_IOVERRIDE; + + /** + Computes the centroid of a fuzzy set. The defuzzification process + integrates over the fuzzy set utilizing the boundaries given as + parameters. The integration algorithm is the midpoint rectangle + method (https://en.wikipedia.org/wiki/Rectangle_method). + + @param term is the fuzzy set + @param minimum is the minimum value of the fuzzy set + @param maximum is the maximum value of the fuzzy set + @return the @f$x@f$-coordinate of the centroid of the fuzzy set + */ virtual scalar defuzzify(const Term* term, scalar minimum, scalar maximum) const FL_IOVERRIDE; virtual Centroid* clone() const FL_IOVERRIDE; static Defuzzifier* constructor(); }; - } + #endif /* FL_CENTROID_H */ diff --git a/fuzzylite/fl/defuzzifier/Defuzzifier.h b/fuzzylite/fl/defuzzifier/Defuzzifier.h index 3598113..25749eb 100644 --- a/fuzzylite/fl/defuzzifier/Defuzzifier.h +++ b/fuzzylite/fl/defuzzifier/Defuzzifier.h @@ -1,38 +1,39 @@ /* - 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. */ -//TODO Check http://en.wikipedia.org/wiki/Defuzzification for other defuzzifiers. - #ifndef FL_DEFUZZIFIER_H #define FL_DEFUZZIFIER_H #include "fl/fuzzylite.h" + +#include "fl/Complexity.h" + #include <string> namespace fl { class Term; + /** + The Defuzzifier class is the abstract class for defuzzifiers. + + @author Juan Rada-Vilela, Ph.D. + @see IntegralDefuzzifier + @see WeightedDefuzzifier + @since 4.0 + */ class FL_API Defuzzifier { public: @@ -43,11 +44,33 @@ namespace fl { } FL_DEFAULT_COPY_AND_MOVE(Defuzzifier) + /** + Returns the name of the class of the defuzzifier + @return the name of the class of the defuzzifier + */ virtual std::string className() const = 0; + /** + Creates a clone of the defuzzifier + @return a clone of the defuzzifier + */ virtual Defuzzifier* clone() const = 0; + + /** + Computes the complexity of defuzzifying the given term + @param term is the term to defuzzify + @return the complexity of defuzzifying the given term + */ + virtual Complexity complexity(const Term* term) const = 0; + /** + Defuzzifies the given fuzzy term utilizing the range `[minimum,maximum]` + @param term is the term to defuzzify, typically an Aggregated term + @param minimum is the minimum value of the range + @param maximum is the maximum value of the range + @return the defuzzified value of the given fuzzy term + */ virtual scalar defuzzify(const Term* term, scalar minimum, scalar maximum) const = 0; }; - } + #endif /* FL_DEFUZZIFIER_H */ diff --git a/fuzzylite/fl/defuzzifier/IntegralDefuzzifier.h b/fuzzylite/fl/defuzzifier/IntegralDefuzzifier.h index 61aaf8a..9cfd132 100644 --- a/fuzzylite/fl/defuzzifier/IntegralDefuzzifier.h +++ b/fuzzylite/fl/defuzzifier/IntegralDefuzzifier.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_INTEGRALDEFUZZIFIER_H @@ -28,24 +20,52 @@ #include "fl/defuzzifier/Defuzzifier.h" namespace fl { - //TODO: check http://en.wikipedia.org/wiki/Adaptive_quadrature + /** + The IntegralDefuzzifier class is the base class for defuzzifiers which integrate + over the fuzzy set. + + @author Juan Rada-Vilela, Ph.D. + @since 4.0 + */ class FL_API IntegralDefuzzifier : public Defuzzifier { - protected: + private: static int _defaultResolution; int _resolution; public: - - static void setDefaultResolution(int defaultResolution); - static int defaultResolution(); - explicit IntegralDefuzzifier(int resolution = defaultResolution()); virtual ~IntegralDefuzzifier() FL_IOVERRIDE; FL_DEFAULT_COPY_AND_MOVE(IntegralDefuzzifier) + /** + Sets the resolution of the defuzzifier. The resolution refers to the + number of divisions in which the range `[minimum,maximum]` is divided + in order to integrate the area under the curve + + @param resolution is the resolution of the defuzzifier + */ virtual void setResolution(int resolution); + /** + Gets the resolution of the defuzzifier. The resolution refers to the + number of divisions in which the range `[minimum,maximum]` is divided + in order to integrate the area under the curve + + @return the resolution of the defuzzifier + */ virtual int getResolution() const; + + /** + Sets the default resolution for integral-based defuzzifiers + @param defaultResolution is the default resolution for integral-based defuzzifiers + */ + static void setDefaultResolution(int defaultResolution); + /** + Gets the default resolution for integral-based defuzzifiers + @return the default resolution for integral-based defuzzifiers + */ + static int defaultResolution(); + }; } diff --git a/fuzzylite/fl/defuzzifier/LargestOfMaximum.h b/fuzzylite/fl/defuzzifier/LargestOfMaximum.h index 8f1d3c8..e325db5 100644 --- a/fuzzylite/fl/defuzzifier/LargestOfMaximum.h +++ b/fuzzylite/fl/defuzzifier/LargestOfMaximum.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_LARGESTOFMAXIMUM_H @@ -29,6 +21,18 @@ namespace fl { + /** + The LargestOfMaximum class is an IntegralDefuzzifier that computes the + largest value of the maximum membership function of a fuzzy set + represented in a Term. + + @author Juan Rada-Vilela, Ph.D. + @see SmallestOfMaximum + @see MeanOfMaximum + @see IntegralDefuzzifier + @see Defuzzifier + @since 4.0 + */ class FL_API LargestOfMaximum : public IntegralDefuzzifier { public: explicit LargestOfMaximum(int resolution = defaultResolution()); @@ -36,6 +40,21 @@ namespace fl { FL_DEFAULT_COPY_AND_MOVE(LargestOfMaximum) virtual std::string className() const FL_IOVERRIDE; + + virtual Complexity complexity(const Term* term) const FL_IOVERRIDE; + + /** + Computes the largest value of the maximum membership function of a + fuzzy set. The largest value is computed by integrating over the + fuzzy set. The integration algorithm is the midpoint rectangle method + (https://en.wikipedia.org/wiki/Rectangle_method). + + @param term is the fuzzy set + @param minimum is the minimum value of the fuzzy set + @param maximum is the maximum value of the fuzzy set + @return the largest @f$x@f$-coordinate of the maximum membership + function value in the fuzzy set + */ virtual scalar defuzzify(const Term* term, scalar minimum, scalar maximum) const FL_IOVERRIDE; virtual LargestOfMaximum* clone() const FL_IOVERRIDE; @@ -43,5 +62,6 @@ namespace fl { static Defuzzifier* constructor(); }; } + #endif /* FL_LARGESTOFMAXIMUM_H */ diff --git a/fuzzylite/fl/defuzzifier/MeanOfMaximum.h b/fuzzylite/fl/defuzzifier/MeanOfMaximum.h index 2c09759..027f43b 100644 --- a/fuzzylite/fl/defuzzifier/MeanOfMaximum.h +++ b/fuzzylite/fl/defuzzifier/MeanOfMaximum.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_MEANOFMAXIMUM_H @@ -29,6 +21,18 @@ namespace fl { + /** + The MeanOfMaximum class is an IntegralDefuzzifier that computes the mean + value of the maximum membership function of a fuzzy set represented in a + Term. + + @author Juan Rada-Vilela, Ph.D. + @see SmallestOfMaximum + @see MeanOfMaximum + @see IntegralDefuzzifier + @see Defuzzifier + @since 4.0 + */ class FL_API MeanOfMaximum : public IntegralDefuzzifier { public: explicit MeanOfMaximum(int resolution = defaultResolution()); @@ -36,6 +40,21 @@ namespace fl { FL_DEFAULT_COPY_AND_MOVE(MeanOfMaximum) virtual std::string className() const FL_IOVERRIDE; + + virtual Complexity complexity(const Term* term) const FL_IOVERRIDE; + + /** + Computes the mean value of the maximum membership function + of a fuzzy set. The mean value is computed while integrating + over the fuzzy set. The integration algorithm is the midpoint + rectangle method (https://en.wikipedia.org/wiki/Rectangle_method). + + @param term is the fuzzy set + @param minimum is the minimum value of the fuzzy set + @param maximum is the maximum value of the fuzzy set + @return the mean @f$x@f$-coordinate of the maximum membership + function value in the fuzzy set + */ virtual scalar defuzzify(const Term* term, scalar minimum, scalar maximum) const FL_IOVERRIDE; virtual MeanOfMaximum* clone() const FL_IOVERRIDE; diff --git a/fuzzylite/fl/defuzzifier/SmallestOfMaximum.h b/fuzzylite/fl/defuzzifier/SmallestOfMaximum.h index 289e2a9..94f8a7a 100644 --- a/fuzzylite/fl/defuzzifier/SmallestOfMaximum.h +++ b/fuzzylite/fl/defuzzifier/SmallestOfMaximum.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_SMALLESTOFMAXIMUM_H @@ -29,6 +21,18 @@ namespace fl { + /** + The SmallestOfMaximum class is an IntegralDefuzzifier that computes the + smallest value of the maximum membership function of a fuzzy set + represented in a Term. + + @author Juan Rada-Vilela, Ph.D. + @see LargestOfMaximum + @see MeanOfMaximum + @see IntegralDefuzzifier + @see Defuzzifier + @since 4.0 + */ class FL_API SmallestOfMaximum : public IntegralDefuzzifier { public: explicit SmallestOfMaximum(int resolution = defaultResolution()); @@ -36,6 +40,21 @@ namespace fl { FL_DEFAULT_COPY_AND_MOVE(SmallestOfMaximum) virtual std::string className() const FL_IOVERRIDE; + + virtual Complexity complexity(const Term* term) const FL_IOVERRIDE; + + /** + Computes the smallest value of the maximum membership function in the + fuzzy set. The smallest value is computed while integrating over the + fuzzy set. The integration algorithm is the midpoint rectangle method + (https://en.wikipedia.org/wiki/Rectangle_method). + + @param term is the fuzzy set + @param minimum is the minimum value of the fuzzy set + @param maximum is the maximum value of the fuzzy set + @return the smallest @f$x@f$-coordinate of the maximum membership + function value in the fuzzy set + */ virtual scalar defuzzify(const Term* term, scalar minimum, scalar maximum) const FL_IOVERRIDE; virtual SmallestOfMaximum* clone() const FL_IOVERRIDE; diff --git a/fuzzylite/fl/defuzzifier/WeightedAverage.h b/fuzzylite/fl/defuzzifier/WeightedAverage.h index 3fbbd38..7f8e9f6 100644 --- a/fuzzylite/fl/defuzzifier/WeightedAverage.h +++ b/fuzzylite/fl/defuzzifier/WeightedAverage.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_WEIGHTEDAVERAGE_H @@ -30,6 +22,18 @@ namespace fl { class Activated; + /** + The WeightedAverage class is a WeightedDefuzzifier that computes the + weighted average of a fuzzy set represented in an Aggregated Term. + + @author Juan Rada-Vilela, Ph.D. + @see WeightedAverageCustom + @see WeightedSum + @see WeightedSumCustom + @see WeightedDefuzzifier + @see Defuzzifier + @since 4.0 + */ class FL_API WeightedAverage : public WeightedDefuzzifier { public: explicit WeightedAverage(Type type = Automatic); @@ -38,6 +42,23 @@ namespace fl { FL_DEFAULT_COPY_AND_MOVE(WeightedAverage) virtual std::string className() const FL_IOVERRIDE; + + virtual Complexity complexity(const Term* term) const FL_IOVERRIDE; + + /** + Computes the weighted average of the given fuzzy set represented in + an Aggregated term as @f$y = \dfrac{\sum_i w_iz_i}{\sum_i w_i} @f$, + where @f$w_i@f$ is the activation degree of term @f$i@f$, and + @f$z_i = \mu_i(w_i) @f$. + + From version 6.0, the implication and aggregation operators are not + utilized for defuzzification. + + @param term is the fuzzy set represented as an Aggregated Term + @param minimum is the minimum value of the range (only used for Tsukamoto) + @param maximum is the maximum value of the range (only used for Tsukamoto) + @return the weighted average of the given fuzzy set + */ virtual scalar defuzzify(const Term* term, scalar minimum, scalar maximum) const FL_IOVERRIDE; virtual WeightedAverage* clone() const FL_IOVERRIDE; diff --git a/fuzzylite/fl/defuzzifier/WeightedAverageCustom.h b/fuzzylite/fl/defuzzifier/WeightedAverageCustom.h new file mode 100644 index 0000000..5597f97 --- /dev/null +++ b/fuzzylite/fl/defuzzifier/WeightedAverageCustom.h @@ -0,0 +1,77 @@ +/* + 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_WEIGHTEDAVERAGECUSTOM_H +#define FL_WEIGHTEDAVERAGECUSTOM_H + +#include "fl/defuzzifier/WeightedDefuzzifier.h" + +namespace fl { + class Activated; + + /** + The (experimental) WeightedAverageCustom class is a WeightedDefuzzifier that computes the + weighted average of a fuzzy set represented in an Aggregated Term utilizing + the fuzzy operators for implication and aggregation to compute the weighted + average. This is an experimental approach to take advantage of customization + thanks to the object-oriented design. + + @author Juan Rada-Vilela, Ph.D. + @see WeightedAverage + @see WeightedSum + @see WeightedSumCustom + @see WeightedDefuzzifier + @see Defuzzifier + @since 6.0 + */ + class FL_API WeightedAverageCustom : public WeightedDefuzzifier { + public: + explicit WeightedAverageCustom(Type type = Automatic); + explicit WeightedAverageCustom(const std::string& type); + virtual ~WeightedAverageCustom() FL_IOVERRIDE; + FL_DEFAULT_COPY_AND_MOVE(WeightedAverageCustom) + + virtual std::string className() const FL_IOVERRIDE; + + virtual Complexity complexity(const Term* term) const FL_IOVERRIDE; + + /** + Computes the weighted average of the given fuzzy set represented as + an AggregatedTerm as @f$y = \dfrac{\sum_i w_iz_i}{\sum_i w_i} @f$, + where @f$w_i@f$ is the activation degree of term @f$i@f$, and + @f$z_i = \mu_i(w_i) @f$. + + If the implication and aggregation operators are set to fl::null (or + set to AlgebraicProduct and UnboundedSum, respectively), then the + operation of WeightedAverageCustom is the same as the WeightedAverage. + Otherwise, the implication and aggregation operators are utilized to + compute the multiplications and sums in @f$y@f$, respectively. + + @param term is the fuzzy set represented as an Aggregated Term + @param minimum is the minimum value of the range (only used for Tsukamoto) + @param maximum is the maximum value of the range (only used for Tsukamoto) + @return the weighted average of the given fuzzy set + */ + virtual scalar defuzzify(const Term* term, + scalar minimum, scalar maximum) const FL_IOVERRIDE; + virtual WeightedAverageCustom* clone() const FL_IOVERRIDE; + + static Defuzzifier* constructor(); + }; +} + +#endif /* FL_WEIGHTEDAVERAGECUSTOM_H */ + diff --git a/fuzzylite/fl/defuzzifier/WeightedDefuzzifier.h b/fuzzylite/fl/defuzzifier/WeightedDefuzzifier.h index 2bf0495..2045772 100644 --- a/fuzzylite/fl/defuzzifier/WeightedDefuzzifier.h +++ b/fuzzylite/fl/defuzzifier/WeightedDefuzzifier.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_WEIGHTEDDEFUZZIFIER_H @@ -30,33 +22,68 @@ namespace fl { class Activated; + /** + The WeightedDefuzzifier class is the base class for defuzzifiers which + compute a weighted function on the fuzzy set without requiring to + integrate over the fuzzy set. + + @author Juan Rada-Vilela, Ph.D. + @since 5.0 + */ class FL_API WeightedDefuzzifier : public Defuzzifier { public: + /**The Type enum indicates the type of the WeightedDefuzzifier based + the terms included in the fuzzy set.*/ enum Type { - Automatic, TakagiSugeno, Tsukamoto + /**Automatic: Automatically inferred from the terms */ + Automatic, + /**TakagiSugeno: Manually set to TakagiSugeno (or Inverse Tsukamoto)*/ + TakagiSugeno, + /**Tsukamoto: Manually set to Tsukamoto*/ + Tsukamoto }; - static std::string typeName(Type); + /** + Returns a string representation of the given type + @param type is the type of a defuzzifier + @return a string representation of the given type + */ + static std::string typeName(Type type); + private: + Type _type; + public: explicit WeightedDefuzzifier(Type type = Automatic); explicit WeightedDefuzzifier(const std::string& type); virtual ~WeightedDefuzzifier() FL_IOVERRIDE; FL_DEFAULT_COPY_AND_MOVE(WeightedDefuzzifier) - virtual void setType(Type type); - virtual Type getType() const; + /** + Sets the type of the weighted defuzzifier + @param type is the type of the weighted defuzzifier + */ + void setType(Type type); + /** + Gets the type of the weighted defuzzifier + @return the type of the weighted defuzzifier + */ + Type getType() const; + /** + Returns a string representation of the type of the defuzzifier + @return a string representation of the type of the defuzzifier + */ virtual std::string getTypeName() const; + /** + Infers the type of the defuzzifier based on the given term. If the + given term is Constant, Linear or Function, then the type is + TakagiSugeno; otherwise, the type is Tsukamoto + + @param term is the given term + @return the inferred type of the defuzzifier based on the given term + */ virtual Type inferType(const Term* term) const; - virtual bool isMonotonic(const Term* term) const; - - virtual scalar tsukamoto(const Term* monotonic, scalar activationDegree, - scalar minimum, scalar maximum) const; - - protected: - Type _type; }; - } #endif /* FL_WEIGHTEDDEFUZZIFIER_H */ diff --git a/fuzzylite/fl/defuzzifier/WeightedSum.h b/fuzzylite/fl/defuzzifier/WeightedSum.h index a754023..fb61ef3 100644 --- a/fuzzylite/fl/defuzzifier/WeightedSum.h +++ b/fuzzylite/fl/defuzzifier/WeightedSum.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_WEIGHTEDSUM_H @@ -30,6 +22,18 @@ namespace fl { + /** + The WeightedSum class is a WeightedDefuzzifier that computes the + weighted sum of a fuzzy set represented in an Aggregated Term. + + @author Juan Rada-Vilela, Ph.D. + @see WeightedSumCustom + @see WeightedAverage + @see WeightedAverageCustom + @see WeightedDefuzzifier + @see Defuzzifier + @since 4.0 + */ class FL_API WeightedSum : public WeightedDefuzzifier { public: explicit WeightedSum(Type type = Automatic); @@ -38,6 +42,23 @@ namespace fl { FL_DEFAULT_COPY_AND_MOVE(WeightedSum) virtual std::string className() const FL_IOVERRIDE; + + virtual Complexity complexity(const Term* term) const FL_IOVERRIDE; + + /** + Computes the weighted sum of the given fuzzy set represented as an + Aggregated Term as @f$y = \sum_i{w_iz_i} @f$, + where @f$w_i@f$ is the activation degree of term @f$i@f$, and @f$z_i + = \mu_i(w_i) @f$. + + From version 6.0, the implication and aggregation operators are not + utilized for defuzzification. + + @param term is the fuzzy set represented as an AggregatedTerm + @param minimum is the minimum value of the range (only used for Tsukamoto) + @param maximum is the maximum value of the range (only used for Tsukamoto) + @return the weighted sum of the given fuzzy set + */ virtual scalar defuzzify(const Term* term, scalar minimum, scalar maximum) const FL_IOVERRIDE; virtual WeightedSum* clone() const FL_IOVERRIDE; diff --git a/fuzzylite/fl/defuzzifier/WeightedSumCustom.h b/fuzzylite/fl/defuzzifier/WeightedSumCustom.h new file mode 100644 index 0000000..c055d1e --- /dev/null +++ b/fuzzylite/fl/defuzzifier/WeightedSumCustom.h @@ -0,0 +1,78 @@ +/* + 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_WEIGHTEDSUMCUSTOM_H +#define FL_WEIGHTEDSUMCUSTOM_H + + +#include "fl/defuzzifier/WeightedDefuzzifier.h" + +namespace fl { + + /** + The (experimental) WeightedSumCustom class is a WeightedDefuzzifier that computes the + weighted sum of a fuzzy set represented in an Aggregated Term utilizing + the fuzzy operators for implication and aggregation to compute the weighted + sum. This is an experimental approach to take advantage of customization + thanks to the object-oriented design. + + @author Juan Rada-Vilela, Ph.D. + @see WeightedSum + @see WeightedAverage + @see WeightedAverageCustom + @see WeightedDefuzzifier + @see Defuzzifier + @since 6.0 + @experimental + */ + class FL_API WeightedSumCustom : public WeightedDefuzzifier { + public: + explicit WeightedSumCustom(Type type = Automatic); + explicit WeightedSumCustom(const std::string& type); + virtual ~WeightedSumCustom() FL_IOVERRIDE; + FL_DEFAULT_COPY_AND_MOVE(WeightedSumCustom) + + virtual std::string className() const FL_IOVERRIDE; + + virtual Complexity complexity(const Term* term) const FL_IOVERRIDE; + + /** + Computes the weighted sum of the given fuzzy set represented in an + Aggregated Term as @f$y = \sum_i{w_iz_i} @f$, + where @f$w_i@f$ is the activation degree of term @f$i@f$, and @f$z_i + = \mu_i(w_i) @f$. + + If the implication and aggregation operators are set to fl::null (or + set to AlgebraicProduct and UnboundedSum, respectively), then the + operation of WeightedAverageCustom is the same as the WeightedAverage. + Otherwise, the implication and aggregation operators are utilized to + compute the multiplications and sums in @f$y@f$, respectively. + + @param term is the fuzzy set represented as an AggregatedTerm + @param minimum is the minimum value of the range (only used for Tsukamoto) + @param maximum is the maximum value of the range (only used for Tsukamoto) + @return the weighted sum of the given fuzzy set + */ + virtual scalar defuzzify(const Term* term, + scalar minimum, scalar maximum) const FL_IOVERRIDE; + virtual WeightedSumCustom* clone() const FL_IOVERRIDE; + + static Defuzzifier* constructor(); + }; +} + +#endif /* FL_WEIGHTEDSUMCUSTOM_H */ + |