summaryrefslogtreecommitdiff
path: root/fuzzylite/fl/term/Term.h
blob: 31dcabdd9264754d220e427d478954f4edbf8373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 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_TERM_H
#define FL_TERM_H

#include "fl/fuzzylite.h"

#include "fl/Operation.h"
#include "fl/Complexity.h"

#include <cmath>
#include <string>
#include <vector>

namespace fl {
    class Engine;

    /**
      The Term class is the abstract class for linguistic terms. The linguistic
      terms in this library can be divided in four groups as: `basic`,
      `extended`, `edge`, and `function`. The `basic` terms are Triangle,
      Trapezoid, Rectangle, and Discrete. The `extended` terms are Bell,
      Binary, Cosine, Gaussian, GaussianProduct, PiShape, SigmoidDifference,
      SigmoidProduct, and Spike. The `edge` terms are Concave, Ramp, Sigmoid,
      SShape, and ZShape. The `function` terms are Constant, Linear, and
      Function.

      In the figure below, the `basic` terms are represented in the first
      column, and the `extended` terms in the second and third columns. The
      `edge` terms are represented in the fifth and sixth rows, and the
      `function` terms in the last row.

      @image html terms.svg

      @author Juan Rada-Vilela, Ph.D.
      @see Variable
      @see InputVariable
      @see OutputVariable
      @since 4.0
     */
    class FL_API Term {
    private:
        std::string _name;
    protected:
        scalar _height;
    public:

        explicit Term(const std::string& name = "", scalar height = 1.0);
        virtual ~Term();
        FL_DEFAULT_COPY_AND_MOVE(Term)

        /**
          Sets the name of the term
          @param name is the name of term
         */
        virtual void setName(const std::string& name);
        /**
          Gets the name of the term
          @return the name of the term
         */
        virtual std::string getName() const;

        /**
          Sets the height of the term
          @param height is the height of the term
         */
        virtual void setHeight(scalar height);
        /**
          Gets the height of the term
          @return the height of the term
         */
        virtual scalar getHeight() const;

        /**
          Returns the representation of the term in the FuzzyLite Language
          @return the representation of the term in FuzzyLite Language
          @see FllExporter
         */
        virtual std::string toString() const;

        /**
          Returns the name of the class of the term
          @return the name of the class of the term
         */
        virtual std::string className() const = 0;
        /**
          Returns the parameters to configure the term. The parameters are
          separated by spaces. If there is one additional parameter, the
          parameter will be considered as the height of the term; otherwise,
          the height will be set to @f$1.0@f$
          @return the parameters to configure the term (@see Term::configure())
         */
        virtual std::string parameters() const = 0;
        /**
          Configures the term with the given parameters. The parameters are
          separated by spaces. If there is one additional parameter, the
          parameter will be considered as the height of the term; otherwise,
          the height will be set to @f$1.0@f$
          @param parameters is the parameters to configure the term
         */
        virtual void configure(const std::string& parameters) = 0;

        /**
         Computes the estimated complexity of evaluating the membership function
         @return the estimated complexity of evaluating the membership function
         */
        virtual Complexity complexity() const = 0;

        /**
          Computes the membership function value at @f$x@f$
          @param x
          @return the membership function value @f$\mu(x)@f$
         */
        virtual scalar membership(scalar x) const = 0;

        /**
          Creates a clone of the term
          @return a clone of the term
         */
        virtual Term* clone() const = 0;

        /**
          Updates the references (if any) to point to the current engine (useful
          when cloning engines or creating terms within Importer objects
          @param engine is the engine to which this term belongs to
         */
        virtual void updateReference(const Engine* engine);

        /**
          For monotonic terms, computes the tsukamoto value of the term for the
          given activation degree @f$\alpha@f$, that is,
          @f$ g_j(\alpha) = \{ z \in\mathbb{R} : \mu_j(z) = \alpha \} $@f. If
          the term is not monotonic (or does not override this method) the
          method computes the membership function @f$\mu(\alpha)@f$.
          @param activationDegree is the activationDegree
          @param minimum is the minimum value of the range of the term
          @param maximum is the maximum value of the range of the term
          @return the tsukamoto value of the term for the given activation degree
                  if the term is monotonic (or overrides this method), or
                  the membership function for the activation degree otherwise.
         */
        virtual scalar tsukamoto(scalar activationDegree, scalar minimum, scalar maximum) const;

        /**
          Indicates whether the term is monotonic.
          @return whether the term is monotonic.
         */
        virtual bool isMonotonic() const;
    };
}
#endif /* FL_TERM_H */