diff options
author | Johannes 'josch' Schauer <josch@mister-muffin.de> | 2020-10-23 08:27:38 +0200 |
---|---|---|
committer | Johannes 'josch' Schauer <josch@mister-muffin.de> | 2020-10-23 08:27:38 +0200 |
commit | 3b91637afd9716881bec3a34c3ace369c82ef61c (patch) | |
tree | 2445bd2a7aadd1fd90bc76e5ab7491a8403d6f75 /fuzzylite/fl/defuzzifier | |
parent | 2b00fcb77bb6e7b769ee34a114679838e00156d1 (diff) |
New upstream version 6.0+dfsg
Diffstat (limited to 'fuzzylite/fl/defuzzifier')
-rw-r--r-- | fuzzylite/fl/defuzzifier/Bisector.h | 64 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/Centroid.h | 63 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/Defuzzifier.h | 76 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/IntegralDefuzzifier.h | 73 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/LargestOfMaximum.h | 67 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/MeanOfMaximum.h | 67 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/SmallestOfMaximum.h | 67 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/WeightedAverage.h | 71 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/WeightedAverageCustom.h | 77 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/WeightedDefuzzifier.h | 90 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/WeightedSum.h | 71 | ||||
-rw-r--r-- | fuzzylite/fl/defuzzifier/WeightedSumCustom.h | 78 |
12 files changed, 864 insertions, 0 deletions
diff --git a/fuzzylite/fl/defuzzifier/Bisector.h b/fuzzylite/fl/defuzzifier/Bisector.h new file mode 100644 index 0000000..046b185 --- /dev/null +++ b/fuzzylite/fl/defuzzifier/Bisector.h @@ -0,0 +1,64 @@ +/* + 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_BISECTOR_H +#define FL_BISECTOR_H + +#include "fl/defuzzifier/IntegralDefuzzifier.h" + +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()); + virtual ~Bisector() FL_IOVERRIDE; + 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 new file mode 100644 index 0000000..b056eac --- /dev/null +++ b/fuzzylite/fl/defuzzifier/Centroid.h @@ -0,0 +1,63 @@ +/* + 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_CENTROID_H +#define FL_CENTROID_H + +#include "fl/defuzzifier/IntegralDefuzzifier.h" + +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()); + virtual ~Centroid() FL_IOVERRIDE; + 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 new file mode 100644 index 0000000..25749eb --- /dev/null +++ b/fuzzylite/fl/defuzzifier/Defuzzifier.h @@ -0,0 +1,76 @@ +/* + 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_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: + + Defuzzifier() { + } + + virtual ~Defuzzifier() { + } + 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 new file mode 100644 index 0000000..9cfd132 --- /dev/null +++ b/fuzzylite/fl/defuzzifier/IntegralDefuzzifier.h @@ -0,0 +1,73 @@ +/* + 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_INTEGRALDEFUZZIFIER_H +#define FL_INTEGRALDEFUZZIFIER_H + +#include "fl/defuzzifier/Defuzzifier.h" + +namespace fl { + + /** + 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 { + private: + static int _defaultResolution; + + int _resolution; + public: + 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(); + + }; +} + +#endif /* INTEGRALDEFUZZIFIER_H */ + diff --git a/fuzzylite/fl/defuzzifier/LargestOfMaximum.h b/fuzzylite/fl/defuzzifier/LargestOfMaximum.h new file mode 100644 index 0000000..e325db5 --- /dev/null +++ b/fuzzylite/fl/defuzzifier/LargestOfMaximum.h @@ -0,0 +1,67 @@ +/* + 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_LARGESTOFMAXIMUM_H +#define FL_LARGESTOFMAXIMUM_H + +#include "fl/defuzzifier/IntegralDefuzzifier.h" + +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()); + virtual ~LargestOfMaximum() FL_IOVERRIDE; + 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; + + static Defuzzifier* constructor(); + }; +} + +#endif /* FL_LARGESTOFMAXIMUM_H */ + diff --git a/fuzzylite/fl/defuzzifier/MeanOfMaximum.h b/fuzzylite/fl/defuzzifier/MeanOfMaximum.h new file mode 100644 index 0000000..027f43b --- /dev/null +++ b/fuzzylite/fl/defuzzifier/MeanOfMaximum.h @@ -0,0 +1,67 @@ +/* + 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_MEANOFMAXIMUM_H +#define FL_MEANOFMAXIMUM_H + +#include "fl/defuzzifier/IntegralDefuzzifier.h" + +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()); + virtual ~MeanOfMaximum() FL_IOVERRIDE; + 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; + + static Defuzzifier* constructor(); + }; +} + +#endif /* FL_MEANOFMAXIMUM_H */ + diff --git a/fuzzylite/fl/defuzzifier/SmallestOfMaximum.h b/fuzzylite/fl/defuzzifier/SmallestOfMaximum.h new file mode 100644 index 0000000..94f8a7a --- /dev/null +++ b/fuzzylite/fl/defuzzifier/SmallestOfMaximum.h @@ -0,0 +1,67 @@ +/* + 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_SMALLESTOFMAXIMUM_H +#define FL_SMALLESTOFMAXIMUM_H + +#include "fl/defuzzifier/IntegralDefuzzifier.h" + +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()); + virtual ~SmallestOfMaximum() FL_IOVERRIDE; + 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; + + static Defuzzifier* constructor(); + }; +} + +#endif /* FL_SMALLESTOFMAXIMUM_H */ + diff --git a/fuzzylite/fl/defuzzifier/WeightedAverage.h b/fuzzylite/fl/defuzzifier/WeightedAverage.h new file mode 100644 index 0000000..7f8e9f6 --- /dev/null +++ b/fuzzylite/fl/defuzzifier/WeightedAverage.h @@ -0,0 +1,71 @@ +/* + 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_WEIGHTEDAVERAGE_H +#define FL_WEIGHTEDAVERAGE_H + +#include "fl/defuzzifier/WeightedDefuzzifier.h" + +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); + explicit WeightedAverage(const std::string& type); + virtual ~WeightedAverage() FL_IOVERRIDE; + 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; + + static Defuzzifier* constructor(); + }; +} + +#endif /* FL_WEIGHTEDAVERAGE_H */ + 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 new file mode 100644 index 0000000..2045772 --- /dev/null +++ b/fuzzylite/fl/defuzzifier/WeightedDefuzzifier.h @@ -0,0 +1,90 @@ +/* + 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_WEIGHTEDDEFUZZIFIER_H +#define FL_WEIGHTEDDEFUZZIFIER_H + +#include "fl/defuzzifier/Defuzzifier.h" + +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: Automatically inferred from the terms */ + Automatic, + /**TakagiSugeno: Manually set to TakagiSugeno (or Inverse Tsukamoto)*/ + TakagiSugeno, + /**Tsukamoto: Manually set to Tsukamoto*/ + Tsukamoto + }; + /** + 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) + + /** + 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; + + }; +} + +#endif /* FL_WEIGHTEDDEFUZZIFIER_H */ + diff --git a/fuzzylite/fl/defuzzifier/WeightedSum.h b/fuzzylite/fl/defuzzifier/WeightedSum.h new file mode 100644 index 0000000..fb61ef3 --- /dev/null +++ b/fuzzylite/fl/defuzzifier/WeightedSum.h @@ -0,0 +1,71 @@ +/* + 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_WEIGHTEDSUM_H +#define FL_WEIGHTEDSUM_H + + +#include "fl/defuzzifier/WeightedDefuzzifier.h" + +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); + explicit WeightedSum(const std::string& type); + virtual ~WeightedSum() FL_IOVERRIDE; + 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; + + static Defuzzifier* constructor(); + }; +} + +#endif /* FL_WEIGHTEDSUM_H */ + 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 */ + |