LinguisticTerm.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright 2010 Juan Rada-Vilela
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. /*
  13. * File: Term.h
  14. * Author: jcrada
  15. *
  16. * Created on December 9, 2009, 12:27 AM
  17. */
  18. #ifndef FL_TERM_H
  19. #define FL_TERM_H
  20. #include "flScalar.h"
  21. #include <vector>
  22. #include <math.h>
  23. #include <string>
  24. #include "defs.h"
  25. #include "FuzzyOperation.h"
  26. #include "FuzzyOperator.h"
  27. namespace fl {
  28. class FuzzyOperator; //forward-declaration
  29. class LinguisticTerm {
  30. public:
  31. enum eMembershipFunction {
  32. MF_TRIANGULAR = 0, MF_TRAPEZOIDAL, MF_RECTANGULAR, MF_SHOULDER, MF_SINGLETON,
  33. MF_COMPOUND, MF_FUNCTION, MF_TAKAGI_SUGENO, MF_DISCRETE,
  34. //to implement
  35. MF_SIGMOIDAL, MF_COSINE, MF_GAUSSIAN,
  36. };
  37. private:
  38. const FuzzyOperator* _fuzzy_operator;
  39. std::string _name;
  40. flScalar _minimum;
  41. flScalar _maximum;
  42. flScalar _modulation;
  43. public:
  44. LinguisticTerm();
  45. LinguisticTerm(const std::string& name, flScalar minimum = -INFINITY,
  46. flScalar maximum = INFINITY);
  47. LinguisticTerm(const FuzzyOperator& fuzzy_op, const std::string& name,
  48. flScalar minimum = -INFINITY, flScalar maximum = INFINITY);
  49. virtual ~LinguisticTerm();
  50. virtual void setFuzzyOperator(const FuzzyOperator& fuzzy_op);
  51. virtual const FuzzyOperator& fuzzyOperator() const;
  52. virtual void setName(const std::string& name);
  53. virtual std::string name() const;
  54. virtual void setMinimum(flScalar min);
  55. virtual flScalar minimum() const;
  56. virtual void setMaximum(flScalar max);
  57. virtual flScalar maximum() const;
  58. virtual void setModulation(flScalar degree);
  59. virtual flScalar modulation() const;
  60. virtual flScalar defuzzify() const;
  61. virtual std::string toString() const;
  62. virtual LinguisticTerm* clone() const = 0;
  63. virtual flScalar membership(flScalar crisp) const = 0;
  64. virtual eMembershipFunction type() const = 0;
  65. virtual void samples(std::vector<flScalar>& x, std::vector<flScalar>& y,
  66. int samples = FL_SAMPLE_SIZE, int out_of_range = 0) const;
  67. virtual flScalar area() const;
  68. virtual void centroid(flScalar&x, flScalar& y) const;
  69. virtual flScalar areaAndCentroid(flScalar& x, flScalar& y) const;
  70. };
  71. }
  72. #endif /* FL_TERM_H */