diff options
Diffstat (limited to 'fuzzylite/fl/activation')
-rw-r--r-- | fuzzylite/fl/activation/Activation.h | 95 | ||||
-rw-r--r-- | fuzzylite/fl/activation/First.h | 104 | ||||
-rw-r--r-- | fuzzylite/fl/activation/General.h | 73 | ||||
-rw-r--r-- | fuzzylite/fl/activation/Highest.h | 86 | ||||
-rw-r--r-- | fuzzylite/fl/activation/Last.h | 103 | ||||
-rw-r--r-- | fuzzylite/fl/activation/Lowest.h | 87 | ||||
-rw-r--r-- | fuzzylite/fl/activation/Proportional.h | 71 | ||||
-rw-r--r-- | fuzzylite/fl/activation/Threshold.h | 183 |
8 files changed, 802 insertions, 0 deletions
diff --git a/fuzzylite/fl/activation/Activation.h b/fuzzylite/fl/activation/Activation.h new file mode 100644 index 0000000..562d53e --- /dev/null +++ b/fuzzylite/fl/activation/Activation.h @@ -0,0 +1,95 @@ +/* + 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_ACTIVATION_H +#define FL_ACTIVATION_H + +#include "fl/fuzzylite.h" + +#include "fl/Complexity.h" + +namespace fl { + class RuleBlock; + + /** + The Activation class is the abstract class for RuleBlock activation + methods. An activation method implements the criteria to activate the + rules within a given rule block. An activation method needs to process + every rule and determine whether the rule is to be activated or + deactivated. The activation methods were first introduced in version 6.0, + but in earlier versions the term `activation` referred to the TNorm that + modulated the consequent of a rule, which is now referred to as the + `implication` operator. + + @author Juan Rada-Vilela, Ph.D. + @see Rule + @see RuleBlock + @see ActivationFactory + @since 6.0 + */ + + class FL_API Activation { + public: + + Activation() { } + + virtual ~Activation() { } + + FL_DEFAULT_COPY_AND_MOVE(Activation) + + /** + Returns the name of the activation method, which is also utilized to + register the activation method in the ActivationFactory. + @return the name of the activation method + @see ActivationFactory + */ + virtual std::string className() const = 0; + + /** + Returns the parameters of the activation method, which can be used to + configure other instances of the activation method. + @return the parameters of the activation method + */ + virtual std::string parameters() const = 0; + + /** + Configures the activation method with the given parameters. + @param parameters contains a list of space-separated parameter values + */ + virtual void configure(const std::string& parameters) = 0; + + /** + Computes the estimated complexity of activating the given rule block + @return the estimated complexity of activating the given rule block + */ + virtual Complexity complexity(const RuleBlock* ruleBlock) const = 0; + + /** + Activates the rule block + @param ruleBlock is the rule block to activate + */ + virtual void activate(RuleBlock* ruleBlock) = 0; + + /** + Clones the activation method. + @return a clone of the activation method + */ + virtual Activation* clone() const = 0; + }; + +} + +#endif /* FL_ACTIVATION_H */ diff --git a/fuzzylite/fl/activation/First.h b/fuzzylite/fl/activation/First.h new file mode 100644 index 0000000..355b1a9 --- /dev/null +++ b/fuzzylite/fl/activation/First.h @@ -0,0 +1,104 @@ +/* + 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_FIRST_H +#define FL_FIRST_H + +#include "fl/activation/Activation.h" + +namespace fl { + + /** + The First class is a RuleBlock Activation method that activates the first + @f$n@f$ rules whose activation degrees are greater than or equal to the given + threshold. The rules are iterated in the order they were added to the rule block. + + @author Juan Rada-Vilela, Ph.D. + @see Last + @see Rule + @see RuleBlock + @see ActivationFactory + @since 6.0 + */ + + class FL_API First : public Activation { + private: + int _numberOfRules; + scalar _threshold; + public: + + explicit First(int numberOfRules = 1, scalar threshold = 0.0); + virtual ~First(); + FL_DEFAULT_COPY_AND_MOVE(First) + + virtual std::string className() const FL_IOVERRIDE; + + /** + Returns the number of rules and the threshold of the activation method + @return "numberOfRules threshold" + */ + virtual std::string parameters() const FL_IOVERRIDE; + + /** + Configures the activation method with the given number of rules and + threshold + @param parameters as "numberOfRules threshold" + */ + virtual void configure(const std::string& parameters) FL_IOVERRIDE; + + /** + Sets the number of rules for the activation degree + @param numberOfRules is the number of rules for the activation degree + */ + virtual void setNumberOfRules(int numberOfRules); + + /** + Gets the number of rules for the activation degree + @return the number of rules for the activation degree + */ + virtual int getNumberOfRules() const; + + /** + Sets the threshold for the activation degree + @param threshold is the threshold for the activation degree + */ + virtual void setThreshold(scalar threshold); + + /** + Gets the threshold for the activation degree + @return the threshold for the activation degree + */ + virtual scalar getThreshold() const; + + virtual Complexity complexity(const RuleBlock* ruleBlock) const FL_IOVERRIDE; + + /** + Activates the first @f$n@f$ rules whose activation degrees are greater than or + equal to the given threshold. The rules are iterated in the order the + rules were added to the rule block. + @param ruleBlock is the rule block to activate + */ + virtual void activate(RuleBlock* ruleBlock) FL_IOVERRIDE; + + virtual First* clone() const FL_IOVERRIDE; + + static Activation* constructor(); + }; + +} + + +#endif /* FL_FIRST_H */ diff --git a/fuzzylite/fl/activation/General.h b/fuzzylite/fl/activation/General.h new file mode 100644 index 0000000..8b057e9 --- /dev/null +++ b/fuzzylite/fl/activation/General.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_GENERAL_H +#define FL_GENERAL_H + +#include "fl/fuzzylite.h" + +#include "fl/activation/Activation.h" + +namespace fl { + + /** + The General class is a RuleBlock Activation method that activates every + rule following the order in which the rules were added to the rule block. + + @author Juan Rada-Vilela, Ph.D. + @see Rule + @see RuleBlock + @see ActivationFactory + @since 6.0 + */ + + class FL_API General : public Activation { + public: + + General(); + virtual ~General(); + FL_DEFAULT_COPY_AND_MOVE(General) + + virtual std::string className() const FL_IOVERRIDE; + + /** + No parameters are required to configure the activation method. + @return an empty string + */ + virtual std::string parameters() const FL_IOVERRIDE; + + /** + No parameters are required to configure the activation method. + @param parameters is an empty string + */ + virtual void configure(const std::string& parameters) FL_IOVERRIDE; + + virtual Complexity complexity(const RuleBlock* ruleBlock) const FL_IOVERRIDE; + + /** + Activates every rule in the given rule block following the order in + which the rules were added. + @param ruleBlock is the rule block to activate + */ + virtual void activate(RuleBlock* ruleBlock) FL_IOVERRIDE; + + virtual General* clone() const FL_IOVERRIDE; + + static Activation* constructor(); + }; +} + +#endif /* FL_GENERAL_H */ diff --git a/fuzzylite/fl/activation/Highest.h b/fuzzylite/fl/activation/Highest.h new file mode 100644 index 0000000..d3abc72 --- /dev/null +++ b/fuzzylite/fl/activation/Highest.h @@ -0,0 +1,86 @@ +/* + 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_HIGHEST_H +#define FL_HIGHEST_H + +#include "fl/fuzzylite.h" + +#include "fl/activation/Activation.h" + +namespace fl { + + /** + The Highest class is a RuleBlock Activation method that activates a given + number of rules with highest activation degrees in descending order. + + @author Juan Rada-Vilela, Ph.D. + @see Lowest + @see Rule + @see RuleBlock + @see ActivationFactory + @since 6.0 + */ + class FL_API Highest : public Activation { + private: + int _numberOfRules; + public: + explicit Highest(int numberOfRules = 1); + virtual ~Highest(); + FL_DEFAULT_COPY_AND_MOVE(Highest) + + virtual std::string className() const FL_IOVERRIDE; + + /** + Returns the number of rules to activate. + @return number of rules to activate + */ + virtual std::string parameters() const FL_IOVERRIDE; + + /** + Configures the activation method with the number of rules to activate. + @param parameters contains the number of rules to activate + */ + virtual void configure(const std::string& parameters) FL_IOVERRIDE; + + /** + Sets the number of rules to activate + @param numberOfRules is the number of rules to activate + */ + virtual void setNumberOfRules(int numberOfRules); + + /** + Returns the number of rules to activate + @return the number of rules to activate + */ + virtual int getNumberOfRules() const; + + virtual Complexity complexity(const RuleBlock* ruleBlock) const FL_IOVERRIDE; + + /** + Activates the given number of rules with the highest activation + degrees + @param ruleBlock is the rule block to activate. + */ + virtual void activate(RuleBlock* ruleBlock) FL_IOVERRIDE; + + virtual Highest* clone() const FL_IOVERRIDE; + + static Activation* constructor(); + }; +} + +#endif /* FL_HIGHEST_H */ diff --git a/fuzzylite/fl/activation/Last.h b/fuzzylite/fl/activation/Last.h new file mode 100644 index 0000000..9dadede --- /dev/null +++ b/fuzzylite/fl/activation/Last.h @@ -0,0 +1,103 @@ +/* + 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_LAST_H +#define FL_LAST_H + + +#include "fl/activation/Activation.h" + +namespace fl { + + /** + The Last class is a RuleBlock Activation method that activates the last + @f$n@f$ rules whose activation degrees are greater than or equal to the given + threshold. The rules are iterated in the reverse order in which they were + added to the rule block. + + @author Juan Rada-Vilela, Ph.D. + @see First + @see Rule + @see RuleBlock + @see ActivationFactory + @since 6.0 + */ + + class FL_API Last : public Activation { + private: + int _numberOfRules; + scalar _threshold; + public: + explicit Last(int numberOfRules = 1, scalar threshold = 0.0); + virtual ~Last(); + FL_DEFAULT_COPY_AND_MOVE(Last) + + virtual std::string className() const FL_IOVERRIDE; + + /** + Returns the number of rules and the threshold of the activation method + @return "numberOfRules threshold" + */ + virtual std::string parameters() const FL_IOVERRIDE; + + /** + Configures the activation method with the given number of rules and + threshold + @param parameters as "numberOfRules threshold" + */ + virtual void configure(const std::string& parameters) FL_IOVERRIDE; + + /** + Sets the number of rules for the activation degree + @param numberOfRules is the number of rules for the activation degree + */ + virtual void setNumberOfRules(int numberOfRules); + + /** + Gets the number of rules for the activation degree + @return the number of rules for the activation degree + */ + virtual int getNumberOfRules() const; + /** + Sets the threshold for the activation degree + @param threshold is the threshold for the activation degree + */ + virtual void setThreshold(scalar threshold); + + /** + Gets the threshold for the activation degree + @return the threshold for the activation degree + */ + virtual scalar getThreshold() const; + + + virtual Complexity complexity(const RuleBlock* ruleBlock) const FL_IOVERRIDE; + + /** + Activates the last @f$n@f$ rules whose activation degrees are greater + than the given threshold. The rules are iterated in the reverse order + that the rules were added to the rule block. + @param ruleBlock is the rule block to activate + */ + virtual void activate(RuleBlock* ruleBlock) FL_IOVERRIDE; + + virtual Last* clone() const FL_IOVERRIDE; + + static Activation* constructor(); + }; +} + +#endif /* FL_LAST_H */ diff --git a/fuzzylite/fl/activation/Lowest.h b/fuzzylite/fl/activation/Lowest.h new file mode 100644 index 0000000..dab8419 --- /dev/null +++ b/fuzzylite/fl/activation/Lowest.h @@ -0,0 +1,87 @@ +/* + 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_LOWEST_H +#define FL_LOWEST_H + +#include "fl/fuzzylite.h" + +#include "fl/activation/Activation.h" + +namespace fl { + + /** + The Lowest class is a RuleBlock Activation method that activates a given + number of rules with lowest activation degrees in ascending order + + @author Juan Rada-Vilela, Ph.D. + @see Highest + @see Rule + @see RuleBlock + @see ActivationFactory + @since 6.0 + */ + class FL_API Lowest : public Activation { + private: + int _numberOfRules; + public: + explicit Lowest(int numberOfRules = 1); + virtual ~Lowest(); + FL_DEFAULT_COPY_AND_MOVE(Lowest) + + virtual std::string className() const FL_IOVERRIDE; + + /** + Returns the number of rules to activate + @return number of rules to activate + */ + virtual std::string parameters() const FL_IOVERRIDE; + + /** + Configures the activation method with the number of rules to activate + @param parameters contains the number of rules to activate + */ + virtual void configure(const std::string& parameters) FL_IOVERRIDE; + + /** + Sets the number of rules to activate + @param numberOfRules is the number of rules to activate + */ + virtual void setNumberOfRules(int numberOfRules); + + /** + Returns the number of rules to activate + @return the number of rules to activate + */ + virtual int getNumberOfRules() const; + + + virtual Complexity complexity(const RuleBlock* ruleBlock) const FL_IOVERRIDE; + + /** + Activates the rules with the lowest activation degrees in the given + rule block + @param ruleBlock is the rule block to activate + */ + virtual void activate(RuleBlock* ruleBlock) FL_IOVERRIDE; + + virtual Lowest* clone() const FL_IOVERRIDE; + + static Activation* constructor(); + }; +} + +#endif /* FL_LOWEST_H */ diff --git a/fuzzylite/fl/activation/Proportional.h b/fuzzylite/fl/activation/Proportional.h new file mode 100644 index 0000000..09e51a7 --- /dev/null +++ b/fuzzylite/fl/activation/Proportional.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_PROPORTIONAL_H +#define FL_PROPORTIONAL_H + +#include "fl/activation/Activation.h" + +namespace fl { + + /** + The Proportional class is a RuleBlock Activation method that activates + the rules utilizing activation degrees proportional to the activation + degrees of the other rules, thus the sum of the activation degrees is + equal to one. + + @author Juan Rada-Vilela, Ph.D. + @see Rule + @see RuleBlock + @see ActivationFactory + @since 6.0 + */ + class FL_API Proportional : public Activation { + public: + Proportional(); + virtual ~Proportional(); + FL_DEFAULT_COPY_AND_MOVE(Proportional) + + virtual std::string className() const FL_IOVERRIDE; + + /** + No parameters are required to configure the activation method + @return an empty string + */ + virtual std::string parameters() const FL_IOVERRIDE; + + /** + No parameters are required to configure the activation method + @param parameters is an empty string + */ + virtual void configure(const std::string& parameters) FL_IOVERRIDE; + + virtual Complexity complexity(const RuleBlock* ruleBlock) const FL_IOVERRIDE; + + /** + Activates the rules utilizing activation degrees proportional to + the activation degrees of the other rules in the rule block. + @param ruleBlock is the rule block to activate. + */ + virtual void activate(RuleBlock* ruleBlock) FL_IOVERRIDE; + + virtual Proportional* clone() const FL_IOVERRIDE; + + static Activation* constructor(); + }; +} + +#endif /* FL_PROPORTIONAL_H */ diff --git a/fuzzylite/fl/activation/Threshold.h b/fuzzylite/fl/activation/Threshold.h new file mode 100644 index 0000000..0baadfa --- /dev/null +++ b/fuzzylite/fl/activation/Threshold.h @@ -0,0 +1,183 @@ +/* + 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_THRESHOLD_H +#define FL_THRESHOLD_H + +#include "fl/fuzzylite.h" + +#include "fl/activation/Activation.h" + +#include <vector> + +namespace fl { + + /** + The Threshold class is a RuleBlock Activation method that activates the + rules whose activation degrees satisfy the equation given by the + comparison operator and the threshold, and deactivates the rules which do + not satisfy the equation. + + @author Juan Rada-Vilela, Ph.D. + @see Rule + @see RuleBlock + @see ActivationFactory + @since 6.0 + */ + + class FL_API Threshold : public Activation { + public: + + /** + Comparison is an enumerator that provides six comparison operators + between the activation degree @f$a@f$ and the threshold @f$\theta@f$. + */ + enum Comparison { + /**@f$a < \theta@f$*/ + LessThan, + /**@f$a \leq \theta@f$*/ + LessThanOrEqualTo, + /**@f$a = \theta@f$*/ + EqualTo, + /**@f$a \neq \theta@f$*/ + NotEqualTo, + /**@f$a \geq \theta@f$*/ + GreaterThanOrEqualTo, + /**@f$a > \theta@f$*/ + GreaterThan + }; + private: + Comparison _comparison; + scalar _value; + public: + explicit Threshold(Comparison comparison = GreaterThanOrEqualTo, scalar threshold = 0.0); + explicit Threshold(const std::string& comparison, scalar threshold); + virtual ~Threshold(); + FL_DEFAULT_COPY_AND_MOVE(Threshold) + + virtual std::string className() const FL_IOVERRIDE; + + /** + Returns the comparison operator followed by the threshold. + @return comparison operator and threshold + */ + virtual std::string parameters() const FL_IOVERRIDE; + + /** + Configures the activation method with the comparison operator and the + threshold. + @param parameters is the comparison operator and threshold + */ + virtual void configure(const std::string& parameters) FL_IOVERRIDE; + + /** + Sets the comparison operator for the activation method + @param comparison is the operator for the activation method + */ + virtual void setComparison(Comparison comparison); + + /** + Gets the comparison operator for the activation method + @return comparison operator for the activation method + */ + virtual Comparison getComparison() const; + + /** + Returns the comparison operator of the activation method + @return the comparison operator in (`==`, `!=`, `<`, `>`, `<=`, `>=`) + */ + virtual std::string comparisonOperator() const; + + /** + Returns the given comparison operator of the activation method + @param comparison is a valid enum value + @return the comparison operator for the given enum value + @throws fl::Exception if the given comparison operator is not valid + */ + virtual std::string comparisonOperator(Comparison comparison) const; + + /** + Returns the list of available comparison operators of the activation + method + @return (`==`, `!=`, `<`, `>`, `<=`, `>=`) + */ + virtual std::vector<std::string> availableComparisonOperators() const; + + + /** + Parses the comparison operator, or throws an + exception if the parameter does not correspond to a valid operator + @param comparisonOperator is an operator in (`==`, `!=`, `<`, `>`, + `<=`, `>=`) + */ + virtual Comparison parseComparison(const std::string& comparisonOperator) const; + + /** + Sets the threshold value of the activation method + @param value is the threshold value for activation degrees + */ + virtual void setValue(scalar value); + + /** + Gets the threshold value of the activation method + @return the threshold value of the activation method + */ + virtual scalar getValue() const; + + /** + Sets the comparison operator and the threshold for the activation + method + @param comparison is the comparison enumerator + @param value is the threshold of the activation method + */ + virtual void setThreshold(Comparison comparison, scalar value); + + /** + Sets the comparison operator and the threshold for the activation method + @param comparison is a valid comparison operator + @param value is the threshold for activation degrees + @throws fl::Exception if the comparison operator is not valid + */ + virtual void setThreshold(const std::string& comparison, scalar value); + + /** + Returns whether the activation method will activate a rule with + the given activation degree + @param activationDegree an activation degree + @return whether the comparison equation is satisfied with the + activation degree and the threshold + */ + virtual bool activatesWith(scalar activationDegree) const; + + + virtual Complexity complexity(const RuleBlock* ruleBlock) const FL_IOVERRIDE; + + /** + Activates the rules whose activation degrees satisfy the comparison + equation with the given threshold, and deactivate the rules which do + not. + @param ruleBlock is the rule block to activate + */ + virtual void activate(RuleBlock* ruleBlock) FL_IOVERRIDE; + + virtual Threshold* clone() const FL_IOVERRIDE; + + static Activation* constructor(); + }; + +} + +#endif /* FL_THRESHOLD_H */ |