summaryrefslogtreecommitdiff
path: root/fuzzylite/fl
diff options
context:
space:
mode:
Diffstat (limited to 'fuzzylite/fl')
-rw-r--r--fuzzylite/fl/Benchmark.h400
-rw-r--r--fuzzylite/fl/Complexity.h297
-rw-r--r--fuzzylite/fl/Console.h143
-rw-r--r--fuzzylite/fl/Engine.h428
-rw-r--r--fuzzylite/fl/Exception.h110
-rw-r--r--fuzzylite/fl/Headers.h49
-rw-r--r--fuzzylite/fl/Operation.h1011
-rw-r--r--fuzzylite/fl/activation/Activation.h95
-rw-r--r--fuzzylite/fl/activation/First.h104
-rw-r--r--fuzzylite/fl/activation/General.h73
-rw-r--r--fuzzylite/fl/activation/Highest.h86
-rw-r--r--fuzzylite/fl/activation/Last.h103
-rw-r--r--fuzzylite/fl/activation/Lowest.h87
-rw-r--r--fuzzylite/fl/activation/Proportional.h71
-rw-r--r--fuzzylite/fl/activation/Threshold.h183
-rw-r--r--fuzzylite/fl/defuzzifier/Bisector.h47
-rw-r--r--fuzzylite/fl/defuzzifier/Centroid.h48
-rw-r--r--fuzzylite/fl/defuzzifier/Defuzzifier.h59
-rw-r--r--fuzzylite/fl/defuzzifier/IntegralDefuzzifier.h62
-rw-r--r--fuzzylite/fl/defuzzifier/LargestOfMaximum.h50
-rw-r--r--fuzzylite/fl/defuzzifier/MeanOfMaximum.h49
-rw-r--r--fuzzylite/fl/defuzzifier/SmallestOfMaximum.h49
-rw-r--r--fuzzylite/fl/defuzzifier/WeightedAverage.h51
-rw-r--r--fuzzylite/fl/defuzzifier/WeightedAverageCustom.h77
-rw-r--r--fuzzylite/fl/defuzzifier/WeightedDefuzzifier.h81
-rw-r--r--fuzzylite/fl/defuzzifier/WeightedSum.h51
-rw-r--r--fuzzylite/fl/defuzzifier/WeightedSumCustom.h78
-rw-r--r--fuzzylite/fl/factory/ActivationFactory.h46
-rw-r--r--fuzzylite/fl/factory/CloningFactory.h198
-rw-r--r--fuzzylite/fl/factory/ConstructionFactory.h180
-rw-r--r--fuzzylite/fl/factory/DefuzzifierFactory.h56
-rw-r--r--fuzzylite/fl/factory/FactoryManager.h131
-rw-r--r--fuzzylite/fl/factory/FunctionFactory.h44
-rw-r--r--fuzzylite/fl/factory/HedgeFactory.h32
-rw-r--r--fuzzylite/fl/factory/SNormFactory.h32
-rw-r--r--fuzzylite/fl/factory/TNormFactory.h32
-rw-r--r--fuzzylite/fl/factory/TermFactory.h32
-rw-r--r--fuzzylite/fl/fuzzylite.h341
-rw-r--r--fuzzylite/fl/hedge/Any.h47
-rw-r--r--fuzzylite/fl/hedge/Extremely.h53
-rw-r--r--fuzzylite/fl/hedge/Hedge.h56
-rw-r--r--fuzzylite/fl/hedge/HedgeFunction.h82
-rw-r--r--fuzzylite/fl/hedge/Not.h43
-rw-r--r--fuzzylite/fl/hedge/Seldom.h48
-rw-r--r--fuzzylite/fl/hedge/Somewhat.h44
-rw-r--r--fuzzylite/fl/hedge/Very.h42
-rw-r--r--fuzzylite/fl/imex/CppExporter.h139
-rw-r--r--fuzzylite/fl/imex/Exporter.h52
-rw-r--r--fuzzylite/fl/imex/FclExporter.h79
-rw-r--r--fuzzylite/fl/imex/FclImporter.h32
-rw-r--r--fuzzylite/fl/imex/FisExporter.h87
-rw-r--r--fuzzylite/fl/imex/FisImporter.h47
-rw-r--r--fuzzylite/fl/imex/FldExporter.h218
-rw-r--r--fuzzylite/fl/imex/FllExporter.h119
-rw-r--r--fuzzylite/fl/imex/FllImporter.h48
-rw-r--r--fuzzylite/fl/imex/Importer.h53
-rw-r--r--fuzzylite/fl/imex/JavaExporter.h124
-rw-r--r--fuzzylite/fl/imex/RScriptExporter.h246
-rw-r--r--fuzzylite/fl/norm/Norm.h56
-rw-r--r--fuzzylite/fl/norm/SNorm.h36
-rw-r--r--fuzzylite/fl/norm/TNorm.h35
-rw-r--r--fuzzylite/fl/norm/s/AlgebraicSum.h49
-rw-r--r--fuzzylite/fl/norm/s/BoundedSum.h45
-rw-r--r--fuzzylite/fl/norm/s/DrasticSum.h50
-rw-r--r--fuzzylite/fl/norm/s/EinsteinSum.h46
-rw-r--r--fuzzylite/fl/norm/s/HamacherSum.h46
-rw-r--r--fuzzylite/fl/norm/s/Maximum.h46
-rw-r--r--fuzzylite/fl/norm/s/NilpotentMaximum.h47
-rw-r--r--fuzzylite/fl/norm/s/NormalizedSum.h44
-rw-r--r--fuzzylite/fl/norm/s/SNormFunction.h81
-rw-r--r--fuzzylite/fl/norm/s/UnboundedSum.h52
-rw-r--r--fuzzylite/fl/norm/t/AlgebraicProduct.h47
-rw-r--r--fuzzylite/fl/norm/t/BoundedDifference.h46
-rw-r--r--fuzzylite/fl/norm/t/DrasticProduct.h50
-rw-r--r--fuzzylite/fl/norm/t/EinsteinProduct.h47
-rw-r--r--fuzzylite/fl/norm/t/HamacherProduct.h46
-rw-r--r--fuzzylite/fl/norm/t/Minimum.h45
-rw-r--r--fuzzylite/fl/norm/t/NilpotentMinimum.h48
-rw-r--r--fuzzylite/fl/norm/t/TNormFunction.h81
-rw-r--r--fuzzylite/fl/rule/Antecedent.h150
-rw-r--r--fuzzylite/fl/rule/Consequent.h116
-rw-r--r--fuzzylite/fl/rule/Expression.h93
-rw-r--r--fuzzylite/fl/rule/Rule.h264
-rw-r--r--fuzzylite/fl/rule/RuleBlock.h194
-rw-r--r--fuzzylite/fl/term/Accumulated.h94
-rw-r--r--fuzzylite/fl/term/Activated.h84
-rw-r--r--fuzzylite/fl/term/Aggregated.h212
-rw-r--r--fuzzylite/fl/term/Bell.h80
-rw-r--r--fuzzylite/fl/term/Binary.h132
-rw-r--r--fuzzylite/fl/term/Concave.h84
-rw-r--r--fuzzylite/fl/term/Constant.h57
-rw-r--r--fuzzylite/fl/term/Cosine.h75
-rw-r--r--fuzzylite/fl/term/Discrete.h245
-rw-r--r--fuzzylite/fl/term/Function.h312
-rw-r--r--fuzzylite/fl/term/Gaussian.h74
-rw-r--r--fuzzylite/fl/term/GaussianProduct.h101
-rw-r--r--fuzzylite/fl/term/Linear.h151
-rw-r--r--fuzzylite/fl/term/PiShape.h105
-rw-r--r--fuzzylite/fl/term/Ramp.h101
-rw-r--r--fuzzylite/fl/term/Rectangle.h74
-rw-r--r--fuzzylite/fl/term/SShape.h81
-rw-r--r--fuzzylite/fl/term/Sigmoid.h88
-rw-r--r--fuzzylite/fl/term/SigmoidDifference.h90
-rw-r--r--fuzzylite/fl/term/SigmoidProduct.h91
-rw-r--r--fuzzylite/fl/term/Spike.h70
-rw-r--r--fuzzylite/fl/term/Term.h136
-rw-r--r--fuzzylite/fl/term/Trapezoid.h94
-rw-r--r--fuzzylite/fl/term/Triangle.h84
-rw-r--r--fuzzylite/fl/term/ZShape.h80
-rw-r--r--fuzzylite/fl/variable/InputVariable.h48
-rw-r--r--fuzzylite/fl/variable/OutputVariable.h214
-rw-r--r--fuzzylite/fl/variable/Variable.h254
112 files changed, 9914 insertions, 1982 deletions
diff --git a/fuzzylite/fl/Benchmark.h b/fuzzylite/fl/Benchmark.h
new file mode 100644
index 0000000..9a212db
--- /dev/null
+++ b/fuzzylite/fl/Benchmark.h
@@ -0,0 +1,400 @@
+/*
+ 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_BENCHMARK_H
+#define FL_BENCHMARK_H
+
+#include "fl/fuzzylite.h"
+
+#include "fl/Complexity.h"
+#include "fl/imex/FldExporter.h"
+
+#include <string>
+#include <vector>
+
+namespace fl {
+
+ class Engine;
+
+ /**
+ The Benchmark class is designed to evaluate the performance of an Engine.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Engine
+ @since 6.0
+ */
+ class FL_API Benchmark {
+ private:
+ std::string _name;
+ Engine* _engine;
+ std::vector<std::vector<scalar> > _expected;
+ std::vector<std::vector<scalar> > _obtained;
+ std::vector<scalar> _times;
+ scalar _tolerance;
+
+ public:
+
+ /**
+ Unit of time to utilize in the results
+ */
+ enum TimeUnit {
+ NanoSeconds, MicroSeconds, MilliSeconds, Seconds, Minutes, Hours
+ };
+
+ /**
+ Shape of the table of results
+ */
+ enum TableShape {
+ Horizontal, Vertical
+ };
+
+ /**
+ Contents of the table of results
+ */
+ enum TableContents {
+ Header = 1, Body = 2, HeaderAndBody = (Header | Body)
+ };
+
+ /**
+ Type of error between expected and obtained values
+ */
+ enum ErrorType {
+ NonFinite, Accuracy, All
+ };
+
+ explicit Benchmark(const std::string& name = "", Engine* engine = fl::null,
+ scalar tolerance = fuzzylite::macheps());
+ virtual ~Benchmark();
+ FL_DEFAULT_COPY_AND_MOVE(Benchmark)
+
+ /**
+ Sets the name of the benchmark
+ @param name is the name of the benchmark
+ */
+ void setName(const std::string& name);
+ /**
+ Gets the name of the benchmark
+ @return name is the name of the benchmark
+ */
+ std::string getName() const;
+
+ /**
+ Sets the engine to benchmark
+ @param engine is the engine to benchmark
+ */
+ void setEngine(Engine* engine);
+ /**
+ Gets the engine to benchmark
+ @return the engine to benchmark
+ */
+ Engine* getEngine() const;
+
+ /**
+ Sets the set of expected values from the engine, where the inner vector
+ contains the input values and output values
+ @param expected is the set of expected values from the engine
+ */
+ void setExpected(const std::vector<std::vector<scalar> >& expected);
+ /**
+ Gets the set of expected values from the engine, where the inner vector
+ contains the input values and output values
+ @return the set of expected values from the engine
+ */
+ const std::vector<std::vector<scalar> >& getExpected() const;
+
+ /**
+ Sets the set of obtained values from the engine, where the inner vector
+ contains the input values and output values
+ @param obtained is the set of obtained values from the engine
+ */
+ void setObtained(const std::vector<std::vector<scalar> >& obtained);
+ /**
+ Gets the set of obtained values from the engine, where the inner vector
+ contains the input values and output values
+ @return the set of obtained values from the engine
+ */
+ const std::vector<std::vector<scalar> >& getObtained() const;
+
+ /**
+ Sets the vector of nanoseconds taken to produce the set of obtained values
+ from the set of expected input values
+ @param times is the vector of nanoseconds taken to produce the set of obtained values
+ from the set of expected input values
+ */
+ void setTimes(const std::vector<scalar> times);
+ /**
+ Gets the vector of nanoseconds taken to produce the set of obtained values
+ from the set of expected input values
+ @return the vector of nanoseconds taken to produce the set of obtained values
+ from the set of expected input values
+ */
+ const std::vector<scalar>& getTimes() const;
+
+ /**
+ Sets the tolerance above which the difference between an expected and
+ obtained value from the engine is considered an error
+ @param tolerance is the tolerance above which the difference between
+ an expected and obtained value from the engine is considered an error
+ */
+ void setTolerance(scalar tolerance);
+ /**
+ Gets the tolerance above which the difference between an expected and
+ obtained value from the engine is considered an error
+ @return the tolerance above which the difference between an expected
+ and obtained value from the engine is considered an error
+ */
+ scalar getTolerance() const;
+
+ /**
+ Produces and loads into memory the set of expected values from the
+ engine
+ @param values is the number of values to evaluate the engine upon
+ @param scope is the scope of the values to generate
+ @throws Exception if the engine is not set
+ */
+ virtual void prepare(int values, FldExporter::ScopeOfValues scope);
+ /**
+ Reads and loads into memory the set of expected values from the
+ engine
+ @param reader is the reader of a set of lines containing
+ space-separated values
+ @param numberOfLines is the maximum number of lines to read from the
+ reader, and a value $f@n=(\infty, -1]$f@ reads the entire file.
+ */
+ virtual void prepare(std::istream& reader, long numberOfLines = -1);
+
+ /**
+ Runs the benchmark on the engine only once
+ @return the time in nanoseconds required by the run, which is
+ also appended to the times stored in Benchmark::getTimes()
+ */
+ virtual scalar runOnce();
+ /**
+ Runs the benchmark on the engine multiple times
+ @param times is the number of times to run the benchmark on the engine
+ @return vector of the time in nanoseconds required by each run, which is
+ also appended to the times stored in Benchmark::getTimes()
+ */
+ virtual std::vector<scalar> run(int times);
+
+ /**
+ Resets the benchmark to be ready to run again
+ */
+ virtual void reset();
+
+ /**
+ Indicates whether errors can be computed based on the expected and
+ obtained values from the benchmark. If the benchmark was prepared from
+ a file reader and the file included columns of expected output values
+ and the benchmark has been run at least once, then the benchmark can
+ automatically compute the errors and will automatically include them in
+ the results.
+ @return whether errors can be computed based on the expected and
+ obtained values from the benchmark
+ */
+ virtual bool canComputeErrors() const;
+
+ /**
+ Computes the mean squared error over all output variables considering
+ only those cases where there is an accuracy error as defined in
+ Benchmark::accuracyErrors().
+ @return the mean squared error over all the output variables.
+ */
+ virtual scalar meanSquaredError() const;
+
+ /**
+ Computes the mean squared error of the given output variable
+ considering only those cases where there is an accuracy error
+ as defined in Benchmark::accuracyErrors().
+ @param outputVariable is the output variable to compute the errors for
+ @return the mean squared error over the given output variable.
+ */
+ virtual scalar meanSquaredError(const OutputVariable* outputVariable) const;
+
+ /**
+ Computes the number of errors over all the output variables caused by
+ non-finite differences or accuracy differences. An error is counted when
+ the difference between the expected and obtained values is not finite,
+ or the absolute difference between the expected and obtained values
+ is not smaller than the tolerance.
+ @return the number of errors over all the output variables caused by
+ non-finite differences or accuracy differences
+ */
+ virtual int allErrors() const;
+
+ /**
+ Computes the number of errors of the given output variable caused by
+ non-finite differences or accuracy differences. An error is counted when
+ the difference between the expected and obtained values is not finite,
+ or the absolute difference between the expected and obtained values
+ is not smaller than the tolerance.
+ @param outputVariable is the output variable to account the errors for
+ @return the number of errors of the given output variable caused by
+ non-finite differences or accuracy differences
+ */
+ virtual int allErrors(const OutputVariable* outputVariable) const;
+
+ /**
+ Computes the number of errors over all the output variables caused by
+ non-finite differences (ie, infinity and NaN). An error is counted when
+ the difference between the expected and obtained values is not finite.
+ @return the number of errors over all the output variables caused by
+ non-finite differences
+ */
+ virtual int nonFiniteErrors() const;
+
+ /**
+ Computes the number of errors of the given output variable caused by
+ non-finite differences (ie, infinity and NaN). An error is counted when
+ the difference between the expected and obtained values is not finite.
+ @param outputVariable is the output variable to account the errors for
+ @return the number of errors of the given output variable caused by
+ non-finite differences
+ */
+ virtual int nonFiniteErrors(const OutputVariable* outputVariable) const;
+
+ /**
+ Computes the number of errors over all the output variables caused by
+ a significant difference in accuracy. An error is counted when the
+ absolute difference between the expected and obtained values
+ is not smaller than the tolerance.
+
+ @f$\text{E} = \sum_y \sum_i \epsilon_i^y, \text{where } \epsilon_i^y =
+ \begin{cases}
+ 0 & \text{if} |e_i^y - o^y_i| < \theta\\
+ 1 & \text{otherwise}
+ \end{cases}
+ @f$,
+ @f$y@f$ is the set of output variables, @f$e@f$ is the set of
+ expected output values, @f$o@f$ is the set of obtained output values,
+ and @f$\theta@f$ is the tolerance
+
+ @return the number of errors over all the output variables caused by
+ a significant difference in accuracy
+ */
+ virtual int accuracyErrors() const;
+
+
+ /**
+ Computes the number of errors over the given output variable caused by
+ a significant difference in accuracy. An error is counted when the
+ absolute difference between the expected and obtained values
+ is not smaller than the tolerance.
+
+ @f$\text{E} = \sum_i \epsilon_i, \text{where } \epsilon_i =
+ \begin{cases}
+ 0 & \text{if} |e_i - o_i| < \theta\\
+ 1 & \text{otherwise}
+ \end{cases}
+ @f$,
+ @f$e@f$ is the set of expected output values,
+ @f$o@f$ is the set of obtained output values,
+ and @f$\theta@f$ is the tolerance
+
+ @param outputVariable is the output variable to account the errors for
+ @return the number of errors of the given output variable caused by
+ a significant difference in accuracy
+ */
+ virtual int accuracyErrors(const OutputVariable* outputVariable) const;
+
+ /**
+ Computes the number of errors of the given type over all the output
+ variables.
+ @param errorType is the type of error to account for
+ @return the number of errors over all the output variables
+ */
+ virtual int numberOfErrors(ErrorType errorType) const;
+
+ /**
+ Computes the number of errors of the given type over the given output
+ variable.
+ @param errorType is the type of error to account for
+ @param outputVariable is the output variable to account the errors for
+ @return the number of errors over the given output variable
+ */
+ virtual int numberOfErrors(ErrorType errorType,
+ const OutputVariable* outputVariable) const;
+
+ /**
+ Returns the name of the time unit
+ @param unit is the time unit
+ @return the name of the time unit
+ */
+ static std::string stringOf(TimeUnit unit);
+
+ /**
+ Returns the factor of the given unit from NanoSeconds
+ @param unit is the time unit
+ @return the factor of the given unit from NanoSeconds
+ */
+ static scalar factorOf(TimeUnit unit);
+ /**
+ Converts the time to different scales
+ @param time is the time to convert
+ @param from is the units of the time to convert from
+ @param to is the units of the time to convert to
+ @return the time in the units specified
+ */
+ static scalar convert(scalar time, TimeUnit from, TimeUnit to);
+
+ /**
+ Returns the header of a horizontal table of results
+ @param runs is the number of times the benchmark will be run, hence
+ producing the relevant number of columns for each run
+ @param includeErrors indicates whether to include columns for computing
+ the errors
+ @return the header of a horizontal table of results
+ */
+ virtual std::vector<std::string> header(int runs, bool includeErrors = true);
+
+ /**Result is a type definition for a pair of strings*/
+ typedef std::pair<std::string, std::string> Result;
+ /**
+ Computes and returns the results from the benchmark aggregating the
+ statistics of all the output variables
+ @param timeUnit is the unit of time of the results
+ @param includeTimes indicates whether to include the times of each run
+ @return the results from the benchmark
+ */
+ virtual std::vector<Result> results(TimeUnit timeUnit = NanoSeconds, bool includeTimes = true) const;
+
+ /**
+ Computes and returns the results from the benchmark for the given output
+ variable
+ @param outputVariable is the output variable to compute the statistics for
+ @param timeUnit is the unit of time of the results
+ @param includeTimes indicates whether to include the times of each run
+ @return the results from the benchmark
+ */
+ virtual std::vector<Result> results(const OutputVariable* outputVariable,
+ TimeUnit timeUnit = NanoSeconds, bool includeTimes = true) const;
+
+ /**
+ Formats the results
+ @param results is the vector of results
+ @param shape is the shape to present the table of results
+ @param contents indicates the information to include in the table of results
+ @param delimiter is the delimiter of the table of results
+ @return the formatted results from the benchmark
+ */
+ virtual std::string format(std::vector<Result> results, TableShape shape,
+ TableContents contents, const std::string& delimiter = "\t") const;
+ };
+
+}
+
+#endif /* FL_BENCHMARK_H */
+
diff --git a/fuzzylite/fl/Complexity.h b/fuzzylite/fl/Complexity.h
new file mode 100644
index 0000000..a63138f
--- /dev/null
+++ b/fuzzylite/fl/Complexity.h
@@ -0,0 +1,297 @@
+/*
+ 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_COMPLEXITY_H
+#define FL_COMPLEXITY_H
+
+#include "fl/fuzzylite.h"
+
+#include <vector>
+
+namespace fl {
+ class Engine;
+ class InputVariable;
+ class OutputVariable;
+ class Variable;
+ class RuleBlock;
+ class Rule;
+
+ /**
+ The Complexity class is used throughout the library to estimate the
+ computational cost of the different components of the library
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Engine
+ @see Variable
+ @see OutputVariable
+ @see RuleBlock
+ @see Activation
+ @see Rule
+ @see Antecedent
+ @see Consequent
+ @see Hedge
+ @see Norm
+ @since 6.0
+ */
+
+ class FL_API Complexity {
+ private:
+ scalar _comparison;
+ scalar _arithmetic;
+ scalar _function;
+
+ public:
+ explicit Complexity(scalar all = 0.0);
+ explicit Complexity(scalar comparison, scalar arithmetic, scalar function);
+ virtual ~Complexity();
+ FL_DEFAULT_COPY_AND_MOVE(Complexity)
+
+ Complexity& operator+=(const Complexity& other);
+ Complexity& operator-=(const Complexity& other);
+ Complexity& operator*=(const Complexity& other);
+ Complexity& operator/=(const Complexity& other);
+
+ Complexity operator+(const Complexity& rhs) const;
+ Complexity operator-(const Complexity& rhs) const;
+ Complexity operator*(const Complexity& rhs) const;
+ Complexity operator/(const Complexity& rhs) const;
+
+ bool operator==(const Complexity& rhs) const;
+ bool operator!=(const Complexity& rhs) const;
+ bool operator<(const Complexity& rhs) const;
+ bool operator<=(const Complexity& rhs) const;
+ bool operator>(const Complexity& rhs) const;
+ bool operator>=(const Complexity& rhs) const;
+
+ /**
+ Increases the comparison measure by the given amount
+ @param comparison is the amount to increase the comparison measure by
+ @return the reference to the Complexity object with the updated comparison
+ measure
+ */
+ virtual Complexity& comparison(scalar comparison);
+ virtual void setComparison(scalar comparison);
+ virtual scalar getComparison() const;
+
+ /**
+ Increases the arithmetic measure by the given amount
+ @param arithmetic is the amount to increase the comparison measure by
+ @return the reference to the Complexity object with the updated arithmetic
+ measure
+ */
+ virtual Complexity& arithmetic(scalar arithmetic);
+ virtual void setArithmetic(scalar arithmetic);
+ virtual scalar getArithmetic() const;
+
+ /**
+ Increases the function measure by the given amount
+ @param function is the amount to increase the function measure by
+ @return the reference to the Complexity object with the updated function
+ measure
+ */
+ virtual Complexity& function(scalar function);
+ virtual void setFunction(scalar function);
+ virtual scalar getFunction() const;
+
+ /**
+ Returns a vector containing the measures of complexity
+ @return a vector containing the measures of complexity
+ */
+ typedef std::pair<std::string, scalar> Measure;
+ virtual std::vector<Measure> measures() const;
+
+ /**
+ Increases the complexity by the given parameter
+ @param x is the addend
+ @return the reference to the updated complexity
+ */
+ virtual Complexity& plus(const Complexity& x);
+ /**
+ Reduces the complexity by the given parameter
+ @param x is the subtrahend
+ @return the reference to the updated complexity object
+ */
+ virtual Complexity& minus(const Complexity& x);
+ /**
+ Multiplies the complexity by the given parameter
+ @param x is the multiplicand
+ @return the reference to the updated complexity object
+ */
+ virtual Complexity& multiply(const Complexity& x);
+ /**
+ Divides the complexity by the given parameter
+ @param x is the divisor
+ @return the reference to the updated complexity object
+ */
+ virtual Complexity& divide(const Complexity& x);
+
+ /**
+ Increases each measure by the given parameter
+ @param x is the addend
+ @return the reference to the updated complexity
+ */
+ virtual Complexity& plus(scalar x);
+ /**
+ Reduces each measure by the given parameter
+ @param x is the subtrahend
+ @return the reference to the updated complexity
+ */
+ virtual Complexity& minus(scalar x);
+ /**
+ Multiplies each measure by the given parameter
+ @param x is the multiplicand
+ @return the reference to the updated complexity
+ */
+ virtual Complexity& multiply(scalar x);
+ /**
+ Divides each measure by the given parameter
+ @param x is the divisor
+ @return the reference to the updated complexity
+ */
+ virtual Complexity& divide(scalar x);
+
+ /**
+ Compares the complexity for equality to another with the given tolerance
+ @param x is the complexity to compare against
+ @param macheps is the tolerance to compare floating-point values
+ @return `true` if every measure in this satisfies Op::isEq(this, x, macheps),
+ and `false` otherwise
+ */
+ virtual bool equals(const Complexity& x, scalar macheps = fuzzylite::macheps()) const;
+ /**
+ Compares the complexity for strict inequality (less than) to another
+ with the given tolerance
+ @param x is the complexity to compare against
+ @param macheps is the tolerance to compare floating-point values
+ @return `true` if every measure in this satisfies Op::isLt(this, x, macheps),
+ and `false` otherwise
+ */
+ virtual bool lessThan(const Complexity& x, scalar macheps = fuzzylite::macheps()) const;
+ /**
+ Compares the complexity for inequality (less than or equal to) to another
+ with the given tolerance
+ @param x is the complexity to compare against
+ @param macheps is the tolerance to compare floating-point values
+ @return `true` if every measure in this satisfies Op::isLE(this, x, macheps),
+ and `false` otherwise
+ */
+ virtual bool lessThanOrEqualsTo(const Complexity& x, scalar macheps = fuzzylite::macheps()) const;
+ /**
+ Compares the complexity for strict inequality (greater than) to another
+ with the given tolerance
+ @param x is the complexity to compare against
+ @param macheps is the tolerance to compare floating-point values
+ @return `true` if every measure in this satisfies Op::isGt(this, x, macheps),
+ and `false` otherwise
+ */
+ virtual bool greaterThan(const Complexity& x, scalar macheps = fuzzylite::macheps()) const;
+ /**
+ Compares the complexity for inequality (greater than or equal to) to
+ another with the given tolerance
+ @param x is the complexity to compare against
+ @param macheps is the tolerance to compare floating-point values
+ @return `true` if every measure in this satisfies Op::isGE(this, x, macheps),
+ and `false` otherwise
+ */
+ virtual bool greaterThanOrEqualsTo(const Complexity& x, scalar macheps = fuzzylite::macheps()) const;
+
+ /**
+ Computes the sum of the measures
+ @return the sum of the measures
+ */
+ virtual scalar sum() const;
+
+ /**
+ Computes the norm of the complexity
+ @return the norm of the complexity
+ */
+ virtual scalar norm() const;
+
+ /**
+ Returns the measures of the complexity
+ @return the measures of the complexity
+ */
+ virtual std::string toString() const;
+
+ /**
+ Computes the complexity of the given engine as the sum of complexities
+ of the rule blocks
+ @param engine is the engine for which to compute the complexity
+ @return the complexity of the given engine as the sum of complexities
+ of the rule blocks
+ */
+ virtual Complexity compute(const Engine* engine) const;
+
+ /**
+ Computes the complexity of the given input variable
+ @param inputVariable is the input variable for which to compute the complexity
+ @return the complexity of the given input variable
+ */
+ virtual Complexity compute(const InputVariable* inputVariable) const;
+ /**
+ Computes the complexity of the given output variable
+ @param outputVariable is the output variable for which to compute the complexity
+ @return the complexity of the given output variable
+ */
+ virtual Complexity compute(const OutputVariable* outputVariable) const;
+
+ /**
+ Computes the complexity of the given input variables
+ @param inputVariables is the vector of input variables for which to
+ compute the complexity
+ @return the complexity of the given input variables
+ */
+ virtual Complexity compute(const std::vector<InputVariable*>& inputVariables) const;
+ /**
+ Computes the complexity of the given output variables
+ @param outputVariables is the vector of output variables for which to
+ compute the complexity
+ @param complexityOfDefuzzification indicates whether to compute the
+ complexity of the variable including the defuzzification process
+ @return the complexity of the given output variables
+ */
+ virtual Complexity compute(const std::vector<OutputVariable*>& outputVariables,
+ bool complexityOfDefuzzification = false) const;
+ /**
+ Computes the complexity of the given variables
+ @param variables is the vector of variables for which to compute the
+ complexity
+ @return the complexity of the given variables
+ */
+ virtual Complexity compute(const std::vector<Variable*>& variables) const;
+
+ /**
+ Computes the complexity of the given rule block
+ @param ruleBlock is the rule block for which to compute the complexity
+ @return the complexity of the given rule block
+ */
+ virtual Complexity compute(const RuleBlock* ruleBlock) const;
+
+ /**
+ Computes the complexity of the given rule blocks
+ @param ruleBlocks is the vector of rule blocks for which to compute the
+ complexity
+ @return Computes the complexity of the given rule blocks
+ */
+ virtual Complexity compute(const std::vector<RuleBlock*>& ruleBlocks) const;
+
+ };
+
+
+}
+
+#endif /* COMPLEXITY_H */
+
diff --git a/fuzzylite/fl/Console.h b/fuzzylite/fl/Console.h
index 59e818d..b96d677 100644
--- a/fuzzylite/fl/Console.h
+++ b/fuzzylite/fl/Console.h
@@ -1,32 +1,23 @@
/*
- 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_CONSOLE_H
#define FL_CONSOLE_H
#include "fl/fuzzylite.h"
-
#include <map>
#include <string>
#include <vector>
@@ -34,57 +25,131 @@
namespace fl {
class Engine;
+ /**
+ The Console class is a command-line tool that helps to utilize the
+ `fuzzylite` library.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @since 4.0
+ */
class FL_API Console {
public:
+ /**
+ A command-line option given by key, value and description
+ */
struct Option {
std::string key, value, description;
- explicit Option(const std::string& key = "", const std::string& value = "", const std::string& description = "") :
- key(key), value(value), description(description) {
- }
+ explicit Option(const std::string& key = "",
+ const std::string& value = "",
+ const std::string& description = "");
};
+ /**Keyword for input file*/
static const std::string KW_INPUT_FILE;
+ /**Keyword for input file format*/
static const std::string KW_INPUT_FORMAT;
+ /**Keyword for output file*/
static const std::string KW_OUTPUT_FILE;
+ /**Keyword for output file format*/
static const std::string KW_OUTPUT_FORMAT;
+ /**Keyword for built-in example*/
static const std::string KW_EXAMPLE;
+ /**Keyword for number of decimals*/
static const std::string KW_DECIMALS;
- static const std::string KW_DATA_INPUT;
- static const std::string KW_DATA_MAXIMUM;
+ /**Keyword for file containing input data*/
+ static const std::string KW_DATA_INPUT_FILE;
+ /**Keyword for number of values to generate*/
+ static const std::string KW_DATA_VALUES;
+ /**Keyword for the scope of the number of values to generate*/
+ static const std::string KW_DATA_VALUES_SCOPE;
+ /**Keyword for exporting headers in FLD*/
static const std::string KW_DATA_EXPORT_HEADER;
+ /**Keyword for exporting input values in FLD*/
static const std::string KW_DATA_EXPORT_INPUTS;
+ /**
+ Creates a new Mamdani Engine based on the SimpleDimmer example
+ @return a new Mamdani Engine based on the SimpleDimmer example
+ */
static Engine* mamdani();
+ /**
+ Creates a new TakagiSugeno Engine based on the Approximation example of @f$sin(x)/x@f$
+ @return a new TakagiSugeno Engine based on the Approximation example of @f$sin(x)/x@f$
+ */
static Engine* takagiSugeno();
+ /**
+ Creates a new Hybrid Engine based on the Tipper example using Mamdani
+ and TakagiSugeno outputs.
+ @return a new Hybrid Engine based on the Tipper example using Mamdani
+ and TakagiSugeno outputs.
+ */
+ static Engine* hybrid();
+
+
protected:
- static std::map<std::string, std::string> parse(int argc, char** argv);
- static void process(const std::map<std::string, std::string>& options);
+ virtual std::map<std::string, std::string> parse(int argc, const char* argv[]);
+ virtual void process(const std::map<std::string, std::string>& options);
- static void process(const std::string& input, std::ostream& writer,
+ virtual void process(const std::string& input, std::ostream& writer,
const std::string& inputFormat, const std::string& outputFormat,
const std::map<std::string, std::string>& options);
- static int readCharacter();
- static void interactive(std::ostream& writer, Engine* engine);
- static std::string interactiveHelp();
-
- static void exportAllExamples(const std::string& from, const std::string& to);
- static void exportAllExamples(const std::string& from, const std::string& to, const std::string& path);
-#ifdef FL_CPP11
- static void benchmarkExamples(const std::string& path, int runs);
-#endif
+ virtual int readCharacter();
+ virtual void interactive(std::ostream& writer, Engine* engine);
+ virtual std::string interactiveHelp();
+
+ virtual void exportAllExamples(const std::string& from, const std::string& to);
+ virtual void exportAllExamples(const std::string& from, const std::string& to,
+ const std::string& examplesPath, const std::string& outputPath);
+
+ /**
+ Benchmarks the engine described in the FLL file against the dataset
+ contained in the FLD file.
+
+ @param fllFile is the file describing the engine in FLL format
+ @param fldFile is the file containing the dataset in FLD format
+ @param runs is the number of runs to evaluate the benchmarks
+ @param writer is the output where the results will be written to
+ @throws Exception if something goes wrong reading the files, importing the
+ engines or evaluating the benchmark
+ */
+
+ virtual void benchmark(const std::string& fllFile, const std::string& fldFile,
+ int runs, std::ofstream* writer = fl::null) const;
+ /**
+ Benchmarks the list of engines against the list of datasets, both described
+ as absolute or relative paths
+
+ @param fllFileList is the file containing the list of paths of engines in
+ FLL format
+ @param fldFileList is the file containing the list of paths of datasets in
+ FLD format
+ @param runs is the number of runs to evaluate the benchmarks
+ @param writer is the output where the results will be written to
+ @throws Exception if something goes wrong reading the files, importing the
+ engines or evaluating the benchmark
+ */
+ virtual void benchmarks(const std::string& fllFileList, const std::string& fldFileList,
+ int runs, std::ofstream* writer = fl::null) const;
public:
- static std::string usage();
- static std::vector<Option> availableOptions();
-
- static int main(int argc, char** argv);
+ /**
+ Returns a string representation of the usage of the command-line tool
+ @return a string representation of the usage of the command-line tool
+ */
+ virtual std::string usage();
+
+ /**
+ Returns a vector of the options available from the command line
+ @return a vector of the options available from the command line
+ */
+ virtual std::vector<Option> availableOptions();
+
+ static int main(int argc, const char* argv[]);
};
-
}
-
#endif /* FL_CONSOLE_H */
diff --git a/fuzzylite/fl/Engine.h b/fuzzylite/fl/Engine.h
index 532c5e9..3a88478 100644
--- a/fuzzylite/fl/Engine.h
+++ b/fuzzylite/fl/Engine.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_ENGINE_H
@@ -27,7 +19,7 @@
#include "fl/fuzzylite.h"
-#include "fl/defuzzifier/IntegralDefuzzifier.h"
+#include "fl/Complexity.h"
#include <string>
#include <vector>
@@ -42,16 +34,29 @@ namespace fl {
class TNorm;
class SNorm;
class Defuzzifier;
-
+ class Activation;
+
+ /**
+ The Engine class is the core class of the library as it groups the
+ necessary components of a fuzzy logic controller.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see InputVariable
+ @see OutputVariable
+ @see RuleBlock
+ @since 4.0
+ */
class FL_API Engine {
private:
- void copyFrom(const Engine& source);
- protected:
std::string _name;
+ std::string _description;
std::vector<InputVariable*> _inputVariables;
std::vector<OutputVariable*> _outputVariables;
- std::vector<RuleBlock*> _ruleblocks;
+ std::vector<RuleBlock*> _ruleBlocks;
+
+ void copyFrom(const Engine& source);
+ protected:
void updateReferences() const;
public:
@@ -61,92 +66,413 @@ namespace fl {
virtual ~Engine();
FL_DEFAULT_MOVE(Engine)
- //TODO: remove int resolution in v6.0
- virtual void configure(const std::string& conjunctionT,
- const std::string& disjunctionS,
- const std::string& activationT,
- const std::string& accumulationS,
+ /**
+ Configures the engine with the given operators
+ @param conjunction is a TNorm registered in the TNormFactory
+ @param disjunction is an SNorm registered in the SNormFactory
+ @param implication is an TNorm registered in the TNormFactory
+ @param aggregation is an SNorm registered in the SNormFactory
+ @param defuzzifier is a defuzzifier registered in the DefuzzifierFactory
+ @param activation is an activation method registered in the ActivationFactory
+ */
+ virtual void configure(const std::string& conjunction,
+ const std::string& disjunction,
+ const std::string& implication,
+ const std::string& aggregation,
const std::string& defuzzifier,
- int resolution = IntegralDefuzzifier::defaultResolution());
+ const std::string& activation);
+ /**
+ Configures the engine with clones of the given object operators, taking
+ ownership of the objects.
+
+ @param conjunction is the operator to process the propositions joined
+ by `and` in the antecedent of the rules
+ @param disjunction is the operator to process the propositions
+ joined by `or` in the antecedent of the rules
+ @param implication is the operator to modify the consequents of the
+ rules based on the activation degree of the antecedents of the rules
+ @param aggregation is the operator to aggregate the resulting
+ implications of the rules
+ @param defuzzifier is the operator to transform the aggregated
+ implications into a single scalar value
+ @param activation is the activation method to activate and fire the
+ rule blocks
+ */
virtual void configure(TNorm* conjunction, SNorm* disjunction,
- TNorm* activation, SNorm* accumulation,
- Defuzzifier* defuzzifier);
+ TNorm* implication, SNorm* aggregation,
+ Defuzzifier* defuzzifier, Activation* activation);
+ /**
+ Indicates whether the engine has been configured correctly and is
+ ready for operation. In more advanced engines, the result of this
+ method should be taken as a suggestion and not as a prerequisite to
+ operate the engine.
+
+ @param status (if not null) contains the configuration errors of the engine
+ @return whether the engine is ready to operate
+ */
virtual bool isReady(std::string* status = fl::null) const;
+ /**
+ Computes the estimated complexity of operation of the engine
+ @return the estimated complexity of operation of the engine
+ */
+ virtual Complexity complexity() const;
+ /**
+ Processes the engine in its current state as follows: (a) Clears the
+ aggregated fuzzy output variables, (b) Activates the rule blocks, and
+ (c) Defuzzifies the output variables
+ @see Aggregated::clear()
+ @see RuleBlock::activate()
+ @see OutputVariable::defuzzify()
+ */
virtual void process();
+ /**
+ Restarts the engine by setting the values of the input variables to
+ fl::nan and clearing the output variables
+ @see Variable::setValue()
+ @see OutputVariable::clear()
+ */
virtual void restart();
+ /**
+ Sets the name of the engine
+ @param name is the name of the engine
+ */
virtual void setName(const std::string& name);
+ /**
+ Gets the name of the engine
+ @return the name of the engine
+ */
virtual std::string getName() const;
+ /**
+ Sets the description of the engine
+ @param description is the description of the engine
+ */
+ virtual void setDescription(const std::string& description);
+ /**
+ Gets the description of the engine
+ @return the description of the engine
+ */
+ virtual std::string getDescription() const;
+
+ /**
+ Sets the value of the given input variable.
+ The cost of this method is O(n), where n is the number of
+ input variables in the engine. For performance, please get the
+ variables by index.
+ @param name is the name of the input variable
+ @param value is the value for the input variable
+ */
virtual void setInputValue(const std::string& name, scalar value);
+ /**
+ Gets the value of the given output variable.
+ The cost of this method is O(n), where n is the number of
+ output variables in the engine. For performance, please get the
+ variables by index.
+ @param name is the name of the output variable
+ @return the value of the given output variable
+ */
virtual scalar getOutputValue(const std::string& name);
-
+ /**
+ Returns a string representation of the engine in the FuzzyLite
+ Language
+ @return a string representation of the engine in the FuzzyLite
+ Language
+ */
virtual std::string toString() const;
enum Type {
- Mamdani, Larsen, TakagiSugeno,
- Tsukamoto, InverseTsukamoto, Hybrid, Unknown
+ /**Mamdani: When the output variables have IntegralDefuzzifier%s*/
+ Mamdani,
+ /**Larsen: When Mamdani and AlgebraicProduct is the implication operator of
+ the rule blocks */
+ Larsen,
+ /**TakagiSugeno: When output variables have WeightedDefuzzifier%s of type
+ TakagiSugeno and the output variables have Constant, Linear, or
+ Function terms*/
+ TakagiSugeno,
+ /**Tsukamoto: When output variables have WeightedDefuzzifier%s of type
+ Tsukamoto and the output variables only have monotonic terms
+ (Concave, Ramp, Sigmoid, SShape, and ZShape)*/
+ Tsukamoto,
+ /**InverseTsukamoto: When output variables have WeightedDefuzzifier%s of type
+ TakagiSugeno and the output variables do not only have Constant,
+ Linear or Function terms*/
+ InverseTsukamoto,
+ /**Hybrid: When output variables have different defuzzifiers*/
+ Hybrid,
+ /**Unknown: When output variables have no defuzzifiers*/
+ Unknown
};
+ /**
+ Infers the type of the engine based on its current configuration
+
+ @param name stores a string representation of the engine type (if the
+ pointer passed is not `fl::null`)
+ @param reason stores a string representation explaining the reasons
+ for the inferred type (if the pointer passed is not `fl::null`)
+ @return the inferred type of the engine based on its current
+ configuration
+ */
virtual Type type(std::string* name = fl::null, std::string* reason = fl::null) const;
+ /**
+ Creates a clone of the engine
+ @return a clone of the engine
+ */
virtual Engine* clone() const;
+ /**
+ Returns a vector that contains the input variables followed by the
+ output variables in the order of insertion
+
+ @return a vector that contains the input variables followed by the
+ output variables in the order of insertion
+ */
virtual std::vector<Variable*> variables() const;
/**
- * Operations for iterable datatype _inputVariables
+ Adds the input variable
+ @param inputVariable is the input variable
*/
virtual void addInputVariable(InputVariable* inputVariable);
- virtual InputVariable* setInputVariable(InputVariable* inputVariable, int index);
- virtual void insertInputVariable(InputVariable* inputVariable, int index);
- virtual InputVariable* getInputVariable(int index) const;
+ /**
+ Sets the input variable at the given index
+ @param inputVariable is the input variable to set
+ @param index is the index at which the input variable is to be stored
+ @return the input variable previously stored at the given index
+ */
+ virtual InputVariable* setInputVariable(InputVariable* inputVariable, std::size_t index);
+ /**
+ Inserts the input variable at the given index, shifting other
+ variables one position to the right
+ @param inputVariable is the input variable to insert
+ @param index is the index at which the input variable is to be
+ inserted
+ */
+ virtual void insertInputVariable(InputVariable* inputVariable, std::size_t index);
+ /**
+ Gets the input variable at the given index
+ @param index is the given index
+ @return the input variable at the given index
+ */
+ virtual InputVariable* getInputVariable(std::size_t index) const;
+ /**
+ Gets the input variable of the given name after iterating the input
+ variables. The cost of this method is O(n), where n is the number of
+ input variables in the engine. For performance, please get the
+ variables by index.
+ @param name is the name of the input variable
+ @return input variable of the given name
+ @throws fl::Exception if there is no variable with the given name
+ */
virtual InputVariable* getInputVariable(const std::string& name) const;
- virtual InputVariable* removeInputVariable(int index);
+ /**
+ Removes the input variable at the given index (without deleting it)
+ and shifts the remaining input variables one position to the left
+ @param index is the given index
+ @return the input variable at the given index
+ */
+ virtual InputVariable* removeInputVariable(std::size_t index);
+ /**
+ Removes the input variable of the given name (without deleting it) and
+ shifts the remaining input variables one position to the left
+ @param name is the name of the input variable
+ @return the input variable of the given name
+ @throws fl::Exception if there is no variable with the given name
+ */
virtual InputVariable* removeInputVariable(const std::string& name);
+ /**
+ Indicates whether an input variable of the given name is in the input
+ variables
+ @param name is the name of the input variable
+ @return whether an input variable is registered with the given name
+ */
virtual bool hasInputVariable(const std::string& name) const;
- virtual int numberOfInputVariables() const;
+ /**
+ Returns the number of input variables added to the engine
+ @return the number of input variables added to the engine
+ */
+ virtual std::size_t numberOfInputVariables() const;
+ /**
+ Returns an immutable vector of input variables
+ @return an immutable vector of input variables
+ */
virtual const std::vector<InputVariable*>& inputVariables() const;
+ /**
+ Sets the vector of input variables
+ @param inputVariables is the vector of input variables
+ */
virtual void setInputVariables(const std::vector<InputVariable*>& inputVariables);
+ /**
+ Returns a mutable vector of input variables
+ @return a mutable vector of input variables
+ */
virtual std::vector<InputVariable*>& inputVariables();
/**
- * Operations for iterable datatype _outputVariables
+ Adds the output variable
+ @param outputVariable is the output variable
*/
virtual void addOutputVariable(OutputVariable* outputVariable);
- virtual OutputVariable* setOutputVariable(OutputVariable* outputVariable, int index);
- virtual void insertOutputVariable(OutputVariable* outputVariable, int index);
- virtual OutputVariable* getOutputVariable(int index) const;
+ /**
+ Sets the output variable at the given index
+ @param outputVariable is the output variable to set
+ @param index is the index at which the output variable is to be stored
+ @return the output variable previously stored at the given index
+ */
+ virtual OutputVariable* setOutputVariable(OutputVariable* outputVariable, std::size_t index);
+ /**
+ Inserts the output variable at the given index, shifting other
+ variables one position to the right
+ @param outputVariable is the output variable to insert
+ @param index is the index at which the output variable is to be inserted
+ */
+ virtual void insertOutputVariable(OutputVariable* outputVariable, std::size_t index);
+ /**
+ Gets the output variable at the given index
+ @param index is the given index
+ @return the output variable at the given index
+ */
+ virtual OutputVariable* getOutputVariable(std::size_t index) const;
+ /**
+ Gets the output variable of the given name after iterating the output
+ variables. The cost of this method is O(n), where n is the number of
+ output variables in the engine. For performance, please get the
+ variables by index.
+ @param name is the name of the output variable
+ @return output variable of the given name
+ @throws fl::Exception if there is no variable with the given name
+ */
virtual OutputVariable* getOutputVariable(const std::string& name) const;
+
+ /**
+ Indicates whether an output variable of the given name is in the
+ output variables
+ @param name is the name of the output variable
+ @return whether an output variable is registered with the given name
+ */
virtual bool hasOutputVariable(const std::string& name) const;
- virtual OutputVariable* removeOutputVariable(int index);
+ /**
+ Removes the output variable at the given index (without deleting it)
+ and shifts the remaining output variables one position to the left
+ @param index is the given index
+ @return the output variable at the given index
+ */
+ virtual OutputVariable* removeOutputVariable(std::size_t index);
+ /**
+ Removes the output variable of the given name (without deleting it)
+ and shifts the remaining output variables one position to the left
+ @param name is the name of the output variable
+ @return the output variable of the given name
+ @throws fl::Exception if there is no variable with the given name
+ */
virtual OutputVariable* removeOutputVariable(const std::string& name);
- virtual int numberOfOutputVariables() const;
+ /**
+ Returns the number of output variables added to the engine
+ @return the number of output variables added to the engine
+ */
+ virtual std::size_t numberOfOutputVariables() const;
+ /**
+ Returns an immutable vector of output variables
+ @return an immutable vector of output variables
+ */
virtual const std::vector<OutputVariable*>& outputVariables() const;
+ /**
+ Sets the vector of output variables
+ @param outputVariables is the vector of output variables
+ */
virtual void setOutputVariables(const std::vector<OutputVariable*>& outputVariables);
+ /**
+ Returns a mutable vector of output variables
+ @return a mutable vector of output variables
+ */
virtual std::vector<OutputVariable*>& outputVariables();
/**
- * Operations for iterable datatype _ruleblocks
+ Adds the rule block
+ @param ruleBlock is the rule block
+ */
+ virtual void addRuleBlock(RuleBlock* ruleBlock);
+ /**
+ Sets the rule block at the given index
+ @param ruleBlock is the rule block to set
+ @param index is the index at which the rule block is to be stored
+ @return the rule block previously stored at the given index
+ */
+ virtual RuleBlock* setRuleBlock(RuleBlock* ruleBlock, std::size_t index);
+ /**
+ Inserts the rule block at the given index, shifting other blocks one
+ position to the right
+ @param ruleBlock is the rule block to insert
+ @param index is the index at which the rule block is to be inserted
+ */
+ virtual void insertRuleBlock(RuleBlock* ruleBlock, std::size_t index);
+ /**
+ Gets the rule block at the given index
+ @param index is the given index
+ @return the rule block at the given index
+ */
+ virtual RuleBlock* getRuleBlock(std::size_t index) const;
+ /**
+ Gets the rule block of the given name after iterating the rule blocks.
+ The cost of this method is O(n), where n is the number of
+ rule blocks in the engine. For performance, please get the rule blocks
+ by index.
+ @param name is the name of the rule block
+ @return rule block of the given name
+ @throws fl::Exception if there is no block with the given name
*/
- virtual void addRuleBlock(RuleBlock* ruleblock);
- virtual RuleBlock* setRuleBlock(RuleBlock* ruleBlock, int index);
- virtual void insertRuleBlock(RuleBlock* ruleblock, int index);
- virtual RuleBlock* getRuleBlock(int index) const;
virtual RuleBlock* getRuleBlock(const std::string& name) const;
+ /**
+ Indicates whether an rule block of the given name is in the rule
+ blocks
+ @param name is the name of the rule block
+ @return whether an rule block of the given name is in the rule blocks
+
+ */
virtual bool hasRuleBlock(const std::string& name) const;
- virtual RuleBlock* removeRuleBlock(int index);
+ /**
+ Removes the rule block at the given index (without deleting it) and
+ shifts the remaining rule blocks one position to the left
+ @param index is the given index
+ @return the rule block at the given index
+ */
+ virtual RuleBlock* removeRuleBlock(std::size_t index);
+ /**
+ Removes the rule block of the given name (without deleting it) and
+ shifts the remaining rule blocks one position to the left
+ @param name is the name of the rule block
+ @return the rule block of the given name
+ @throws fl::Exception if there is no rule block with the given name
+ */
virtual RuleBlock* removeRuleBlock(const std::string& name);
- virtual int numberOfRuleBlocks() const;
+ /**
+ Returns the number of rule blocks added to the engine
+ @return the number of rule blocks added to the engine
+ */
+ virtual std::size_t numberOfRuleBlocks() const;
+ /**
+ Returns an immutable vector of rule blocks
+ @return an immutable vector of rule blocks
+ */
virtual const std::vector<RuleBlock*>& ruleBlocks() const;
+ /**
+ Sets the vector of rule blocks
+ @param ruleBlocks is the vector of rule blocks
+ */
virtual void setRuleBlocks(const std::vector<RuleBlock*>& ruleBlocks);
+ /**
+ Returns a mutable vector of rule blocks
+ @return a mutable vector of rule blocks
+ */
virtual std::vector<RuleBlock*>& ruleBlocks();
};
-
}
#endif /* FL_ENGINE_H */
diff --git a/fuzzylite/fl/Exception.h b/fuzzylite/fl/Exception.h
index f33fb13..60996f1 100644
--- a/fuzzylite/fl/Exception.h
+++ b/fuzzylite/fl/Exception.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_EXCEPTION_H
@@ -33,34 +25,116 @@
namespace fl {
+ /**
+
+ The Exception class is the only type of exception that is utilized
+ throughout the library. If the library is built with the compiling flag
+ `-DFL_BACKTRACE=ON`, the method Exception::btCallStack() will provide a
+ stack trace when an exception is thrown. Please, have in mind that
+ enabling the stack trace requires the external library `dbghelp` in
+ the Windows platform, which is generally available in the operating
+ system.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @since 4.0
+
+ */
+
+#ifdef FL_WINDOWS
+ //Disable warning for dllexport of std::exception in Windows
+#pragma warning (push)
+#pragma warning (disable:4275)
+#endif
+
class FL_API Exception : public std::exception {
- protected:
+#ifdef FL_WINDOWS
+#pragma warning (pop)
+#endif
+ private:
std::string _what;
public:
explicit Exception(const std::string& what);
- Exception(const std::string& what, const std::string& file, int line,
+ /**
+ Constructor to be used in conjunction with macro `FL_AT`
+ @param what is the message of the exception
+ @param file is the name of the file where the exception occurred
+ @param line is the line number in the file where the exception occurred
+ @param function is the name of the function where the exception occurred
+ */
+ explicit Exception(const std::string& what, const std::string& file, int line,
const std::string& function);
virtual ~Exception() FL_INOEXCEPT FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Exception)
+ /**
+ Sets the message of the `std::exception`
+ @param what is the message of the `std::exception`
+ */
virtual void setWhat(const std::string& what);
+ /**
+ Gets the message of the `std::exception`
+ @return the message of the `std::exception`
+ */
virtual std::string getWhat() const;
+ /**
+ Gets the message of the `std::exception`
+ @return the message of the `std::exception`
+ */
virtual const char* what() const FL_INOEXCEPT FL_IOVERRIDE;
+ /**
+ Appends a message to the exception
+ @param whatElse is a message to the exception
+ */
virtual void append(const std::string& whatElse);
+ /**
+ Appends an error trace to the exception. The method can be called
+ utilizing the macro `FL_AT`
+ @param file is the name of the file where the exception occurred
+ @param line is the line number in the file where the exception occurred
+ @param function is the name of the function where the exception occurred
+ */
virtual void append(const std::string& file, int line, const std::string& function);
+ /**
+ Appends an error trace with a message to the exception. The method can be called
+ utilizing the macro `FL_AT`
+ @param whatElse is further information about the exception
+ @param file is the name of the file where the exception occurred
+ @param line is the line number in the file where the exception occurred
+ @param function is the name of the function where the exception occurred
+ */
virtual void append(const std::string& whatElse,
const std::string& file, int line, const std::string& function);
+ /**
+ Returns the stack trace (if enabled)
+ @return the stack trace (if enabled)
+ */
static std::string btCallStack();
+ /**
+ Provides a signal handler to catch signals
+ @param signal is the code of the signal
+ */
static void signalHandler(int signal);
+
+ /**
+ Converts a given signal into an Exception (does not work very well on Windows)
+ @param signal is the code of the signal
+ */
static void convertToException(int signal);
+
+ /**
+ Provides a handler for `terminate` and `unexpected` signals
+ */
static void terminate();
+ /**
+ Logs the exception to console and proceeds the regular execution of the library
+ @param exception is the exception thrown
+ */
static void catchException(const std::exception& exception);
};
-
}
#endif /* FL_EXCEPTION_H */
diff --git a/fuzzylite/fl/Headers.h b/fuzzylite/fl/Headers.h
index 9c2299a..1c41002 100644
--- a/fuzzylite/fl/Headers.h
+++ b/fuzzylite/fl/Headers.h
@@ -1,36 +1,46 @@
/*
- 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_HEADERS_H
#define FL_HEADERS_H
+/**
+ The Headers.h file contains the headers of all the classes in the
+ `fuzzylite` library, thereby encouraging the use of the directive `#include
+ "fl/Headers.h"` in projects using the library.
+ */
+
+
#include "fl/fuzzylite.h"
+#include "fl/Benchmark.h"
+#include "fl/Complexity.h"
#include "fl/Console.h"
#include "fl/Engine.h"
#include "fl/Exception.h"
+#include "fl/activation/Activation.h"
+#include "fl/activation/First.h"
+#include "fl/activation/General.h"
+#include "fl/activation/Highest.h"
+#include "fl/activation/Last.h"
+#include "fl/activation/Lowest.h"
+#include "fl/activation/Proportional.h"
+#include "fl/activation/Threshold.h"
+
#include "fl/defuzzifier/Bisector.h"
#include "fl/defuzzifier/Centroid.h"
#include "fl/defuzzifier/Defuzzifier.h"
@@ -42,6 +52,7 @@
#include "fl/defuzzifier/WeightedDefuzzifier.h"
#include "fl/defuzzifier/WeightedSum.h"
+#include "fl/factory/ActivationFactory.h"
#include "fl/factory/CloningFactory.h"
#include "fl/factory/ConstructionFactory.h"
#include "fl/factory/FactoryManager.h"
@@ -61,10 +72,12 @@
#include "fl/imex/FllImporter.h"
#include "fl/imex/FllExporter.h"
#include "fl/imex/JavaExporter.h"
+#include "fl/imex/RScriptExporter.h"
#include "fl/hedge/Any.h"
#include "fl/hedge/Extremely.h"
#include "fl/hedge/Hedge.h"
+#include "fl/hedge/HedgeFunction.h"
#include "fl/hedge/Not.h"
#include "fl/hedge/Seldom.h"
#include "fl/hedge/Somewhat.h"
@@ -84,6 +97,8 @@
#include "fl/norm/s/Maximum.h"
#include "fl/norm/s/NilpotentMaximum.h"
#include "fl/norm/s/NormalizedSum.h"
+#include "fl/norm/s/SNormFunction.h"
+#include "fl/norm/s/UnboundedSum.h"
#include "fl/norm/t/AlgebraicProduct.h"
#include "fl/norm/t/BoundedDifference.h"
@@ -92,6 +107,7 @@
#include "fl/norm/t/HamacherProduct.h"
#include "fl/norm/t/Minimum.h"
#include "fl/norm/t/NilpotentMinimum.h"
+#include "fl/norm/t/TNormFunction.h"
#include "fl/rule/Antecedent.h"
#include "fl/rule/Consequent.h"
@@ -99,8 +115,9 @@
#include "fl/rule/RuleBlock.h"
#include "fl/rule/Expression.h"
-#include "fl/term/Accumulated.h"
+#include "fl/term/Aggregated.h"
#include "fl/term/Bell.h"
+#include "fl/term/Binary.h"
#include "fl/term/Concave.h"
#include "fl/term/Constant.h"
#include "fl/term/Cosine.h"
diff --git a/fuzzylite/fl/Operation.h b/fuzzylite/fl/Operation.h
index d92e66c..8070116 100644
--- a/fuzzylite/fl/Operation.h
+++ b/fuzzylite/fl/Operation.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_OPERATION_H
@@ -34,111 +26,1044 @@
namespace fl {
- class FL_API Operation {
+ /**
+ The Operation class contains methods for numeric operations, string
+ manipulation, and other functions, all of which are also accessible via
+ fl::Op.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @since 4.0
+ */
+ class Operation {
public:
+ /**
+ Returns the minimum between the two parameters
+ @param a
+ @param b
+ @return @f$\min(a,b)@f$
+ */
template <typename T>
static T min(T a, T b);
+ /**
+ Returns the maximum between the two parameters
+ @param a
+ @param b
+ @return @f$\max(a,b)@f$
+ */
template <typename T>
static T max(T a, T b);
+ /**
+ Returns @f$x@f$ bounded in @f$[\min,\max]@f$
+ @param x is the value to be bounded
+ @param min is the minimum value of the range
+ @param max is the maximum value of the range
+ @return @f$
+ \begin{cases}
+ \min & \mbox{if $x < \min$} \cr
+ \max & \mbox{if $x > \max$} \cr
+ x & \mbox{otherwise}
+ \end{cases}
+ @f$
+ */
template <typename T>
static T bound(T x, T min, T max);
+ /**
+ Indicates whether @f$x@f$ is within the boundaries (open or closed)
+ @param x is the value
+ @param min is the minimum of the range
+ @param max is the maximum of the range
+ @param geq determines whether the maximum is a closed interval
+ @param leq determines whether the minimum is a closed interval
+ @return @f$
+ \begin{cases}
+ x \in [\min,\max] & \mbox{if $geq \wedge leq$} \cr
+ x \in (\min,\max] & \mbox{if $geq \wedge \bar{leq}$} \cr
+ x \in [\min, \max) & \mbox{if $\bar{geq} \wedge leq$} \cr
+ x \in (\min, \max) & \mbox{if $\bar{geq} \wedge \bar{leq}$} \cr
+ \end{cases}
+ @f$
+ */
template <typename T>
static bool in(T x, T min, T max, bool geq = true, bool leq = true);
+ /**
+ Indicates whether @f$x@f$ is infinity
+ @param x is the value
+ @return whether @f$x@f$ is infinity
+ */
template <typename T>
static bool isInf(T x);
+ /**
+ Indicates whether @f$x@f$ is not-a-number (NaN)
+ @param x is the value
+ @return whether @f$x@f$ is not-a-number (NaN)
+ */
template <typename T>
static bool isNaN(T x);
+ /**
+ Indicates whether @f$x@f$ is finite, that is, @f$x \not\in
+ \{\pm\infty, \mathrm{NaN}\}@f$
+ @param x is the value
+ @return whether @f$x@f$ is finite
+ */
template <typename T>
static bool isFinite(T x);
- //Is less than
+ /**
+ Returns whether @f$a@f$ is less than @f$b@f$ at the given tolerance
+ @param a
+ @param b
+ @param macheps is the minimum difference upon which two
+ floating-point values are considered equivalent
+ @return whether @f$a@f$ is less than @f$b@f$ at the given tolerance
+ */
+ static bool isLt(scalar a, scalar b, scalar macheps = fuzzylite::_macheps);
+ /**
+ Returns whether @f$a@f$ is less than or equal to @f$b@f$ at the given
+ tolerance
+ @param a
+ @param b
+ @param macheps is the minimum difference upon which two
+ floating-point values are considered equivalent
+ @return whether @f$a@f$ is less than or equal to @f$b@f$ at the given
+ tolerance
+ */
+ static bool isLE(scalar a, scalar b, scalar macheps = fuzzylite::_macheps);
+ /**
+ Returns whether @f$a@f$ is equal to @f$b@f$ at the given tolerance
+ @param a
+ @param b
+ @param macheps is the minimum difference upon which two
+ floating-point values are considered equivalent
+ @return whether @f$a@f$ is equal to @f$b@f$ at the given tolerance
+ */
+ static bool isEq(scalar a, scalar b, scalar macheps = fuzzylite::_macheps);
+ /**
+ Returns whether @f$a@f$ is greater than @f$b@f$ at the given tolerance
+ @param a
+ @param b
+ @param macheps is the minimum difference upon which two
+ floating-point values are considered equivalent
+ @return whether @f$a@f$ is greater than @f$b@f$ at the given tolerance
+ */
+ static bool isGt(scalar a, scalar b, scalar macheps = fuzzylite::_macheps);
+ /**
+ Returns whether @f$a@f$ is greater than or equal to @f$b@f$ at the
+ given tolerance
+ @param a
+ @param b
+ @param macheps is the minimum difference upon which two
+ floating-point values are considered equivalent
+ @return whether @f$a@f$ is greater than or equal to @f$b@f$ at the
+ given tolerance
+ */
+ static bool isGE(scalar a, scalar b, scalar macheps = fuzzylite::_macheps);
- static bool isLt(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
- static bool isLE(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
- static bool isEq(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
- static bool isGt(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
- static bool isGE(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
+ /**
+ Linearly interpolates the parameter @f$x@f$ in range
+ `[fromMin,fromMax]` to a new value in the range `[toMin,toMax]`
+ @param x is the source value to interpolate
+ @param fromMin is the minimum value of the source range
+ @param fromMax is the maximum value of the source range
+ @param toMin is the minimum value of the target range
+ @param toMax is the maximum value of the target range
+ @return the source value linearly interpolated to the target range:
+ @f$ y = y_a + (y_b - y_a) \dfrac{x-x_a}{x_b-x_a} @f$
+ */
+ static scalar scale(scalar x, scalar fromMin, scalar fromMax,
+ scalar toMin, scalar toMax);
+ /**
+ Linearly interpolates the parameter @f$x@f$ in range
+ `[fromMin,fromMax]` to a new value in the range `[toMin,toMax]`,
+ truncated to the range `[toMin,toMax]` if bounded is `true`.
+ @param x is the source value to interpolate
+ @param fromMin is the minimum value of the source range
+ @param fromMax is the maximum value of the source range
+ @param toMin is the minimum value of the target range
+ @param toMax is the maximum value of the target range
+ @param bounded determines whether the resulting value is bounded to
+ the range
+ @return the source value linearly interpolated to the target range:
+ @f$ y = y_a + (y_b - y_a) \dfrac{x-x_a}{x_b-x_a} @f$
+ */
static scalar scale(scalar x, scalar fromMin, scalar fromMax,
- scalar toMin, scalar toMax, bool bounded = false);
+ scalar toMin, scalar toMax, bool bounded);
+ /**
+ Adds two values
+ @param a
+ @param b
+ @return @f$a+b@f$
+ */
static scalar add(scalar a, scalar b);
+ /**
+ Subtracts two values
+ @param a
+ @param b
+ @return @f$a-b@f$
+ */
static scalar subtract(scalar a, scalar b);
+ /**
+ Multiplies two values
+ @param a
+ @param b
+ @return @f$a\times b@f$
+ */
static scalar multiply(scalar a, scalar b);
+ /**
+ Divides two values
+ @param a
+ @param b
+ @return @f$a/b@f$
+ */
static scalar divide(scalar a, scalar b);
+ /**
+ Computes the modulo
+ @param a
+ @param b
+ @return @f$a \mod b@f$
+ */
static scalar modulo(scalar a, scalar b);
+
+ /**
+ Computes the logical AND
+ @param a
+ @param b
+ @return @f$
+ \begin{cases}
+ 1.0 & \mbox{if $a=1 \wedge b=1$}\cr
+ 0.0 & \mbox{otherwise}
+ \end{cases}
+ @f$
+ */
static scalar logicalAnd(scalar a, scalar b);
+ /**
+ Computes the logical OR
+ @param a
+ @param b
+ @return @f$
+ \begin{cases}
+ 1.0 & \mbox{if $a=1 \vee b=1$}\cr
+ 0.0 & \mbox{otherwise}
+ \end{cases}
+ @f$
+ */
static scalar logicalOr(scalar a, scalar b);
+ /**
+ Returns the complement of the value
+ @param a
+ @return @f$
+ \begin{cases}
+ 0.0 & \mbox{if $a=1$}\cr
+ 1.0 & \mbox{otherwise}
+ \end{cases}
+ @f$
+ */
static scalar logicalNot(scalar a);
+ /**
+ Negates the value
+ @param a
+ @return -a
+ */
static scalar negate(scalar a);
+ /**
+ Rounds the value to the nearest integer
+ @param x
+ @return @f$
+ \begin{cases}
+ \lfloor x + 0.5 \rfloor & \mbox{if $x > 0$}\cr
+ \lceil x - 0.5 \rceil & \mbox{otherwise}
+ \end{cases}
+ @f$
+ */
static scalar round(scalar x);
- //greater than
+ /**
+ Returns whether @f$a@f$ is greater than or equal to @f$b@f$ at the
+ default tolerance
+ @param a
+ @param b
+ @return whether @f$a@f$ is greater than or equal to @f$b@f$ at the
+ default tolerance
+ */
static scalar gt(scalar a, scalar b);
- //greater than or equal to
+ /**
+ Returns whether @f$a@f$ is greater than or equal to @f$b@f$ at the
+ default tolerance
+ @param a
+ @param b
+ @return whether @f$a@f$ is greater than or equal to @f$b@f$ at the
+ default tolerance
+ */
static scalar ge(scalar a, scalar b);
- //equal to
+ /**
+ Returns whether @f$a@f$ is equal to @f$b@f$ at the default tolerance
+ @param a
+ @param b
+ @return whether @f$a@f$ is equal to @f$b@f$ at the default tolerance
+ */
static scalar eq(scalar a, scalar b);
- //not equal to
+ /**
+ Returns whether @f$a@f$ is different from @f$b@f$ at the default
+ tolerance
+ @param a
+ @param b
+ @return whether @f$a@f$ is different from @f$b@f$ at the default
+ tolerance
+ */
static scalar neq(scalar a, scalar b);
- //less than or equal to
+ /**
+ Returns whether @f$a@f$ is less than or equal to @f$b@f$ at the
+ default tolerance
+ @param a
+ @param b
+ @return whether @f$a@f$ is less than or equal to @f$b@f$ at the
+ default tolerance
+ */
static scalar le(scalar a, scalar b);
- //less than
+ /**
+ Returns whether @f$a@f$ is less than @f$b@f$ at the default tolerance
+ @param a
+ @param b
+ @return whether @f$a@f$ is less than @f$b@f$ at the default tolerance
+ */
static scalar lt(scalar a, scalar b);
+ /**
+ Returns a random number
+ */
+ static int random();
+
+ /**
+ Increments @f$x@f$ by the unit, treating the entire vector as a
+ number. For example, incrementing a few times @f$x_0=\{0,0\}@f$
+ within boundaries @f$[0,1]@f$ results in: @f$x_1=\{0,1\}@f$,
+ @f$x_2=\{1,0\}@f$, @f$x_3=\{1,1\}@f$, @f$x_4=\{0,0\}@f$.
+ @param x is the vector to increment
+ @param min is the minimum value of the dimension
+ @param max is the maximum value of the dimension
+ @return `true` if @f$x@f$ was incremented, `false` otherwise (e.g.,
+ incrementing @f$x_3@f$ returns `false`). In earlier versions to 6.0, the
+ result was the inverse and indicated whether the counter had overflown
+ (most sincere apologies for this change).
+ */
static bool increment(std::vector<int>& x, std::vector<int>& min, std::vector<int>& max);
+ /**
+ Increments @f$x@f$ by the unit at the given position, treating the
+ entire vector as a number. For example, incrementing
+ @f$x_0=\{0,0,0\}@f$ within boundaries @f$[0,1]@f$ at the second
+ position results in: @f$x_1=\{0,1,0\}@f$, @f$x_2=\{1,0,0\}@f$,
+ @f$x_3=\{1,1,0\}@f$, @f$x_4=\{0,0,0\}@f$.
+ @param x is the vector to increment
+ @param position is the position of the vector to increment, where
+ smaller values lead to higher significance digits
+ @param min is the minimum value of the dimension
+ @param max is the maximum value of the dimension
+ @return `true` if @f$x@f$ was incremented, `false` otherwise (e.g.,
+ incrementing @f$x_3@f$ returns `false`). In earlier versions to 6.0, the
+ result was the inverse and indicated whether the counter had overflown
+ (most sincere apologies for this change).
+ */
static bool increment(std::vector<int>& x, int position, std::vector<int>& min, std::vector<int>& max);
- static double mean(const std::vector<scalar>& x);
- static double variance(const std::vector<scalar>& x);
- static double variance(const std::vector<scalar>& x, scalar mean);
- static double standardDeviation(const std::vector<scalar>& x);
- static double standardDeviation(const std::vector<scalar>& x, scalar mean);
+ /**
+ Computes the sum of the vector
+ */
+ template <typename T>
+ static T sum(const std::vector<T>& x);
+ /**
+ Computes the mean of the vector
+ @param x is the vector
+ @return @f$\dfrac{\sum_i{x_i}}{|x|}@f$
+ */
+ template <typename T>
+ static scalar mean(const std::vector<T>& x);
+ /**
+ Computes the variance of the vector
+ @param x is the vector
+ @return @f$ \sum_i{ (x_i - \bar{x})^2 } / (|x| - 1) @f$
+ */
+ template <typename T>
+ static scalar variance(const std::vector<T>& x);
+ /**
+ Computes the variance of the vector using the given mean
+ @param x is the vector
+ @param mean is the mean value of the vector
+ @return @f$ \sum_i{ (x_i - \bar{x})^2 } / (|x| - 1) @f$
+ */
+ template <typename T>
+ static scalar variance(const std::vector<T>& x, scalar mean);
+ /**
+ Computes the standard deviation of the vector
+ @param x
+ @return @f$ \sqrt{\mbox{variance}(x, \bar{x})} @f$
+ */
+ template <typename T>
+ static scalar standardDeviation(const std::vector<T>& x);
+ /**
+ Computes the standard deviation of the vector using the given mean
+ @param x
+ @param mean is the mean value of x
+ @return @f$ \sqrt{\mbox{variance}(x, \bar{x})} @f$
+ */
+ template <typename T>
+ static scalar standardDeviation(const std::vector<T>& x, scalar mean);
+ /**
+ Returns a valid name for variables
+ @param name
+ @return an name whose characters are in `[a-zA-Z_0-9.]`
+ */
static std::string validName(const std::string& name);
- static int isValidForName(int character);
-
+ /**
+ Replaces the substrings that are equal to the given expression
+ @param str is the target string
+ @param find is the string to find
+ @param replace is the string to replace the findings
+ @param replaceAll whether all the substrings are to be replaced or
+ just the first string
+ @return the original string with replacements
+ */
static std::string findReplace(const std::string& str, const std::string& find,
const std::string& replace, bool replaceAll = true);
+ /**
+ Replaces the first substring that is equal to the given expression
+ @param str is the target string
+ @param find is the string to find
+ @param replace is the string to replace
+ @return the original string with the replacement
+ */
+ static std::string replaceFirst(const std::string& str, const std::string& find,
+ const std::string& replace);
+
+ /**
+ Replaces the every substring that is equal to the given expression
+ @param str is the target string
+ @param find is the string to find
+ @param replace is the string to replace
+ @return the original string with all of the replacements
+ */
+ static std::string replaceAll(const std::string& str, const std::string& find,
+ const std::string& replace);
+
+ /**
+ Splits the string around the given delimiter
+ @param str is the string to split
+ @param delimiter is the substrings on which the string will be split
+ @param ignoreEmpty whether the empty strings are discarded
+ @return the string split around the given delimiter
+ */
static std::vector<std::string> split(const std::string& str,
const std::string& delimiter = " ", bool ignoreEmpty = true);
+ /**
+ Removes whitespace at the beginning and end of the text
+ @param text
+ @return a space-trimmed string
+ */
static std::string trim(const std::string& text);
+ /**
+ Replaces every matching character in the text with the given
+ replacement
+ @param text is the string to have replacements
+ @param matchesChar is a pointer to a method that indicates whether
+ the given character is a match
+ @param replacement a string to replace a matching character
+ @return the string with every matching character replaced
+ */
static std::string format(const std::string& text, int matchesChar(int),
const std::string& replacement = "");
- //Intentionally results in a compiler error in C++11, or linker error in C++98
- //in order to avoid the deprecated usage of this method from version 4.0
- static scalar toScalar(const std::string& x, bool quiet,
- scalar alternative = fl::nan) FL_IDELETE;
+ /**
+ Parses the given string into a scalar value
+ @param x is the string to parse
+ @return the given string into a scalar value
+ @throws fl::Exception if the string does not contain a scalar value
+ */
+ static scalar toScalar(const std::string& x); //throws (fl::Exception)
- static scalar toScalar(const std::string& x); //throws fl::Exception
+ /**
+ Parses the given string into a scalar value without throwing an
+ exception
+ @param x is the string to parse
+ @param alternative is the value to return if the string does not
+ contain a scalar value
+ @param ok contains whether the operation was successful (optional)
+ @return the given string into a scalar value or the alternative value
+ if the string does not contain a scalar value
+ */
+ static scalar toScalar(const std::string& x, scalar alternative,
+ bool* ok = fl::null) FL_INOEXCEPT;
- static scalar toScalar(const std::string& x, scalar alternative) FL_INOEXCEPT;
+ /**
+ Parses the given string into a vector of scalar values
+ @param x is the string containing space-separated values to parse
+ @return the vector of scalar values
+ @throws fl::Exception if the string contains an invalid scalar value
+ */
+ static std::vector<scalar> toScalars(const std::string& x); //throws (fl::Exception)
+ /**
+ Parses the given string into a vector of scalar values
+ @param x is the string containing space-separated values to parse
+ @param alternative is the value to use if an invalid value is found
+ @param ok contains whether the operation was successful (optional)
+ @return the vector of scalar values
+ */
+ static std::vector<scalar> toScalars(const std::string& x, scalar alternative,
+ bool* ok = fl::null) FL_INOEXCEPT;
+
+ /**
+ Indicates whether the string can be converted to a numeric value.
+ @param x
+ @return whether the string can be converted to a numeric value
+ */
static bool isNumeric(const std::string& x);
+ /**
+ Returns a string representation of the given value
+ @param x is the value
+ @param decimals is the number of decimals to display
+ @param scalarFormat are the flags for the underlying std::ostringstream
+ @return a string representation of the given value
+ */
template <typename T>
- static std::string str(T x, int decimals = fuzzylite::decimals());
+ static std::string str(T x, int decimals = fuzzylite::_decimals,
+ std::ios_base::fmtflags scalarFormat = fuzzylite::_scalarFormat);
+ /**
+ Joins a vector of elements by the given separator into a single
+ string. The elements are represented as strings utilizing the
+ Operation::str() method on each element
+ @param x is the vector of elements
+ @param separator is the string to add between the elements
+ @return a single string joining the vector of elements by the given
+ separator
+ */
template <typename T>
static std::string join(const std::vector<T>& x, const std::string& separator);
+ /**
+ Joins a variadic number of elements by the given separator into a
+ single string. The elements are represented as strings utilizing the
+ Operation::str() method on each element
+ @param items is the number of elements to join
+ @param separator is the string to add between the elements
+ @param first is the first element, which defines the type of the
+ subsequent elements
+ @param ... are the remaining elements to join
+ @return a single string joining the variadic number of elements by
+ the given separator
+ */
template <typename T>
static std::string join(int items, const std::string& separator, T first, ...);
};
+ /**A shortened type to refer to Operation*/
typedef Operation Op;
}
+
+
+/**
+ Template implementation
+ */
+
+#include "fl/defuzzifier/Defuzzifier.h"
+#include "fl/norm/Norm.h"
+#include "fl/norm/SNorm.h"
+#include "fl/norm/TNorm.h"
+
+#include <algorithm>
+#include <iomanip>
+#include <cstdarg>
+#include <cctype>
+
+namespace fl {
+
+ template <typename T>
+ inline T Operation::min(T a, T b) {
+ if (Op::isNaN(a)) return b;
+ if (Op::isNaN(b)) return a;
+ return a < b ? a : b;
+ }
+
+ template <typename T>
+ inline T Operation::max(T a, T b) {
+ if (Op::isNaN(a)) return b;
+ if (Op::isNaN(b)) return a;
+ return a > b ? a : b;
+ }
+
+ template <typename T>
+ inline T Operation::bound(T x, T min, T max) {
+ if (x > max) return max;
+ if (x < min) return min;
+ return x;
+ }
+
+ template <typename T>
+ inline bool Operation::in(T x, T min, T max, bool geq, bool leq) {
+ bool left = geq ? Op::isGE(x, min) : Op::isGt(x, min);
+ bool right = leq ? Op::isLE(x, max) : Op::isLt(x, max);
+ return (left and right);
+ }
+
+ template <typename T>
+ inline bool Operation::isInf(T x) {
+ return x == fl::inf or x == -fl::inf;
+ }
+
+ template <typename T>
+ inline bool Operation::isNaN(T x) {
+ return (x != x);
+ }
+
+ template<typename T>
+ inline bool Operation::isFinite(T x) {
+ return not (x != x or x == fl::inf or x == -fl::inf);
+ }
+
+ inline bool Operation::isLt(scalar a, scalar b, scalar macheps) {
+ return not (a == b or std::abs(a - b) < macheps or (a != a and b != b)) and a < b;
+ }
+
+ inline bool Operation::isLE(scalar a, scalar b, scalar macheps) {
+ return a == b or std::abs(a - b) < macheps or (a != a and b != b) or a < b;
+ }
+
+ inline bool Operation::isEq(scalar a, scalar b, scalar macheps) {
+ return a == b or std::abs(a - b) < macheps or (a != a and b != b);
+ }
+
+ inline bool Operation::isGt(scalar a, scalar b, scalar macheps) {
+ return not (a == b or std::abs(a - b) < macheps or (a != a and b != b)) and a > b;
+ }
+
+ inline bool Operation::isGE(scalar a, scalar b, scalar macheps) {
+ return a == b or std::abs(a - b) < macheps or (a != a and b != b) or a > b;
+ }
+
+ inline scalar Operation::scale(scalar x, scalar fromMin, scalar fromMax, scalar toMin, scalar toMax) {
+ return (toMax - toMin) / (fromMax - fromMin) * (x - fromMin) + toMin;
+ }
+
+ inline scalar Operation::scale(scalar x, scalar fromMin, scalar fromMax, scalar toMin, scalar toMax, bool bounded) {
+ scalar result = (toMax - toMin) / (fromMax - fromMin) * (x - fromMin) + toMin;
+ return bounded ? Op::bound(result, toMin, toMax) : result;
+ }
+
+ inline scalar Operation::add(scalar a, scalar b) {
+ return a + b;
+ }
+
+ inline scalar Operation::subtract(scalar a, scalar b) {
+ return a - b;
+ }
+
+ inline scalar Operation::multiply(scalar a, scalar b) {
+ return a * b;
+ }
+
+ inline scalar Operation::divide(scalar a, scalar b) {
+ return a / b;
+ }
+
+ inline scalar Operation::modulo(scalar a, scalar b) {
+ return fmod(a, b);
+ }
+
+ inline scalar Operation::logicalAnd(scalar a, scalar b) {
+ return (isEq(a, 1.0) and isEq(b, 1.0)) ? 1.0 : 0.0;
+ }
+
+ inline scalar Operation::logicalOr(scalar a, scalar b) {
+ return (isEq(a, 1.0) or isEq(b, 1.0)) ? 1.0 : 0.0;
+ }
+
+ inline scalar Operation::logicalNot(scalar a) {
+ return isEq(a, 1.0) ? 0.0 : 1.0;
+ }
+
+ inline scalar Operation::negate(scalar a) {
+ return -a;
+ }
+
+ inline scalar Operation::round(scalar x) {
+ return (x > 0.0) ? std::floor(x + 0.5) : std::ceil(x - 0.5);
+ }
+
+ inline scalar Operation::gt(scalar a, scalar b) {
+ return isGt(a, b);
+ }
+
+ inline scalar Operation::ge(scalar a, scalar b) {
+ return isGE(a, b);
+ }
+
+ inline scalar Operation::eq(scalar a, scalar b) {
+ return isEq(a, b);
+ }
+
+ inline scalar Operation::neq(scalar a, scalar b) {
+ return not isEq(a, b);
+ }
+
+ inline scalar Operation::le(scalar a, scalar b) {
+ return isLE(a, b);
+ }
+
+ inline scalar Operation::lt(scalar a, scalar b) {
+ return isLt(a, b);
+ }
+
+ inline int Operation::random() {
+ return std::rand();
+ }
+
+ inline bool Operation::increment(std::vector<int>& x, std::vector<int>& min, std::vector<int>& max) {
+ return increment(x, -1 + int(x.size()), min, max);
+ }
+
+ inline bool Operation::increment(std::vector<int>& x, int position, std::vector<int>& min, std::vector<int>& max) {
+ if (x.empty() or position < 0) return false;
+
+ bool incremented = true;
+ if (x.at(position) < max.at(position)) {
+ ++x.at(position);
+ } else {
+ incremented = !(position == 0);
+ x.at(position) = min.at(position);
+ --position;
+ if (position >= 0) {
+ incremented = increment(x, position, min, max);
+ }
+ }
+ return incremented;
+ }
+
+ template<typename T>
+ inline T Operation::sum(const std::vector<T>& x) {
+ T result = T(0);
+ for (std::size_t i = 0; i < x.size(); ++i) {
+ result += x.at(i);
+ }
+ return result;
+ }
+
+ template<typename T>
+ inline scalar Operation::mean(const std::vector<T>& x) {
+ return scalar(sum(x)) / x.size();
+ }
+
+ template<typename T>
+ inline scalar Operation::standardDeviation(const std::vector<T>& x) {
+ return standardDeviation(x, mean(x));
+ }
+
+ template<typename T>
+ inline scalar Operation::standardDeviation(const std::vector<T>& x, scalar mean) {
+ if (x.empty()) return fl::nan;
+ if (x.size() == 1) return scalar(0.0);
+ return std::sqrt(variance(x, mean));
+ }
+
+ template<typename T>
+ inline scalar Operation::variance(const std::vector<T>& x) {
+ return variance(x, mean(x));
+ }
+
+ template<typename T>
+ inline scalar Operation::variance(const std::vector<T>& x, scalar mean) {
+ if (x.empty()) return fl::nan;
+ if (x.size() == 1) return scalar(0.0);
+ scalar result = 0.0;
+ for (std::size_t i = 0; i < x.size(); ++i) {
+ result += (x.at(i) - mean) * (x.at(i) - mean);
+ }
+ result /= -1 + x.size();
+ return result;
+ }
+
+
+
+ //Text Operations:
+
+ inline std::string Operation::validName(const std::string& name) {
+ if (trim(name).empty()) return "unnamed";
+ std::ostringstream ss;
+ for (std::size_t i = 0; i < name.length(); ++i) {
+ char c = name[i];
+ if (c == '_' or c == '.' or isalnum(c)) {
+ ss << c;
+ }
+ }
+ return ss.str();
+ }
+
+ inline std::string Operation::findReplace(const std::string& str, const std::string& find,
+ const std::string& replace, bool replaceAll) {
+ std::ostringstream result;
+ std::size_t fromIndex = 0, nextIndex;
+ do {
+ nextIndex = str.find(find, fromIndex);
+ result << str.substr(fromIndex, nextIndex - fromIndex);
+ if (nextIndex != std::string::npos)
+ result << replace;
+ fromIndex = nextIndex + find.size();
+ } while (replaceAll and nextIndex != std::string::npos);
+ return result.str();
+ }
+
+ inline std::string Operation::replaceFirst(const std::string& str,
+ const std::string& find, const std::string& replace) {
+ return findReplace(str, find, replace, false);
+ }
+
+ inline std::string Operation::replaceAll(const std::string& str,
+ const std::string& find, const std::string& replace) {
+ return findReplace(str, find, replace, true);
+ }
+
+ inline std::vector<std::string> Operation::split(const std::string& str,
+ const std::string& delimiter, bool ignoreEmpty) {
+ std::vector<std::string> result;
+ if (str.empty() or delimiter.empty()) {
+ result.push_back(str);
+ return result;
+ }
+ std::string::const_iterator position = str.begin(), next = str.begin();
+ while (next != str.end()) {
+ next = std::search(position, str.end(), delimiter.begin(), delimiter.end());
+ std::string token(position, next);
+ if (not (token.empty() and ignoreEmpty)) {
+ result.push_back(token);
+ }
+ if (next != str.end()) {
+ position = next + delimiter.size();
+ }
+ }
+ return result;
+ }
+
+ inline std::string Operation::trim(const std::string& text) {
+ if (text.empty()) return text;
+ if (not (std::isspace(text.at(0)) or std::isspace(text.at(text.size() - 1))))
+ return text;
+ std::size_t start = 0, end = text.size() - 1;
+ while (start <= end and std::isspace(text.at(start))) {
+ ++start;
+ }
+ while (end >= start and std::isspace(text.at(end))) {
+ --end;
+ }
+ std::size_t length = end - start + 1;
+ if (length <= 0) return "";
+ return text.substr(start, length);
+ }
+
+ inline std::string Operation::format(const std::string& text, int matchesChar(int),
+ const std::string& replacement) {
+ std::ostringstream ss;
+ std::string::const_iterator it = text.begin();
+ while (it != text.end()) {
+ if (matchesChar(*it)) {
+ ss << *it;
+ } else {
+ ss << replacement;
+ }
+ ++it;
+ }
+ return ss.str();
+ }
+
+ inline scalar Operation::toScalar(const std::string& x) {
+ std::istringstream iss(x);
+ scalar result;
+ iss >> result;
+ char strict;
+ if (not (iss.fail() or iss.get(strict))) return result;
+
+ std::ostringstream _nan;
+ _nan << fl::nan;
+ if (x == _nan.str() or x == "nan")
+ return fl::nan;
+
+ std::ostringstream pInf;
+ pInf << fl::inf;
+ if (x == pInf.str() or x == "inf")
+ return fl::inf;
+
+ std::ostringstream nInf;
+ nInf << (-fl::inf);
+ if (x == nInf.str() or x == "-inf")
+ return -fl::inf;
+
+ throw Exception("[conversion error] from <" + x + "> to scalar", FL_AT);
+ }
+
+ inline scalar Operation::toScalar(const std::string& x, scalar alternative, bool* ok) FL_INOEXCEPT {
+ if (ok) *ok = true;
+ std::istringstream iss(x);
+ scalar result;
+ iss >> result;
+ char strict;
+ if (not (iss.fail() or iss.get(strict))) return result;
+
+ std::ostringstream _nan;
+ _nan << fl::nan;
+ if (x == _nan.str() or x == "nan")
+ return fl::nan;
+
+ std::ostringstream pInf;
+ pInf << fl::inf;
+ if (x == pInf.str() or x == "inf")
+ return fl::inf;
+
+ std::ostringstream nInf;
+ nInf << (-fl::inf);
+ if (x == nInf.str() or x == "-inf")
+ return -fl::inf;
+
+ if (ok) *ok = false;
+ return alternative;
+ }
+
+ inline std::vector<scalar> Operation::toScalars(const std::string& x) {
+ std::vector<scalar> result;
+ std::istringstream tokenizer(x);
+ std::string token;
+ while (tokenizer >> token) {
+ result.push_back(Op::toScalar(token));
+ }
+ return result;
+ }
+
+ inline std::vector<scalar> Operation::toScalars(const std::string& x,
+ scalar alternative, bool* ok) FL_INOEXCEPT {
+ std::vector<scalar> result;
+ std::istringstream tokenizer(x);
+ std::string token;
+ bool allOK = true;
+ while (tokenizer >> token) {
+ bool good;
+ result.push_back(Op::toScalar(token, alternative, &good));
+ allOK &= good;
+ }
+ if (ok) *ok = allOK;
+ return result;
+ }
+
+ inline bool Operation::isNumeric(const std::string& x) {
+ try {
+ Op::toScalar(x);
+ return true;
+ } catch (...) {
+ return false;
+ }
+ }
+
+ template <typename T>
+ inline std::string Operation::str(T x, int decimals,
+ std::ios_base::fmtflags scalarFormat) {
+ std::ostringstream ss;
+ if (scalarFormat != std::ios_base::fmtflags(0x0)) ss.flags(scalarFormat);
+ if (decimals >= 0) ss.precision(decimals);
+ if (Op::isNaN(x)) {
+ ss << "nan";
+ } else if (Op::isInf(x)) {
+ ss << (x < T(0) ? "-inf" : "inf");
+ } else if (decimals >= 0 //print x considering the given decimals regardless of macheps
+ and Op::isEq(scalar(x), 0.0, std::pow(10.0, -decimals))) {
+ ss << T(0);
+ } else ss << x;
+ return ss.str();
+ }
+
+ template <> FL_API
+ inline std::string Operation::str(const std::string& x, int decimals,
+ std::ios_base::fmtflags scalarFormat) {
+ FL_IUNUSED(decimals);
+ FL_IUNUSED(scalarFormat);
+ return x;
+ }
+
+ template <typename T>
+ inline std::string Operation::join(const std::vector<T>& x,
+ const std::string& separator) {
+ std::ostringstream ss;
+ for (std::size_t i = 0; i < x.size(); ++i) {
+ ss << str(x.at(i));
+ if (i + 1 < x.size()) ss << separator;
+ }
+ return ss.str();
+ }
+
+ template <> FL_API
+ inline std::string Operation::join(const std::vector<std::string>& x,
+ const std::string& separator) {
+ std::ostringstream ss;
+ for (std::size_t i = 0; i < x.size(); ++i) {
+ ss << x.at(i);
+ if (i + 1 < x.size()) ss << separator;
+ }
+ return ss.str();
+ }
+
+ template <typename T>
+ inline std::string Operation::join(int items, const std::string& separator, T first, ...) {
+ std::ostringstream ss;
+ ss << str(first);
+ if (items > 1) ss << separator;
+ va_list args;
+ va_start(args, first);
+ for (int i = 0; i < items - 1; ++i) {
+ ss << str(va_arg(args, T));
+ if (i + 1 < items - 1) ss << separator;
+ }
+ va_end(args);
+ return ss.str();
+ }
+
+ template <> FL_API
+ inline std::string Operation::join(int items, const std::string& separator,
+ float first, ...) {
+ std::ostringstream ss;
+ ss << str(first);
+ if (items > 1) ss << separator;
+ va_list args;
+ va_start(args, first);
+ for (int i = 0; i < items - 1; ++i) {
+ ss << str(va_arg(args, double)); //automatic promotion
+ if (i + 1 < items - 1) ss << separator;
+ }
+ va_end(args);
+ return ss.str();
+ }
+
+ template <> FL_API
+ inline std::string Operation::join(int items, const std::string& separator, const char* first, ...) {
+ std::ostringstream ss;
+ ss << first;
+ if (items > 1) ss << separator;
+ va_list args;
+ va_start(args, first);
+ for (int i = 0; i < items - 1; ++i) {
+ ss << va_arg(args, const char*);
+ if (i + 1 < items - 1) ss << separator;
+ }
+ va_end(args);
+ return ss.str();
+ }
+}
#endif /* FL_OPERATION_H */
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 */
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 */
+
diff --git a/fuzzylite/fl/factory/ActivationFactory.h b/fuzzylite/fl/factory/ActivationFactory.h
new file mode 100644
index 0000000..6ebfc73
--- /dev/null
+++ b/fuzzylite/fl/factory/ActivationFactory.h
@@ -0,0 +1,46 @@
+/*
+ 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_ACTIVATIONFACTORY_H
+#define FL_ACTIVATIONFACTORY_H
+
+#include "fl/fuzzylite.h"
+
+#include "fl/factory/ConstructionFactory.h"
+#include "fl/activation/Activation.h"
+
+namespace fl {
+
+ /**
+ The ActivationFactory class is a ConstructionFactory of Activation
+ methods for RuleBlock%s.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Activation
+ @see RuleBlock
+ @see ConstructionFactory
+ @see FactoryManager
+ @since 6.0
+ */
+ class FL_API ActivationFactory : public ConstructionFactory<Activation*> {
+ public:
+ ActivationFactory();
+ virtual ~ActivationFactory() FL_IOVERRIDE;
+ FL_DEFAULT_COPY_AND_MOVE(ActivationFactory)
+ };
+}
+
+#endif /* FL_ACTIVATIONFACTORY_H */
diff --git a/fuzzylite/fl/factory/CloningFactory.h b/fuzzylite/fl/factory/CloningFactory.h
index 3262721..a21e1d2 100644
--- a/fuzzylite/fl/factory/CloningFactory.h
+++ b/fuzzylite/fl/factory/CloningFactory.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_CLONINGFACTORY_H
@@ -33,9 +25,20 @@
namespace fl {
+ /**
+ The CloningFactory class is the base class for a factory whose objects
+ are created from a registered object by calling the `clone()` method.
+
+ @param <T> is the class of the object to be cloned
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see FactoryManager
+ @since 5.0
+ */
+
template <typename T>
- class FL_API CloningFactory {
- protected:
+ class CloningFactory {
+ private:
std::string _name;
std::map<std::string, T> _objects;
@@ -46,17 +49,178 @@ namespace fl {
virtual ~CloningFactory();
FL_DEFAULT_MOVE(CloningFactory)
+ /**
+ Returns the name of the factory
+ @return the name of the factory
+ */
virtual std::string name() const;
+ /**
+ Registers the object in the factory and assumes its ownership
+ @param key is the unique name by which objects are registered
+ @param object is the object to be cloned via a `clone` method
+ */
virtual void registerObject(const std::string& key, T object);
+ /**
+ Deregisters the given object from the factory and deletes it
+ @param key is the unique name by which objects are registered
+ */
virtual void deregisterObject(const std::string& key);
+ /**
+ Checks whether the factory has the given object registered
+ @param key is the unique name by which objects are registered
+ @return whether the factory has the given object registered
+ */
virtual bool hasObject(const std::string& key) const;
+ /**
+ Gets the object registered by the given key, not a clone of the object
+ @param key is the unique name by which objects are registered
+ @return the object registered by the given key
+ */
virtual T getObject(const std::string& key) const;
+ /**
+ Creates a cloned object by executing the clone method on the registered object
+ @param key is the unique name by which objects are registered
+ @return a cloned object by executing the clone method on the registered object
+ */
virtual T cloneObject(const std::string& key) const;
+ /**
+ Returns a vector of the available objects
+ @return a vector of the available objects
+ */
virtual std::vector<std::string> available() const;
+ /**
+ Gets the map of registered keys and objects
+ @return the map of registered keys and objects
+ */
+ virtual std::map<std::string, T>& objects();
+ /**
+ Gets an immutable map of registered keys and objects
+ @return an immutable map of registered keys and objects
+ */
+ virtual const std::map<std::string, T>& objects() const;
};
}
+/**
+ Template implementation
+ */
+
+#include "fl/Exception.h"
+
+namespace fl {
+
+ template<typename T>
+ inline CloningFactory<T>::CloningFactory(const std::string& name) : _name(name) {
+
+ }
+
+ template<typename T>
+ inline CloningFactory<T>::CloningFactory(const CloningFactory& other) {
+ typename std::map<std::string, T>::const_iterator it = other._objects.begin();
+ while (it != other._objects.end()) {
+ T clone = fl::null;
+ if (it->second) clone = it->second->clone();
+ this->_objects[it->first] = clone;
+ ++it;
+ }
+ }
+
+ template<typename T>
+ inline CloningFactory<T>& CloningFactory<T>::operator=(const CloningFactory& other) {
+ if (this != &other) {
+ typename std::map<std::string, T>::const_iterator it = this->_objects.begin();
+ while (it != this->_objects.end()) {
+ if (it->second) delete it->second;
+ ++it;
+ }
+ this->_objects.clear();
+
+ it = other._objects.begin();
+ while (it != other._objects.end()) {
+ T clone = fl::null;
+ if (it->second) clone = it->second->clone();
+ this->_objects[it->first] = clone;
+ ++it;
+ }
+ }
+ return *this;
+ }
+
+ template<typename T>
+ inline CloningFactory<T>::~CloningFactory() {
+ typename std::map<std::string, T>::const_iterator it = this->_objects.begin();
+ while (it != this->_objects.end()) {
+ if (it->second) delete it->second;
+ ++it;
+ }
+ }
+
+ template<typename T>
+ inline std::string CloningFactory<T>::name() const {
+ return this->_name;
+ }
+
+ template<typename T>
+ inline void CloningFactory<T>::registerObject(const std::string& key, T object) {
+ this->_objects[key] = object;
+ }
+
+ template<typename T>
+ inline void CloningFactory<T>::deregisterObject(const std::string& key) {
+ typename std::map<std::string, T>::iterator it = this->_objects.find(key);
+ if (it != this->_objects.end()) {
+ this->_objects.erase(it);
+ delete it->second;
+ }
+ }
+
+ template<typename T>
+ inline bool CloningFactory<T>::hasObject(const std::string& key) const {
+ typename std::map<std::string, T>::const_iterator it = this->_objects.find(key);
+ return (it != this->_objects.end());
+ }
+
+ template<typename T>
+ inline T CloningFactory<T>::getObject(const std::string& key) const {
+ typename std::map<std::string, T>::const_iterator it = this->_objects.find(key);
+ if (it != this->_objects.end()) {
+ if (it->second) return it->second;
+ }
+ return fl::null;
+ }
+
+ template<typename T>
+ inline T CloningFactory<T>::cloneObject(const std::string& key) const {
+ typename std::map<std::string, T>::const_iterator it = this->_objects.find(key);
+ if (it != this->_objects.end()) {
+ if (it->second) return it->second->clone();
+ return fl::null;
+ }
+ throw Exception("[cloning error] " + _name + " object by name <" + key + "> not registered", FL_AT);
+ }
+
+ template<typename T>
+ inline std::vector<std::string> CloningFactory<T>::available() const {
+ std::vector<std::string> result;
+ typename std::map<std::string, T>::const_iterator it = this->_objects.begin();
+ while (it != this->_objects.end()) {
+ result.push_back(it->first);
+ }
+ return result;
+ }
+
+ template<typename T>
+ inline std::map<std::string, T>& CloningFactory<T>::objects() {
+ return this->_objects;
+ }
+
+ template<typename T>
+ inline const std::map<std::string, T>& CloningFactory<T>::objects() const {
+ return this->_objects;
+ }
+}
+
#endif /* FL_CLONINGFACTORY_H */
diff --git a/fuzzylite/fl/factory/ConstructionFactory.h b/fuzzylite/fl/factory/ConstructionFactory.h
index d01ca7d..2558d7f 100644
--- a/fuzzylite/fl/factory/ConstructionFactory.h
+++ b/fuzzylite/fl/factory/ConstructionFactory.h
@@ -1,29 +1,21 @@
/*
- 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_FACTORY_H
-#define FL_FACTORY_H
+#ifndef FL_CONSTRUCTIONFACTORY_H
+#define FL_CONSTRUCTIONFACTORY_H
#include "fl/fuzzylite.h"
@@ -33,12 +25,25 @@
namespace fl {
+ /**
+ The ConstructionFactory class is the base class for a factory whose
+ objects are created from a registered ConstructionFactory::Constructor.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see FactoryManager
+ @since 5.0
+ */
+
template <typename T>
- class FL_API ConstructionFactory {
+ class ConstructionFactory {
public:
+ /**
+ The Constructor type definition refers to a zero-parameter method
+ which returns an instance of T
+ */
typedef T(*Constructor)();
- protected:
+ private:
std::string _name;
std::map<std::string, Constructor> _constructors;
@@ -47,18 +52,151 @@ namespace fl {
virtual ~ConstructionFactory();
FL_DEFAULT_COPY_AND_MOVE(ConstructionFactory)
+ /**
+ Returns the name of the factory
+ @return the name of the factory
+ */
virtual std::string name() const;
+ /**
+ Registers the constructor in the factory
+ @param key is the unique name by which constructors are registered
+ @param constructor is the pointer to the constructor of the object
+ */
virtual void registerConstructor(const std::string& key, Constructor constructor);
+ /**
+ Deregisters from the factory the constructor associated to the given key
+ @param key is the unique name by which constructors are registered
+ */
virtual void deregisterConstructor(const std::string& key);
+ /**
+ Checks whether the factory has a constructor registered by the given key
+ @param key is the unique name by which constructors are registered
+ @return whether the factory has the given constructor registered
+ */
virtual bool hasConstructor(const std::string& key) const;
+ /**
+ Gets the constructor registered by the given key
+ @param key is the unique name by which constructors are registered
+ @return the pointer to the given constructor
+ */
virtual Constructor getConstructor(const std::string& key) const;
+ /**
+ Creates an object by executing the constructor associated to the given key
+ @param key is the unique name by which constructors are registered
+ @return an object by executing the constructor associated to the given key
+ */
virtual T constructObject(const std::string& key) const;
+ /**
+ Returns a vector of keys for the constructors available
+ @return a vector of keys for the constructors available
+ */
virtual std::vector<std::string> available() const;
-
+ /**
+ Gets the map of registered keys and constructors
+ @return the map of registered keys and constructors
+ */
+ virtual std::map<std::string, Constructor>& constructors();
+ /**
+ Gets an immutable map of registered keys and constructors
+ @return an immutable map of registered keys and constructors
+ */
+ virtual const std::map<std::string, Constructor>& constructors() const;
};
}
-#endif /* FL_FACTORY_H */
+/**
+ * Template implementation
+ */
+
+
+#include "fl/Exception.h"
+#include "fl/defuzzifier/Defuzzifier.h"
+#include "fl/hedge/Hedge.h"
+#include "fl/norm/SNorm.h"
+#include "fl/norm/TNorm.h"
+#include "fl/term/Term.h"
+
+namespace fl {
+
+ template <typename T>
+ inline ConstructionFactory<T>::ConstructionFactory(const std::string& name) : _name(name) {
+
+ }
+
+ template <typename T>
+ inline ConstructionFactory<T>::~ConstructionFactory() {
+ }
+
+ template<typename T>
+ inline std::string ConstructionFactory<T>::name() const {
+ return this->_name;
+ }
+
+ template <typename T>
+ inline void ConstructionFactory<T>::registerConstructor(const std::string& key, Constructor constructor) {
+ this->_constructors[key] = constructor;
+ }
+
+ template <typename T>
+ inline void ConstructionFactory<T>::deregisterConstructor(const std::string& key) {
+ typename std::map<std::string, Constructor>::iterator it = this->_constructors.find(key);
+ if (it != this->_constructors.end()) {
+ this->_constructors.erase(it);
+ }
+ }
+
+ template <typename T>
+ inline bool ConstructionFactory<T>::hasConstructor(const std::string& key) const {
+ typename std::map<std::string, Constructor>::const_iterator it = this->_constructors.find(key);
+ return (it != this->_constructors.end());
+ }
+
+ template <typename T>
+ inline typename ConstructionFactory<T>::Constructor ConstructionFactory<T>::getConstructor(const std::string& key) const {
+ typename std::map<std::string, Constructor>::const_iterator it = this->_constructors.find(key);
+ if (it != this->_constructors.end()) {
+ return it->second;
+ }
+ return fl::null;
+ }
+
+ template <typename T>
+ inline T ConstructionFactory<T>::constructObject(const std::string& key) const {
+ typename std::map<std::string, Constructor>::const_iterator it = this->_constructors.find(key);
+ if (it != this->_constructors.end()) {
+ if (it->second) {
+ return it->second();
+ }
+ return fl::null;
+ }
+ std::ostringstream ss;
+ ss << "[factory error] constructor of " + _name + " <" << key << "> not registered";
+ throw Exception(ss.str(), FL_AT);
+ }
+
+ template <typename T>
+ inline std::vector<std::string> ConstructionFactory<T>::available() const {
+ std::vector<std::string> result;
+ typename std::map<std::string, Constructor>::const_iterator it = this->_constructors.begin();
+ while (it != this->_constructors.end()) {
+ result.push_back(it->first);
+ ++it;
+ }
+ return result;
+ }
+
+ template<typename T>
+ inline std::map<std::string, typename ConstructionFactory<T>::Constructor>& ConstructionFactory<T>::constructors() {
+ return this->_constructors;
+ }
+
+ template<typename T>
+ inline const std::map<std::string, typename ConstructionFactory<T>::Constructor>& ConstructionFactory<T>::constructors() const {
+ return this->_constructors;
+ }
+}
+
+#endif /* FL_CONSTRUCTIONFACTORY_H */
diff --git a/fuzzylite/fl/factory/DefuzzifierFactory.h b/fuzzylite/fl/factory/DefuzzifierFactory.h
index 32d3ee7..8fa4c1b 100644
--- a/fuzzylite/fl/factory/DefuzzifierFactory.h
+++ b/fuzzylite/fl/factory/DefuzzifierFactory.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_DEFUZZIFIERFACTORY_H
@@ -33,19 +25,51 @@
namespace fl {
+ /**
+ The DefuzzifierFactory class is a ConstructionFactory of Defuzzifier%s.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Defuzzifier
+ @see ConstructionFactory
+ @see FactoryManager
+ @since 4.0
+ */
class FL_API DefuzzifierFactory : public ConstructionFactory<Defuzzifier*> {
public:
DefuzzifierFactory();
virtual ~DefuzzifierFactory() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(DefuzzifierFactory)
+ /**
+ Creates a Defuzzifier by executing the registered constructor
+ @param key is the unique name by which constructors are registered
+ @param resolution is the resolution of an IntegralDefuzzifier
+ @param type is the type of a WeightedDefuzzifier
+ @return a Defuzzifier by executing the registered constructor and
+ setting its resolution or type accordingly
+ */
virtual Defuzzifier* constructDefuzzifier(const std::string& key,
- int resolution, WeightedDefuzzifier::Type) const;
+ int resolution, WeightedDefuzzifier::Type type) const;
+ /**
+ Creates a Defuzzifier by executing the registered constructor
+ @param key is the unique name by which constructors are registered
+ @param resolution is the resolution of an IntegralDefuzzifier
+ @return a Defuzzifier by executing the registered constructor and
+ setting its resolution
+ */
virtual Defuzzifier* constructDefuzzifier(const std::string& key, int resolution) const;
+ /**
+ Creates a Defuzzifier by executing the registered constructor
+ @param key is the unique name by which constructors are registered
+ @param type is the type of a WeightedDefuzzifier
+ @return a Defuzzifier by executing the registered constructor and
+ setting its type
+ */
virtual Defuzzifier* constructDefuzzifier(const std::string& key, WeightedDefuzzifier::Type type);
};
}
+
#endif /* DEFUZZIFIERFACTORY_H */
diff --git a/fuzzylite/fl/factory/FactoryManager.h b/fuzzylite/fl/factory/FactoryManager.h
index d853d93..79f7996 100644
--- a/fuzzylite/fl/factory/FactoryManager.h
+++ b/fuzzylite/fl/factory/FactoryManager.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_FACTORYMANAGER_H
@@ -27,55 +19,136 @@
#include "fl/fuzzylite.h"
+#include "fl/factory/TNormFactory.h"
+#include "fl/factory/SNormFactory.h"
+#include "fl/factory/ActivationFactory.h"
+#include "fl/factory/DefuzzifierFactory.h"
+#include "fl/factory/TermFactory.h"
+#include "fl/factory/HedgeFactory.h"
+#include "fl/factory/FunctionFactory.h"
+
namespace fl {
- class TNormFactory;
- class SNormFactory;
- class DefuzzifierFactory;
- class TermFactory;
- class HedgeFactory;
- class FunctionFactory;
+ /**
+ The FactoryManager class is a central class grouping different factories
+ of objects, together with a singleton instance to access each of the
+ factories throughout the library.
+
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see TermFactory
+ @see TNormFactory
+ @see SNormFactory
+ @see HedgeFactory
+ @see ActivationFactory
+ @see DefuzzifierFactory
+ @see FunctionFactory
+ @since 4.0
+ */
class FL_API FactoryManager {
- protected:
- static FactoryManager _instance;
-
+ private:
FL_unique_ptr<TNormFactory> _tnorm;
FL_unique_ptr<SNormFactory> _snorm;
+ FL_unique_ptr<ActivationFactory> _activation;
FL_unique_ptr<DefuzzifierFactory> _defuzzifier;
FL_unique_ptr<TermFactory> _term;
FL_unique_ptr<HedgeFactory> _hedge;
FL_unique_ptr<FunctionFactory> _function;
+ public:
FactoryManager();
- FactoryManager(TNormFactory* tnorm, SNormFactory* snorm,
- DefuzzifierFactory* defuzzifier, TermFactory* term,
- HedgeFactory* hedge, FunctionFactory* function);
- FactoryManager(const FactoryManager& other);
+ explicit FactoryManager(TNormFactory* tnorm, SNormFactory* snorm,
+ ActivationFactory* activation, DefuzzifierFactory* defuzzifier,
+ TermFactory* term, HedgeFactory* hedge, FunctionFactory* function);
+ explicit FactoryManager(const FactoryManager& other);
FactoryManager& operator=(const FactoryManager& other);
FL_DEFAULT_MOVE(FactoryManager)
virtual ~FactoryManager();
- public:
+ /**
+ Gets the static instance of the manager
+ @return the static instance of the manager
+ */
static FactoryManager* instance();
+ /**
+ Sets the factory of TNorm%s
+ @param tnorm is the factory of TNorm%s
+ */
virtual void setTnorm(TNormFactory* tnorm);
+ /**
+ Gets the factory of TNorm%s
+ @return the factory of TNorm%s
+ */
virtual TNormFactory* tnorm() const;
+ /**
+ Sets the factory of SNorm%s
+ @param snorm is the factory of SNorm%s
+ */
virtual void setSnorm(SNormFactory* snorm);
+ /**
+ Gets the factory of SNorm%s
+ @return the factory of SNorm%s
+ */
virtual SNormFactory* snorm() const;
+ /**
+ Sets the factory of Activation methods
+ @param activation is the factory of Activation methods
+ */
+ virtual void setActivation(ActivationFactory* activation);
+ /**
+ Gets the factory of Activation methods
+ @return the factory of Activation methods
+ */
+ virtual ActivationFactory* activation() const;
+
+ /**
+ Sets the factory of Defuzzifier%s
+ @param defuzzifier is the factory of Defuzzifier%s
+ */
virtual void setDefuzzifier(DefuzzifierFactory* defuzzifier);
+ /**
+ Gets the factory of Defuzzifier%s
+ @return the factory of Defuzzifier%s
+ */
virtual DefuzzifierFactory* defuzzifier() const;
+ /**
+ Sets the factory of Term%s
+ @param term is the factory of Term%s
+ */
virtual void setTerm(TermFactory* term);
+ /**
+ Gets the factory of Term%s
+ @return the factory of Term%s
+ */
virtual TermFactory* term() const;
+ /**
+ Sets the factory of Hedge%s
+ @param hedge is the factory of Hedge%s
+ */
virtual void setHedge(HedgeFactory* hedge);
+ /**
+ Gets the factory of Hedge%s
+ @return the factory of Hedge%s
+ */
virtual HedgeFactory* hedge() const;
+ /**
+ Sets the factory of Function Element%s
+ @param function is the factory of Function Element%s
+ */
virtual void setFunction(FunctionFactory* function);
+ /**
+ Gets the factory of Function Element%s
+ @return the factory of Function Element%s
+ */
virtual FunctionFactory* function() const;
};
}
+
#endif /* FL_FACTORYMANAGER_H */
diff --git a/fuzzylite/fl/factory/FunctionFactory.h b/fuzzylite/fl/factory/FunctionFactory.h
index c1ea9f1..84e0104 100644
--- a/fuzzylite/fl/factory/FunctionFactory.h
+++ b/fuzzylite/fl/factory/FunctionFactory.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_FUNCTIONFACTORY_H
@@ -31,7 +23,18 @@
namespace fl {
- class FunctionFactory : public CloningFactory<Function::Element*> {
+ /**
+ The FunctionFactory class is a CloningFactory of operators and functions
+ utilized by the Function term.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Function
+ @see Element
+ @see CloningFactory
+ @see FactoryManager
+ @since 5.0
+ */
+ class FL_API FunctionFactory : public CloningFactory<Function::Element*> {
private:
void registerOperators();
void registerFunctions();
@@ -40,11 +43,18 @@ namespace fl {
virtual ~FunctionFactory() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FunctionFactory)
+ /**
+ Returns a vector of the operators available
+ @return a vector of the operators available
+ */
virtual std::vector<std::string> availableOperators() const;
+ /**
+ Returns a vector of the functions available
+ @return a vector of the functions available
+ */
virtual std::vector<std::string> availableFunctions() const;
};
-
}
#endif /* FL_FUNCTIONFACTORY_H */
diff --git a/fuzzylite/fl/factory/HedgeFactory.h b/fuzzylite/fl/factory/HedgeFactory.h
index aca5d3a..e4733b2 100644
--- a/fuzzylite/fl/factory/HedgeFactory.h
+++ b/fuzzylite/fl/factory/HedgeFactory.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_HEDGEFACTORY_H
@@ -31,6 +23,15 @@
namespace fl {
+ /**
+ The HedgeFactory class is a ConstructionFactory of Hedge%s.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Hedge
+ @see ConstructionFactory
+ @see FactoryManager
+ @since 4.0
+ */
class FL_API HedgeFactory : public ConstructionFactory<Hedge*> {
public:
HedgeFactory();
@@ -38,5 +39,6 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(HedgeFactory)
};
}
+
#endif /* FL_HEDGEFACTORY_H */
diff --git a/fuzzylite/fl/factory/SNormFactory.h b/fuzzylite/fl/factory/SNormFactory.h
index ca8bf1a..111664a 100644
--- a/fuzzylite/fl/factory/SNormFactory.h
+++ b/fuzzylite/fl/factory/SNormFactory.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_SNORMFACTORY_H
@@ -31,6 +23,15 @@
namespace fl {
+ /**
+ The SNormFactory class is a ConstructionFactory of SNorm%s.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see SNorm
+ @see ConstructionFactory
+ @see FactoryManager
+ @since 4.0
+ */
class FL_API SNormFactory : public ConstructionFactory<SNorm*> {
public:
SNormFactory();
@@ -38,5 +39,6 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(SNormFactory)
};
}
+
#endif /* FL_SNORMFACTORY_H */
diff --git a/fuzzylite/fl/factory/TNormFactory.h b/fuzzylite/fl/factory/TNormFactory.h
index 6af2249..5093fa7 100644
--- a/fuzzylite/fl/factory/TNormFactory.h
+++ b/fuzzylite/fl/factory/TNormFactory.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_TNORMFACTORY_H
@@ -31,6 +23,15 @@
namespace fl {
+ /**
+ The TNormFactory class is a ConstructionFactory of TNorm%s.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see TNorm
+ @see ConstructionFactory
+ @see FactoryManager
+ @since 4.0
+ */
class FL_API TNormFactory : public ConstructionFactory<TNorm*> {
public:
TNormFactory();
@@ -38,5 +39,6 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(TNormFactory)
};
}
+
#endif /* FL_TNORMFACTORY_H */
diff --git a/fuzzylite/fl/factory/TermFactory.h b/fuzzylite/fl/factory/TermFactory.h
index 6fd0656..f6a5d60 100644
--- a/fuzzylite/fl/factory/TermFactory.h
+++ b/fuzzylite/fl/factory/TermFactory.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_TERMFACTORY_H
@@ -32,6 +24,15 @@
namespace fl {
+ /**
+ The TermFactory class is a ConstructionFactory of Term%s.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see ConstructionFactory
+ @see FactoryManager
+ @since 4.0
+ */
class FL_API TermFactory : public ConstructionFactory<Term*> {
public:
TermFactory();
@@ -39,5 +40,6 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(TermFactory)
};
}
+
#endif /* FL_TERMFACTORY_H */
diff --git a/fuzzylite/fl/fuzzylite.h b/fuzzylite/fl/fuzzylite.h
index 18c8dfa..3cca94b 100644
--- a/fuzzylite/fl/fuzzylite.h
+++ b/fuzzylite/fl/fuzzylite.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_FUZZYLITE_H
@@ -31,14 +23,7 @@
#include <sstream>
#include <limits>
#include <memory>
-
-#ifndef FL_VERSION
-#define FL_VERSION "?"
-#endif
-
-#ifndef FL_DATE
-#define FL_DATE "?"
-#endif
+#include <cstddef>
#ifndef FL_BUILD_PATH
#define FL_BUILD_PATH ""
@@ -54,19 +39,21 @@
#ifdef __APPLE__
#define FL_APPLE
+#ifndef FL_UNIX
+#define FL_UNIX
+#endif
#endif
#define FL__FILE__ std::string(__FILE__).substr(std::string(FL_BUILD_PATH).size())
-#define FL_LOG_PREFIX FL__FILE__ << " [" << __LINE__ << "]:"
+#define FL_LOG_PREFIX FL__FILE__ << " (" << __LINE__ << "):"
#define FL_AT FL__FILE__, __LINE__, __FUNCTION__
+#define FL_LOG(message) {if (fl::fuzzylite::isLogging()){std::cout << FL_LOG_PREFIX << message << std::endl;}}
+#define FL_LOGP(message) {if (fl::fuzzylite::isLogging()){std::cout << message << std::endl;}}
-#define FL_LOG(message) {if (fl::fuzzylite::logging()){std::cout << FL_LOG_PREFIX << message << std::endl;}}
-#define FL_LOGP(message) {if (fl::fuzzylite::logging()){std::cout << message << std::endl;}}
-
-#define FL_DEBUG_BEGIN if (fl::fuzzylite::debug()){
+#define FL_DEBUG_BEGIN if (fl::fuzzylite::isDebugging()){
#define FL_DEBUG_END }
#define FL_DBG(message) FL_DEBUG_BEGIN\
@@ -83,7 +70,7 @@
//#define bitand &
//#define bitor |
-//TODO: Address warning 4251 by exporting members?
+//@todo: Address warning 4251 by exporting members?
//http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html
#ifdef _MSC_VER
#pragma warning (disable:4251)
@@ -107,21 +94,80 @@
#define FL_API
#endif
+/**
+ The fl namespace is the namespace where all the classes of the `fuzzylite`
+ library are contained in.
+ @author Juan Rada-Vilela, Ph.D.
+ @since 4.0
+ */
namespace fl {
+ /**
+ Represents floating-point values (typedef to float or double).
+ */
#ifdef FL_USE_FLOAT
typedef float scalar;
#else
+ /**
+ Represents floating-point values as doubles.
+ */
typedef double scalar;
#endif
- const scalar nan = std::numeric_limits<scalar>::quiet_NaN();
- const scalar inf = std::numeric_limits<scalar>::infinity();
+#define FL_IUNUSED(x) (void) (x)
+
+#ifdef __GNUC__
+#define FL_IUNUSED_DECL __attribute__((unused))
+#else
+#define FL_IUNUSED_DECL
+#endif
-#ifdef FL_CPP11
+ /**
+ Represents the Not-A-Number scalar value
+ */
+ const scalar nan FL_IUNUSED_DECL = std::numeric_limits<scalar>::quiet_NaN();
+ /**
+ Represents the infinity scalar value
+ */
+ const scalar inf FL_IUNUSED_DECL = std::numeric_limits<scalar>::infinity();
+
+#ifdef FL_CPP98
+ //C++98 defines
+
+ //Pointers
+ /**
+ Represents the `C++11` or `C++98` null pointer depending on whether the
+ compilation flag `-DFL_CPP98` is set
+ */
+ const long null = 0L;
+#define FL_unique_ptr std::auto_ptr
+#define FL_move_ptr(x) x
+
+ //Identifiers
+#define FL_IOVERRIDE
+#define FL_IFINAL
+#define FL_IDEFAULT
+#define FL_IDELETE
+#define FL_INOEXCEPT throw()
+#define FL_ITHREAD_LOCAL
+
+ //Constructors
+#define FL_DEFAULT_COPY(Class)
+#define FL_DEFAULT_MOVE(Class)
+#define FL_DEFAULT_COPY_AND_MOVE(Class)
+
+#define FL_DISABLE_COPY(Class) \
+ Class(const Class &);\
+ Class &operator=(const Class &);
+
+#else
//C++11 defines
//Pointers
+ /**
+ Represents the `C++11` or `C++98` null pointer depending on whether the
+ compilation flag `-DFL_CPP98` is set
+ */
const std::nullptr_t null = nullptr;
#define FL_unique_ptr std::unique_ptr
#define FL_move_ptr(x) std::move(x)
@@ -132,6 +178,7 @@ namespace fl {
#define FL_IDEFAULT = default
#define FL_IDELETE = delete
#define FL_INOEXCEPT noexcept
+#define FL_ITHREAD_LOCAL /*thread_local (commented for performance)*/
//Constructors
#define FL_DEFAULT_COPY(Class) \
@@ -150,73 +197,231 @@ namespace fl {
Class(const Class &) = delete;\
Class &operator=(const Class &) = delete;
-#else
- //C++98 defines
+#endif
- //Pointers
- const long null = 0L;
-#define FL_unique_ptr std::auto_ptr
-#define FL_move_ptr(x) x
+}
- //Identifiers
-#define FL_IOVERRIDE
-#define FL_IFINAL
-#define FL_IDEFAULT
-#define FL_IDELETE
-#define FL_INOEXCEPT throw()
- //Constructors
-#define FL_DEFAULT_COPY(Class)
-#define FL_DEFAULT_MOVE(Class)
-#define FL_DEFAULT_COPY_AND_MOVE(Class)
+namespace fl {
-#define FL_DISABLE_COPY(Class) \
- Class(const Class &);\
- Class &operator=(const Class &);
+ /**
-#endif
-}
+ The fuzzylite class contains global settings and information about the
+ library.
+ @author Juan Rada-Vilela, Ph.D.
+ @since 4.0
-namespace fl {
+ */
class FL_API fuzzylite {
- protected:
+ friend class Operation;
+ private:
static int _decimals;
static scalar _macheps;
- static bool _debug;
+ static std::ios_base::fmtflags _scalarFormat;
static bool _logging;
-
+ static bool _debugging;
public:
+ /**
+ Returns the name of the `fuzzylite` library
+ @return the name of the `fuzzylite` library
+ */
static std::string name();
- static std::string fullname();
+ /**
+ Returns the version of the `fuzzylite` library
+ @return the version of the `fuzzylite` library
+ */
static std::string version();
- static std::string longVersion();
+ /**
+ Returns the name of the `fuzzylite` library including the version
+ @return the name of the `fuzzylite` library including the version
+ */
+ static std::string library();
+
+ /**
+ Returns the license under which the `fuzzylite` library is released
+ @return the license under which the `fuzzylite` library is released
+ */
static std::string license();
- static std::string author();
- static std::string company();
- static std::string website();
- static std::string date();
- static std::string platform();
+ /**
+ Returns the name of the author of the `fuzzylite` library
+ @return "Juan Rada-Vilela, Ph.D."
+ */
+ static std::string author();
- static std::string floatingPoint();
+ /**
+ Returns the name of the company that owns the `fuzzylite` library
+ @return "FuzzyLite Limited"
+ */
+ static std::string company();
- static bool debug();
- static void setDebug(bool debug);
+ /**
+ Returns the website of the `fuzzylite` library
+ @return "http://www.fuzzylite.com/"
+ */
+ static std::string website();
+ /**
+ Returns the number of decimals utilized when formatting scalar values
+ @return the number of decimals utilized when formatting scalar values
+ (default is 3)
+ */
static int decimals();
+
+ /**
+ Sets the number of decimals utilized when formatting scalar values
+ @param decimals is the number of decimals utilized when formatting
+ scalar values
+ */
static void setDecimals(int decimals);
+ /**
+ Returns the minimum difference at which two floating-point values
+ are considered equivalent
+ @return the minimum difference at which two floating-point values
+ are considered equivalent (default is 1e-6)
+ */
static scalar macheps();
+
+ /**
+ Sets the minimum difference at which two floating-point values are
+ considered equivalent
+ @param macheps is the minimum difference at which two floating-point
+ values are considered equivalent (default is 1e-6)
+ */
static void setMachEps(scalar macheps);
- static bool logging();
+ /**
+ Sets the default format to be utilized for every fl::scalar passed to
+ Op::str()
+ @param scalarFormat is the format to be utilized for every fl::scalar
+ passed to Op::str()
+ */
+ static void setScalarFormat(std::ios_base::fmtflags scalarFormat);
+
+ /**
+ Gets the default format to be utilized for every fl::scalar passed to
+ Op::str()
+ @return the format to be utilized for every fl::scalar passed to Op::str()
+ */
+ static std::ios_base::fmtflags scalarFormat();
+
+ /**
+ Returns whether the library is logging information via the `FL_LOG`
+ macro
+ @return whether the library is logging information via the `FL_LOG`
+ macro
+ */
+ static bool isLogging();
+
+ /**
+ Sets whether the library is set to log information using the macro
+ `FL_LOG`
+ @param logging indicates whether the library is set to log
+ information via the `FL_LOG` macro
+ */
static void setLogging(bool logging);
+ /**
+ Indicates whether the library is running in debug mode
+ @return `true` if the library is running in debug mode, and `false`
+ if it is running in release mode
+ */
+ static bool isDebugging();
+
+ /**
+ Sets whether the library is set to run in debug mode
+ @param debugging indicates whether the library is set to run in debug mode
+ */
+ static void setDebugging(bool debugging);
+
+ /**
+ Returns the platform under which the `fuzzylite` library was built
+ @return `Unix` or `Windows`
+ */
+ static std::string platform();
+
+ /**
+ Returns the name of the type of the floating-point variables
+ @return `double` or `float`
+ */
+ static std::string floatingPoint();
};
}
+namespace fl {
+
+ inline std::string fuzzylite::name() {
+ return "fuzzylite";
+ }
+
+ inline std::string fuzzylite::library() {
+ return name() + " " + version();
+ }
+
+ inline std::string fuzzylite::version() {
+ return "6.0";
+ }
+
+ inline std::string fuzzylite::license() {
+ return "FuzzyLite License";
+ }
+
+ inline std::string fuzzylite::author() {
+ return "Juan Rada-Vilela, Ph.D.";
+ }
+
+ inline std::string fuzzylite::company() {
+ return "FuzzyLite Limited";
+ }
+
+ inline std::string fuzzylite::website() {
+ return "http://www.fuzzylite.com/";
+ }
+
+ inline void fuzzylite::setDebugging(bool debugging) {
+ _debugging = debugging;
+ }
+
+ inline bool fuzzylite::isDebugging() {
+ return _debugging;
+ }
+
+ inline void fuzzylite::setDecimals(int decimals) {
+ _decimals = decimals;
+ }
+
+ inline int fuzzylite::decimals() {
+ return _decimals;
+ }
+
+ inline void fuzzylite::setScalarFormat(std::ios_base::fmtflags scalarFormat) {
+ _scalarFormat = scalarFormat;
+ }
+
+ inline std::ios_base::fmtflags fuzzylite::scalarFormat() {
+ return _scalarFormat;
+ }
+
+ inline void fuzzylite::setMachEps(scalar macheps) {
+ _macheps = macheps;
+ }
+
+ inline scalar fuzzylite::macheps() {
+ return _macheps;
+ }
+
+ inline void fuzzylite::setLogging(bool logging) {
+ _logging = logging;
+ }
+
+ inline bool fuzzylite::isLogging() {
+ return _logging;
+ }
+}
+
#endif /* FL_FUZZYLITE_H */
diff --git a/fuzzylite/fl/hedge/Any.h b/fuzzylite/fl/hedge/Any.h
index c30b4c7..bf71842 100644
--- a/fuzzylite/fl/hedge/Any.h
+++ b/fuzzylite/fl/hedge/Any.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_ANY_H
@@ -28,8 +20,20 @@
#include "fl/hedge/Hedge.h"
namespace fl {
- //Only this hedge has virtual methods due to its special case use.
+ /**
+ The Any class is a special Hedge that always returns `1.0`. Its
+ position with respect to the other hedges is last in the ordered set
+ (Not, Seldom, Somewhat, Very, Extremely, Any). The Antecedent of a Rule
+ considers Any to be a syntactically special hedge because it is not
+ followed by a Term (e.g., `if Variable is any then...`). Amongst hedges,
+ only Any has virtual methods to be overriden due to its particular case.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Hedge
+ @see HedgeFactory
+ @since 4.0
+ */
class FL_API Any : public Hedge {
public:
Any();
@@ -37,11 +41,20 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Any)
virtual std::string name() const FL_IOVERRIDE;
+
+
+ virtual Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the hedge for the given value
+ @param x is irrelevant
+ @return `1.0`
+ */
virtual scalar hedge(scalar x) const FL_IOVERRIDE;
virtual Any* clone() const FL_IOVERRIDE;
static Hedge* constructor();
};
-
}
+
#endif /* FL_ANY_H */
diff --git a/fuzzylite/fl/hedge/Extremely.h b/fuzzylite/fl/hedge/Extremely.h
index 7ecda66..fbd617a 100644
--- a/fuzzylite/fl/hedge/Extremely.h
+++ b/fuzzylite/fl/hedge/Extremely.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_EXTREMELY_H
@@ -29,14 +21,35 @@
namespace fl {
- class FL_API Extremely : public Hedge {
+ /**
+ The Extremely class is a Hedge located fifth in the ordered set
+ (Not, Seldom, Somewhat, Very, Extremely, Any).
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Hedge
+ @see HedgeFactory
+ @since 4.0
+ */
+ class FL_API Extremely FL_IFINAL : public Hedge {
public:
- std::string name() const;
- scalar hedge(scalar x) const;
- Extremely* clone() const;
+ std::string name() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the hedge for the membership function value @f$x@f$
+ @param x is a membership function value
+ @return @f$
+ \begin{cases}
+ 2x^2 & \mbox{if $x \le 0.5$} \cr
+ 1-2(1-x)^2 & \mbox{otherwise} \cr
+ \end{cases}@f$
+ */
+ scalar hedge(scalar x) const FL_IOVERRIDE;
+ Extremely* clone() const FL_IOVERRIDE;
static Hedge* constructor();
};
-
}
+
#endif /* FL_EXTREMELY_H */
diff --git a/fuzzylite/fl/hedge/Hedge.h b/fuzzylite/fl/hedge/Hedge.h
index 011c745..9dac17c 100644
--- a/fuzzylite/fl/hedge/Hedge.h
+++ b/fuzzylite/fl/hedge/Hedge.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_HEDGE_H
@@ -27,10 +19,24 @@
#include "fl/fuzzylite.h"
+#include "fl/Complexity.h"
+
#include <string>
namespace fl {
+ /**
+ The Hedge class is the abstract class for hedges. Hedges are utilized
+ within the Antecedent and Consequent of a Rule in order to modify the
+ membership function of a linguistic Term.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Antecedent
+ @see Consequent
+ @see Rule
+ @see HedgeFactory
+ @since 4.0
+ */
class FL_API Hedge {
public:
@@ -41,8 +47,28 @@ namespace fl {
}
FL_DEFAULT_COPY_AND_MOVE(Hedge)
+ /**
+ Returns the name of the hedge
+ @return the name of the hedge
+ */
virtual std::string name() const = 0;
+
+ /**
+ Computes the estimated complexity of applying the hedge
+ @return the estimated complexity of applying the hedge
+ */
+ virtual Complexity complexity() const = 0;
+ /**
+ Computes the hedge for the membership function value @f$x@f$
+ @param x is a membership function value
+ @return the hedge of @f$x@f$
+ */
virtual scalar hedge(scalar x) const = 0;
+
+ /**
+ Creates a clone of the hedge
+ @return a clone of the hedge.
+ */
virtual Hedge* clone() const = 0;
};
diff --git a/fuzzylite/fl/hedge/HedgeFunction.h b/fuzzylite/fl/hedge/HedgeFunction.h
new file mode 100644
index 0000000..bc8930d
--- /dev/null
+++ b/fuzzylite/fl/hedge/HedgeFunction.h
@@ -0,0 +1,82 @@
+/*
+ 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_HEDGEFUNCTION_H
+#define FL_HEDGEFUNCTION_H
+
+#include "fl/hedge/Hedge.h"
+
+#include "fl/term/Function.h"
+
+namespace fl {
+
+ /**
+ The HedgeFunction class is a customizable Hedge via Function, which
+ computes any function based on the @f$x@f$ value. This hedge is not
+ registered with the HedgeFactory due to issues configuring the formula
+ within. To register the hedge, a static method with the
+ constructor needs to be manually created and registered. Please, check the
+ file `test/hedge/HedgeFunction.cpp` for further details.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Function
+ @see Hedge
+ @see HedgeFactory
+ @since 6.0
+ */
+
+ class FL_API HedgeFunction FL_IFINAL : public Hedge {
+ private:
+ Function _function;
+ public:
+ explicit HedgeFunction(const std::string& formula = "");
+
+ std::string name() const FL_IOVERRIDE;
+
+ /**
+ Returns the reference to the Function
+ @return the reference to the Function
+ */
+ Function& function();
+
+ /**
+ Loads the function with the given formula
+ @param formula is a valid formula in infix notation
+ */
+ void setFormula(const std::string& formula);
+ /**
+ Returns the formula loaded into the function
+ @return the formula loaded into the function
+ */
+ std::string getFormula() const;
+
+ Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the hedge for the membership function value @f$x@f$ utilizing
+ the given function via HedgeFunction::setFormula()
+ @param x is a membership function value
+ @return the evaluation of the function
+ */
+ scalar hedge(scalar x) const FL_IOVERRIDE;
+ HedgeFunction* clone() const FL_IOVERRIDE;
+
+ static Hedge* constructor();
+ };
+}
+
+#endif /* FL_HEDGEFUNCTION_H */
+
diff --git a/fuzzylite/fl/hedge/Not.h b/fuzzylite/fl/hedge/Not.h
index 161fefd..e981ac9 100644
--- a/fuzzylite/fl/hedge/Not.h
+++ b/fuzzylite/fl/hedge/Not.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_NOT_H
@@ -29,14 +21,31 @@
namespace fl {
- class FL_API Not : public Hedge {
+ /**
+ The Not class is a Hedge located first in the ordered set
+ (Not, Seldom, Somewhat, Very, Extremely, Any).
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Hedge
+ @see HedgeFactory
+ @since 4.0
+ */
+ class FL_API Not FL_IFINAL : public Hedge {
public:
std::string name() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the hedge for the membership function value @f$x@f$
+ @param x is a membership function value
+ @return @f$1-x@f$
+ */
scalar hedge(scalar x) const FL_IOVERRIDE;
Not* clone() const FL_IOVERRIDE;
static Hedge* constructor();
};
-
}
+
#endif /* FL_NOT_H */
diff --git a/fuzzylite/fl/hedge/Seldom.h b/fuzzylite/fl/hedge/Seldom.h
index a2a96c2..0bbedbf 100644
--- a/fuzzylite/fl/hedge/Seldom.h
+++ b/fuzzylite/fl/hedge/Seldom.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_SELDOM_H
@@ -29,14 +21,36 @@
namespace fl {
- class FL_API Seldom : public Hedge {
+ /**
+ The Seldom class is a Hedge located second in the ordered set
+ (Not, Seldom, Somewhat, Very, Extremely, Any).
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Hedge
+ @see HedgeFactory
+ @since 4.0
+ */
+ class FL_API Seldom FL_IFINAL : public Hedge {
public:
std::string name() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the hedge for the membership function value @f$x@f$
+ @param x is a membership function value
+ @return @f$
+ \begin{cases}
+ \sqrt{0.5x} & \mbox{if $x \le 0.5$} \cr
+ 1-\sqrt{0.5(1-x)} & \mbox{otherwise}\cr
+ \end{cases}
+ @f$
+ */
scalar hedge(scalar x) const FL_IOVERRIDE;
Seldom* clone() const FL_IOVERRIDE;
static Hedge* constructor();
};
-
}
+
#endif /* FL_SELDOM_H */
diff --git a/fuzzylite/fl/hedge/Somewhat.h b/fuzzylite/fl/hedge/Somewhat.h
index 89a14a6..ccd21ec 100644
--- a/fuzzylite/fl/hedge/Somewhat.h
+++ b/fuzzylite/fl/hedge/Somewhat.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_SOMEWHAT_H
@@ -29,14 +21,32 @@
namespace fl {
- class FL_API Somewhat : public Hedge {
+ /**
+ The Somewhat class is a Hedge located third in the ordered set
+ (Not, Seldom, Somewhat, Very, Extremely, Any).
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Hedge
+ @see HedgeFactory
+ @since 4.0
+ */
+ class FL_API Somewhat FL_IFINAL : public Hedge {
public:
std::string name() const FL_IOVERRIDE;
+
+
+ Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the hedge for the membership function value @f$x@f$
+ @param x is a membership function value
+ @return @f$\sqrt{x}@f$
+ */
scalar hedge(scalar x) const FL_IOVERRIDE;
Somewhat* clone() const FL_IOVERRIDE;
static Hedge* constructor();
};
-
}
+
#endif /* FL_SOMEWHAT_H */
diff --git a/fuzzylite/fl/hedge/Very.h b/fuzzylite/fl/hedge/Very.h
index bcfe5e4..b80c994 100644
--- a/fuzzylite/fl/hedge/Very.h
+++ b/fuzzylite/fl/hedge/Very.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_VERY_H
@@ -29,14 +21,30 @@
namespace fl {
- class FL_API Very : public Hedge {
+ /**
+ The Very class is a Hedge located fourth in the ordered set
+ (Not, Seldom, Somewhat, Very, Extremely, Any).
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Hedge
+ @see HedgeFactory
+ @since 4.0
+ */
+ class FL_API Very FL_IFINAL : public Hedge {
public:
std::string name() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the hedge for the membership function value @f$x@f$
+ @param x is a membership function value
+ @return @f$x^2@f$
+ */
scalar hedge(scalar x) const FL_IOVERRIDE;
Very* clone() const FL_IOVERRIDE;
static Hedge* constructor();
};
-
}
#endif /* FL_VERY_H */
diff --git a/fuzzylite/fl/imex/CppExporter.h b/fuzzylite/fl/imex/CppExporter.h
index e53cf15..1c48225 100644
--- a/fuzzylite/fl/imex/CppExporter.h
+++ b/fuzzylite/fl/imex/CppExporter.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_CPPEXPORTER_H
@@ -36,30 +28,129 @@ namespace fl {
class Norm;
class Defuzzifier;
class Hedge;
-
+ class Activation;
+
+ /**
+ The CppExporter class is an Exporter that translates an Engine and its
+ components to the `C++` programming language using the `fuzzylite`
+ library.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see JavaExporter
+ @see Exporter
+ @since 4.0
+ */
class FL_API CppExporter : public Exporter {
- protected:
- bool _prefixNamespace;
- virtual std::string fl(const std::string& clazz) const;
+ private:
+ bool _usingNamespace;
+ bool _usingVariableNames;
public:
- explicit CppExporter(bool prefixNamespace = false);
+ explicit CppExporter(bool usingNamespace = false, bool usingVariableNames = true);
virtual ~CppExporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(CppExporter)
virtual std::string name() const FL_IOVERRIDE;
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
- virtual void setPrefixNamespace(bool prefixNamespace);
- virtual bool isPrefixNamespace() const;
-
+ /**
+ Sets whether the fl namespace of the library is prepended to types
+ (e.g., fl::Engine)
+
+ @param usingNamespace whether the fl namespace of the library is
+ prepended to types (e.g., fl::Engine)
+ */
+ virtual void setUsingNamespace(bool usingNamespace);
+ /**
+ Gets whether the fl namespace of the library is prepended to types
+ (e.g., fl::Engine)
+ @return whether the fl namespace of the library is prepended to types
+ */
+ virtual bool isUsingNamespace() const;
+
+ /**
+ Returns the given text prepended with the `fl` namespace if
+ CppExporter::isUsingNamespace is `true`, or the text otherwise
+
+ @param clazz is the text to be prepended the `fl::`.
+ @return the given text prepended with the `fl` namespace if
+ CppExporter::isUsingNamespace is `true`, or the text otherwise
+ */
+ virtual std::string fl(const std::string& clazz) const;
+ /**
+ Sets whether variables are exported using their names
+ (e.g., `power->setValue(fl::nan)`) instead of numbered identifiers
+ (e.g., `inputVariable1->setValue(fl::nan)`)
+ @param usingVariableNames indicates whether variables are exported using
+ their names
+ */
+ virtual void setUsingVariableNames(bool usingVariableNames);
+ /**
+ Gets whether variables are exported using their names
+ (e.g., `power->setValue(fl::nan)`) instead of numbered identifiers
+ (e.g., `inputVariable1->setValue(fl::nan)`)
+ @return whether variables are exported using their names
+ */
+ virtual bool isUsingVariableNames() const;
+
+ /**
+ Returns a string representation of InputVariable in the `C++` programming language
+ @param inputVariable is the input variable
+ @param engine is the engine in which the input variable is registered
+ @return a string representation of the input variable in the `C++` programming language
+ */
virtual std::string toString(const InputVariable* inputVariable, const Engine* engine) const;
+ /**
+ Returns a string representation of the OutputVariable in the `C++` programming language
+ @param outputVariable is the output variable
+ @param engine is the engine in which the output variable is registered
+ @return a string representation of the output variable in the `C++` programming language
+ */
virtual std::string toString(const OutputVariable* outputVariable, const Engine* engine) const;
+ /**
+ Returns a string representation of the RuleBlock in the `C++` programming language
+ @param ruleBlock is the rule block
+ @param engine is the engine in which the rule block is registered
+ @return a string representation of the rule block in the `C++` programming language
+ */
virtual std::string toString(const RuleBlock* ruleBlock, const Engine* engine) const;
+
+ /**
+ Returns a string representation of the Activation method in the `C++` programming language
+ @param activation is the activation method
+ @return a string representation of the activation method in the `C++` programming language
+ */
+ virtual std::string toString(const Activation* activation) const;
+
+ /**
+ Returns a string representation of the scalar value in the `C++` programming language
+ @param value is the scalar value
+ @return a string representation of the scalar value in the `C++` programming language
+ */
virtual std::string toString(scalar value) const;
+ /**
+ Returns a string representation of the Hedge in the `C++` programming language
+ @param hedge is the hedge
+ @return a string representation of the hedge in the `C++` programming language
+ */
virtual std::string toString(const Hedge* hedge) const;
+ /**
+ Returns a string representation of the Term in the `C++` programming language
+ @param term is the term
+ @return a string representation of the term in the `C++` programming language
+ */
virtual std::string toString(const Term* term) const;
- virtual std::string toString(const Norm* op) const;
+ /**
+ Returns a string representation of the Norm in the `C++` programming language
+ @param norm is the norm
+ @return a string representation of the norm in the `C++` programming language
+ */
+ virtual std::string toString(const Norm* norm) const;
+ /**
+ Returns a string representation of the Defuzzifier in the `C++` programming language
+ @param defuzzifier is the defuzzifier
+ @return a string representation of the defuzzifier in the `C++` programming language
+ */
virtual std::string toString(const Defuzzifier* defuzzifier) const;
virtual CppExporter* clone() const FL_IOVERRIDE;
diff --git a/fuzzylite/fl/imex/Exporter.h b/fuzzylite/fl/imex/Exporter.h
index 8b55c21..b883edf 100644
--- a/fuzzylite/fl/imex/Exporter.h
+++ b/fuzzylite/fl/imex/Exporter.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_EXPORTER_H
@@ -32,6 +24,16 @@
namespace fl {
class Engine;
+ /**
+ The Exporter class is the abstract class for exporters to translate an
+ Engine into different formats.
+
+ @todo declare methods for exporting other components (e.g., Variable)
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Importer
+ @since 4.0
+ */
class FL_API Exporter {
public:
@@ -39,10 +41,30 @@ namespace fl {
virtual ~Exporter();
FL_DEFAULT_COPY_AND_MOVE(Exporter)
+ /**
+ Returns a string representation of the engine
+ @param engine is the engine to export
+ @return a string representation of the engine
+ */
virtual std::string toString(const Engine* engine) const = 0;
+ /**
+ Stores the string representation of the engine into the specified file
+ @param path is the full path of the file to export the engine to
+ @param engine is the engine to export
+ @throws fl::Exception if the file cannot be created
+ */
virtual void toFile(const std::string& path, const Engine* engine) const;
+ /**
+ Returns the name of the exporter
+ @return the name of the exporter
+ */
virtual std::string name() const = 0;
+
+ /**
+ Creates a clone of the exporter
+ @return a clone of the exporter
+ */
virtual Exporter* clone() const = 0;
};
diff --git a/fuzzylite/fl/imex/FclExporter.h b/fuzzylite/fl/imex/FclExporter.h
index 9bfa3ed..efec3c4 100644
--- a/fuzzylite/fl/imex/FclExporter.h
+++ b/fuzzylite/fl/imex/FclExporter.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_FCLEXPORTER_H
@@ -37,8 +29,17 @@ namespace fl {
class Defuzzifier;
class Term;
+ /**
+ The FclExporter class is an Exporter that translates an Engine and its
+ components to the Fuzzy Control Language specification.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see FclImporter
+ @see Exporter
+ @since 4.0
+ */
class FL_API FclExporter : public Exporter {
- protected:
+ private:
std::string _indent;
public:
@@ -46,25 +47,59 @@ namespace fl {
virtual ~FclExporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FclExporter)
+ /**
+ Sets the indentation string within blocks
+ @param indent is the indentation string within blocks
+ */
virtual void setIndent(const std::string& indent);
+ /**
+ Gets the indentation string within blocks
+ @return the indentation string within blocks
+ */
virtual std::string getIndent() const;
virtual std::string name() const FL_IOVERRIDE;
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
-
+
+ /**
+ Returns a string representation of the InputVariable according to the Fuzzy Control Language specification
+ @param variable is the input variable
+ @return a string representation of the input variable according to the Fuzzy Control Language specification
+ */
virtual std::string toString(const InputVariable* variable) const;
+ /**
+ Returns a string representation of the OutputVariable according to the Fuzzy Control Language specification
+ @param variable is the output variable
+ @return a string representation of the output variable according to the Fuzzy Control Language specification
+ */
virtual std::string toString(const OutputVariable* variable) const;
+ /**
+ Returns a string representation of the RuleBlock according to the Fuzzy Control Language specification
+ @param ruleBlock is the rule block
+ @return a string representation of the rule block according to the Fuzzy Control Language specification
+ */
virtual std::string toString(const RuleBlock* ruleBlock) const;
-
+ /**
+ Returns a string representation of the Norm according to the Fuzzy Control Language specification
+ @param norm is the norm
+ @return a string representation of the norm according to the Fuzzy Control Language specification
+ */
virtual std::string toString(const Norm* norm) const;
-
- virtual std::string toString(const TNorm* tnorm) const; //TODO: Delete in v6.0
- virtual std::string toString(const SNorm* snorm) const; //TODO: Delete in v6.0
+ /**
+ Returns a string representation of the Defuzzifier according to the Fuzzy Control Language specification
+ @param defuzzifier is the defuzzifier
+ @return a string representation of the defuzzifier according to the Fuzzy Control Language specification
+ */
virtual std::string toString(const Defuzzifier* defuzzifier) const;
+ /**
+ Returns a string representation of the Term according to the Fuzzy Control Language specification
+ @param term is the term
+ @return a string representation of the term according to the Fuzzy Control Language specification
+ */
virtual std::string toString(const Term* term) const;
virtual FclExporter* clone() const FL_IOVERRIDE;
};
-
}
+
#endif /* FL_FCLEXPORTER_H */
diff --git a/fuzzylite/fl/imex/FclImporter.h b/fuzzylite/fl/imex/FclImporter.h
index b219717..2e75432 100644
--- a/fuzzylite/fl/imex/FclImporter.h
+++ b/fuzzylite/fl/imex/FclImporter.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_FCLIMPORTER_H
@@ -39,6 +31,15 @@ namespace fl {
class Term;
class Defuzzifier;
+ /**
+ The FclImporter class is an Importer that configures an Engine and its
+ components utilizing the Fuzzy Control Language specification.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see FclExporter
+ @see Importer
+ @since 4.0
+ */
class FL_API FclImporter : public Importer {
public:
FclImporter();
@@ -69,6 +70,5 @@ namespace fl {
virtual bool parseEnabled(const std::string& line) const;
};
-
}
#endif /* FL_FCLIMPORTER_H */
diff --git a/fuzzylite/fl/imex/FisExporter.h b/fuzzylite/fl/imex/FisExporter.h
index 05d6a22..a7f5d8c 100644
--- a/fuzzylite/fl/imex/FisExporter.h
+++ b/fuzzylite/fl/imex/FisExporter.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_FISEXPORTER_H
@@ -39,6 +31,15 @@ namespace fl {
class Proposition;
class Variable;
+ /**
+ The FisExporter class is an Exporter that translates an Engine and its
+ components into the Fuzzy Inference System format for Matlab or Octave.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see FisImporter
+ @see Exporter
+ @since 4.0
+ */
class FL_API FisExporter : public Exporter {
protected:
@@ -52,22 +53,68 @@ namespace fl {
virtual std::string name() const FL_IOVERRIDE;
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
-
- virtual std::string toString(const Norm* norm) const;
- virtual std::string toString(const TNorm* tnorm) const; //TODO: delete in v6.0
- virtual std::string toString(const SNorm* snorm) const; //TODO: delete in v6.0
+
+ /**
+ Returns a string representation of the TNorm in the Fuzzy Inference System format
+ @param tnorm is the TNorm
+ @return a string representation of the TNorm in the Fuzzy Inference System format
+ */
+ virtual std::string toString(const TNorm* tnorm) const;
+
+ /**
+ Returns a string representation of the SNorm in the Fuzzy Inference System format
+ @param snorm is the SNorm
+ @return a string representation of the SNorm in the Fuzzy Inference System format
+ */
+ virtual std::string toString(const SNorm* snorm) const;
+
+ /**
+ Returns a string representation of the Defuzzifier in the Fuzzy Inference System format
+ @param defuzzifier is the defuzzifier
+ @return a string representation of the Defuzzifier in the Fuzzy Inference System format
+ */
virtual std::string toString(const Defuzzifier* defuzzifier) const;
+ /**
+ Returns a string representation of the Term in the Fuzzy Inference System format
+ @param term is the term
+ @return a string representation of the term in the Fuzzy Inference System format
+ */
virtual std::string toString(const Term* term) const;
+ /**
+ Returns a string representation of the `[System]` configuration
+ @param engine is the engine
+ @return a string representation of the `[System]` configuration
+ */
virtual std::string exportSystem(const Engine* engine) const;
+ /**
+ Returns a string representation of the `[Input]` configuration
+ @param engine is the engine
+ @return a string representation of the `[Input]` configuration
+ */
virtual std::string exportInputs(const Engine* engine) const;
+ /**
+ Returns a string representation of the `[Output]` configuration
+ @param engine is the engine
+ @return a string representation of the `[Output]` configuration
+ */
virtual std::string exportOutputs(const Engine* engine) const;
+ /**
+ Returns a string representation of the `[Rules]` configuration
+ @param engine is the engine
+ @return a string representation of the `[Rules]` configuration
+ */
virtual std::string exportRules(const Engine* engine) const;
+ /**
+ Returns a string representation for the Rule in the Fuzzy Inference System format
+ @param rule is the rule
+ @param engine is the engine in which the rule is registered
+ @return a string representation for the rule in the Fuzzy Inference System format
+ */
virtual std::string exportRule(const Rule* rule, const Engine* engine) const;
virtual FisExporter* clone() const FL_IOVERRIDE;
};
-
}
#endif /* FL_FISEXPORTER_H */
diff --git a/fuzzylite/fl/imex/FisImporter.h b/fuzzylite/fl/imex/FisImporter.h
index b631a48..2c9ce36 100644
--- a/fuzzylite/fl/imex/FisImporter.h
+++ b/fuzzylite/fl/imex/FisImporter.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_FISIMPORTER_H
@@ -39,6 +31,16 @@ namespace fl {
class Defuzzifier;
class Variable;
+ /**
+ The FisImporter class is an Importer that configures an Engine and its
+ components from utilizing the Fuzzy Inference System format for Matlab or
+ Octave.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see FisExporter
+ @see Importer
+ @since 4.0
+ */
class FL_API FisImporter : public Importer {
public:
FisImporter();
@@ -60,20 +62,19 @@ namespace fl {
virtual void importOutput(const std::string& section, Engine* engine) const;
virtual void importRules(const std::string& section, Engine* engine) const;
virtual std::string translateProposition(scalar code, Variable* variable) const;
-
- //TODO: rename extract to translate in v6.0
- virtual std::string extractTNorm(const std::string& tnorm) const;
- virtual std::string extractSNorm(const std::string& tnorm) const;
- virtual std::string extractDefuzzifier(const std::string& defuzzifier) const;
+
+ virtual std::string translateTNorm(const std::string& tnorm) const;
+ virtual std::string translateSNorm(const std::string& tnorm) const;
+ virtual std::string translateDefuzzifier(const std::string& defuzzifier) const;
virtual Term* parseTerm(const std::string& line, const Engine* engine) const;
virtual Term* createInstance(const std::string& termClass, const std::string& name,
const std::vector<std::string>& params, const Engine* engine) const;
- //TODO: rename to parseRange in v6.0
- virtual std::pair<scalar, scalar> range(const std::string& range) const;
- };
+ virtual std::pair<scalar, scalar> parseRange(const std::string& range) const;
+ };
}
+
#endif /* FL_FISIMPORTER_H */
diff --git a/fuzzylite/fl/imex/FldExporter.h b/fuzzylite/fl/imex/FldExporter.h
index 71679a6..98a14c9 100644
--- a/fuzzylite/fl/imex/FldExporter.h
+++ b/fuzzylite/fl/imex/FldExporter.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_FLDEXPORTER_H
@@ -34,47 +26,219 @@ namespace fl {
class InputVariable;
class OutputVariable;
+ /**
+ The FldExporter class is an Exporter that evaluates an Engine and exports
+ its input values and output values to the FuzzyLite Dataset (FLD) format,
+ see [http://www.fuzzylite.com/fll-fld](http://www.fuzzylite.com/fll-fld)
+ for more information.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see FllExporter
+ @see Exporter
+ @since 4.0
+ */
class FL_API FldExporter : public Exporter {
- protected:
+ private:
std::string _separator;
bool _exportHeaders;
bool _exportInputValues;
bool _exportOutputValues;
public:
+
+ /**
+ The ScopeOfValues refers to the scope of the equally-distributed values
+ to generate.
+ */
+ enum ScopeOfValues {
+ /**Generates @f$n@f$ values for each variable*/
+ EachVariable,
+ /**Generates @f$n@f$ values for all variables*/
+ AllVariables
+ };
explicit FldExporter(const std::string& separator = " ");
virtual ~FldExporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FldExporter)
virtual std::string name() const FL_IOVERRIDE;
+ /**
+ Sets the separator of the dataset columns
+ @param separator is the separator of the dataset columns
+ */
virtual void setSeparator(const std::string& separator);
+ /**
+ Gets the separator of the dataset columns
+ @return the separator of the dataset columns
+ */
virtual std::string getSeparator() const;
+ /**
+ Sets whether the header of the dataset is to be exported
+ @param exportHeaders indicates whether the header of the dataset is
+ to be exported
+ */
virtual void setExportHeader(bool exportHeaders);
+ /**
+ Gets whether the header of the dataset is to be exported
+ @return whether the header of the dataset is to be exported
+ */
virtual bool exportsHeader() const;
+ /**
+ Sets whether the values of the input variables are to be exported
+ @param exportInputValues indicates whether the values of the input
+ variables are to be exported
+ */
virtual void setExportInputValues(bool exportInputValues);
+ /**
+ Gets whether the values of the input variables are to be exported
+ @return whether the values of the input variables are to be exported
+ */
virtual bool exportsInputValues() const;
+ /**
+ Sets whether the values of the output variables are to be exported
+ @param exportOutputValues indicates whether the values of the output
+ variables are to be exported
+ */
virtual void setExportOutputValues(bool exportOutputValues);
+ /**
+ Gets whether the values of the output variables are to be exported
+ @return whether the values of the output variables are to be exported
+ */
virtual bool exportsOutputValues() const;
+ /**
+ Gets the header of the dataset for the given engine
+ @param engine is the engine to be exported
+ @return the header of the dataset for the given engine
+ */
virtual std::string header(const Engine* engine) const;
- //WARNING: The engine will be const_casted in order to be processed!
+ /**
+ Returns a FuzzyLite Dataset from the engine. Please consider that the
+ engine will be `const_cast`ed to achieve so; that is, despite being
+ marked as `const`, the engine will be modified in order to compute
+ the output values based on the input values.
+ @param engine is the engine to export
+ @return a FuzzyLite Dataset from the engine
+ */
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
- virtual std::string toString(Engine* engine, int maximumNumberOfResults) const;
- virtual std::string toString(Engine* engine, const std::string& inputData) const;
+ /**
+ Returns a FuzzyLite Dataset from the engine.
+ @param engine is the engine to export
+ @param values is the number of values to export
+ @param scope indicates the scope of the values
+ @return a FuzzyLite Dataset from the engine
+ */
+ virtual std::string toString(Engine* engine, int values, ScopeOfValues scope = AllVariables) const;
+
+ /**
+ Returns a FuzzyLite Dataset from the engine.
+ @param engine is the engine to export
+ @param values is the number of values to export
+ @param scope indicates the scope of the values
+ @param activeVariables contains the input variables to generate values for.
+ The input variables must be in the same order as in the engine. A value of
+ fl::null indicates the variable is not active.
+ @return a FuzzyLite Dataset from the engine
+ */
+ virtual std::string toString(Engine* engine, int values, ScopeOfValues scope,
+ const std::vector<InputVariable*>& activeVariables) const;
+ /**
+ Returns a FuzzyLite Dataset from the engine.
+ @param engine is the engine to export
+ @param reader is the reader of a set of lines containing space-separated
+ input values
+ @return a FuzzyLite Dataset from the engine
+ */
+ virtual std::string toString(Engine* engine, std::istream& reader) const;
- using Exporter::toFile;
- virtual void toFile(const std::string& path, Engine* engine, int maximumNumberOfResults) const;
- virtual void toFile(const std::string& path, Engine* engine, const std::string& inputData) const;
-
- virtual std::vector<scalar> parse(const std::string& x) const;
- void write(Engine* engine, std::ostream& writer, int maximumNumberOfResults) const;
- void write(Engine* engine, std::ostream& writer, std::istream& reader) const;
- void write(Engine* engine, std::ostream& writer, const std::vector<scalar>& inputValues) const;
+ using Exporter::toFile;
+ /**
+ Saves the engine as a FuzzyLite Dataset into the specified file
+ @param path is the full path of the file
+ @param engine is the engine to export
+ @param values is the number of values to export
+ @param scope indicates the scope of the values
+ */
+ virtual void toFile(const std::string& path, Engine* engine,
+ int values, ScopeOfValues scope = AllVariables) const;
+ /**
+ Saves the engine as a FuzzyLite Dataset into the specified file
+ @param path is the full path of the file
+ @param engine is the engine to export
+ @param values is the number of values to export
+ @param scope indicates the scope of the values
+ @param activeVariables contains the input variables to generate values for.
+ The input variables must be in the same order as in the engine. A value of
+ fl::null indicates the variable is not active.
+ */
+ virtual void toFile(const std::string& path, Engine* engine,
+ int values, ScopeOfValues scope,
+ const std::vector<InputVariable*>& activeVariables) const;
+ /**
+ Saves the engine as a FuzzyLite Dataset into the specified file
+ @param path is the full path of the file
+ @param engine is the engine to export
+ @param reader is the reader of a set of lines containing space-separated input values
+ */
+ virtual void toFile(const std::string& path, Engine* engine, std::istream& reader) const;
+
+ /**
+ Parses the string into a vector of values unless the string starts with `#`
+ @param values is a space-separated set of values
+ @return a vector of values
+ */
+ virtual std::vector<scalar> parse(const std::string& values) const;
+
+ /**
+ Writes the engine into the given writer
+ @param engine is the engine to export
+ @param writer is the output where the engine will be written to
+ @param values is the number of values to export
+ @param scope indicates the scope of the values
+ */
+ virtual void write(Engine* engine, std::ostream& writer, int values,
+ ScopeOfValues scope = AllVariables) const;
+ /**
+ Writes the engine into the given writer
+ @param engine is the engine to export
+ @param writer is the output where the engine will be written to
+ @param values is the number of values to export
+ @param scope indicates the scope of the values
+ @param activeVariables contains the input variables to generate values for.
+ The input variables must be in the same order as in the engine. A value of
+ fl::null indicates the variable is not active.
+ */
+ virtual void write(Engine* engine, std::ostream& writer, int values, ScopeOfValues scope,
+ const std::vector<InputVariable*>& activeVariables) const;
+ /**
+ Writes the engine into the given writer
+ @param engine is the engine to export
+ @param writer is the output where the engine will be written to
+ @param reader is the reader of a set of lines containing space-separated input values
+ */
+ virtual void write(Engine* engine, std::ostream& writer, std::istream& reader) const;
+ /**
+ Writes the engine into the given writer
+ @param engine is the engine to export
+ @param writer is the output where the engine will be written to
+ @param inputValues is the vector of input values
+ */
+ virtual void write(Engine* engine, std::ostream& writer, const std::vector<scalar>& inputValues) const;
+ /**
+ Writes the engine into the given writer
+ @param engine is the engine to export
+ @param writer is the output where the engine will be written to
+ @param inputValues is the vector of input values
+ @param activeVariables contains the input variables to generate values for.
+ The input variables must be in the same order as in the engine. A value of
+ fl::null indicates the variable is not active.
+ */
+ virtual void write(Engine* engine, std::ostream& writer, const std::vector<scalar>& inputValues,
+ const std::vector<InputVariable*>& activeVariables) const;
virtual FldExporter* clone() const FL_IOVERRIDE;
};
diff --git a/fuzzylite/fl/imex/FllExporter.h b/fuzzylite/fl/imex/FllExporter.h
index e6a89f5..5a222e4 100644
--- a/fuzzylite/fl/imex/FllExporter.h
+++ b/fuzzylite/fl/imex/FllExporter.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_FLLEXPORTER_H
@@ -36,11 +28,23 @@ namespace fl {
class RuleBlock;
class Rule;
class Norm;
+ class Activation;
class Defuzzifier;
class Term;
+ /**
+ The FllExporter class is an Exporter that translates an Engine and its
+ components to the FuzzyLite Language (FLL), see
+ [http://www.fuzzylite.com/fll-fld](http://www.fuzzylite.com/fll-fld) for
+ more information.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see FllImporter
+ @see Exporter
+ @since 4.0
+ */
class FL_API FllExporter : public Exporter {
- protected:
+ private:
std::string _indent;
std::string _separator;
public:
@@ -50,33 +54,114 @@ namespace fl {
virtual std::string name() const FL_IOVERRIDE;
+ /**
+ Sets the indent string of the FuzzyLite Language
+ @param indent is the indent string of the FuzzyLite Language
+ */
virtual void setIndent(const std::string& indent);
+ /**
+ Gets the indent string of the FuzzyLite Language
+ @return the indent string of the FuzzyLite Language
+ */
virtual std::string getIndent() const;
+ /**
+ Gets the separator of the FuzzyLite Language
+ @param separator of the FuzzyLite Language
+ */
virtual void setSeparator(const std::string& separator);
+ /**
+ Gets the separator of the FuzzyLite Language
+ @return the separator of the FuzzyLite Language
+ */
virtual std::string getSeparator() const;
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
+ /**
+ Returns a string representation of the vector of variables in the FuzzyLite Language
+ @param variables is the vector of variables
+ @return a string representation of the vector of variables in the FuzzyLite Language
+ */
virtual std::string toString(const std::vector<Variable*>& variables) const;
+ /**
+ Returns a string representation of the vector of input variables in the FuzzyLite Language
+ @param inputVariables is the vector of input variables
+ @return a string representation of the vector of input variables in the FuzzyLite Language
+ */
virtual std::string toString(const std::vector<InputVariable*>& inputVariables) const;
+ /**
+ Returns a string representation of the vector of output variables in the FuzzyLite Language
+ @param outputVariables is a vector of output variables
+ @return a string representation of the vector of output variables in the FuzzyLite Language
+ */
virtual std::string toString(const std::vector<OutputVariable*>& outputVariables) const;
+ /**
+ Returns a string representation of the vector of rule blocks in the FuzzyLite Language
+ @param ruleBlocks is the vector of rule blocks
+ @return a string representation of the vector of rule blocks in the FuzzyLite Language
+ */
virtual std::string toString(const std::vector<RuleBlock*>& ruleBlocks) const;
+ /**
+ Returns a string representation of the Variable in the FuzzyLite Language
+ @param variable is the variable
+ @return a string representation of the variable in the FuzzyLite Language
+ */
virtual std::string toString(const Variable* variable) const;
+ /**
+ Returns a string representation of the InputVariable in the FuzzyLite Language
+ @param inputVariable is the input variable to export
+ @return a string representation of the input variable in the FuzzyLite Language
+ */
virtual std::string toString(const InputVariable* inputVariable) const;
+ /**
+ Returns a string representation of the OutputVariable in the FuzzyLite Language
+ @param outputVariable is the output variable
+ @return a string representation of the output variable in the FuzzyLite Language
+ */
virtual std::string toString(const OutputVariable* outputVariable) const;
+ /**
+ Returns a string representation of the RuleBlock in the FuzzyLite Language
+ @param ruleBlock is the rule block
+ @return a string representation of the rule block in the FuzzyLite Language
+ */
virtual std::string toString(const RuleBlock* ruleBlock) const;
+ /**
+ Returns a string representation of the Rule in the FuzzyLite Language
+ @param rule is the rule
+ @return a string representation of the rule in the FuzzyLite Language
+ */
virtual std::string toString(const Rule* rule) const;
+ /**
+ Returns a string representation of the Norm in the FuzzyLite Language
+ @param norm is the norm
+ @return a string representation of the norm in the FuzzyLite Language
+ */
virtual std::string toString(const Norm* norm) const;
+ /**
+ Returns a string representation of the Activation method in the FuzzyLite Language
+ @param activation is the activation method
+ @return a string representation of the activation method in the FuzzyLite Language
+ */
+ virtual std::string toString(const Activation* activation) const;
+ /**
+ Returns a string representation of the Defuzzifier in the FuzzyLite Language
+ @param defuzzifier is the defuzzifier
+ @return a string representation of the defuzzifier in the FuzzyLite Language
+ */
virtual std::string toString(const Defuzzifier* defuzzifier) const;
+ /**
+ Returns a string representation of the Term in the FuzzyLite Language
+ @param term is the term
+ @return a string representation of the term in the FuzzyLite Language
+ */
virtual std::string toString(const Term* term) const;
virtual FllExporter* clone() const FL_IOVERRIDE;
};
-
}
#endif /* FL_FLLEXPORTER_H */
diff --git a/fuzzylite/fl/imex/FllImporter.h b/fuzzylite/fl/imex/FllImporter.h
index 5be41c7..055bb88 100644
--- a/fuzzylite/fl/imex/FllImporter.h
+++ b/fuzzylite/fl/imex/FllImporter.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_FLLIMPORTER_H
@@ -32,18 +24,39 @@
namespace fl {
class TNorm;
class SNorm;
+ class Activation;
class Term;
class Defuzzifier;
+ /**
+ The FllImporter class is an Importer that configures an Engine and its
+ components utilizing the FuzzyLite Language (FLL), see
+ [http://www.fuzzylite.com/fll-fld](http://www.fuzzylite.com/fll-fld) for
+ more information.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see FllExporter
+ @see Importer
+ @since 4.0
+ @todo parse methods returning respective instances from blocks of text
+ */
class FL_API FllImporter : public Importer {
- protected:
+ private:
std::string _separator;
public:
explicit FllImporter(const std::string& separator = "\n");
virtual ~FllImporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FllImporter)
+ /**
+ Sets the separator of the language (default separator is a new line '\n')
+ @param separator is the separator of the language
+ */
virtual void setSeparator(const std::string& separator);
+ /**
+ Gets the separator of the language (default separator is a new line '\n')
+ @return the separator of the language
+ */
virtual std::string getSeparator() const;
virtual std::string name() const FL_IOVERRIDE;
@@ -52,6 +65,7 @@ namespace fl {
virtual FllImporter* clone() const FL_IOVERRIDE;
protected:
+
virtual void process(const std::string& tag, const std::string& block, Engine* engine) const;
virtual void processInputVariable(const std::string& block, Engine* engine) const;
virtual void processOutputVariable(const std::string& block, Engine* engine) const;
@@ -59,6 +73,7 @@ namespace fl {
virtual TNorm* parseTNorm(const std::string& name) const;
virtual SNorm* parseSNorm(const std::string& name) const;
+ virtual Activation* parseActivation(const std::string& name) const;
virtual Term* parseTerm(const std::string& text, Engine* engine) const;
@@ -68,7 +83,6 @@ namespace fl {
virtual std::pair<std::string, std::string> parseKeyValue(const std::string& text,
char separator = ':') const;
- virtual std::string clean(const std::string& line) const;
};
}
diff --git a/fuzzylite/fl/imex/Importer.h b/fuzzylite/fl/imex/Importer.h
index 28d2b36..1250e66 100644
--- a/fuzzylite/fl/imex/Importer.h
+++ b/fuzzylite/fl/imex/Importer.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_IMPORTER_H
@@ -32,6 +24,16 @@
namespace fl {
class Engine;
+ /**
+ The Importer class is the abstract class for importers to configure an
+ Engine and its components from different text formats.
+
+ @todo declare methods to import specific components
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Exporter
+ @since 4.0
+ */
class FL_API Importer {
public:
@@ -39,13 +41,30 @@ namespace fl {
virtual ~Importer();
FL_DEFAULT_COPY_AND_MOVE(Importer)
- virtual Engine* fromString(const std::string& s) const = 0;
+ /**
+ Imports the engine from the given text
+ @param text is the string representation of the engine to import from
+ @return the engine represented by the text
+ */
+ virtual Engine* fromString(const std::string& text) const = 0;
+ /**
+ Imports the engine from the given file
+ @param path is the full path of the file containing the engine to import from
+ @return the engine represented by the file
+ */
virtual Engine* fromFile(const std::string& path) const;
+ /**
+ Returns the name of the importer
+ @return the name of the importer
+ */
virtual std::string name() const = 0;
+ /**
+ Creates a clone of the importer
+ @return a clone of the importer
+ */
virtual Importer* clone() const = 0;
};
-
}
#endif /* IMPORTER_H */
diff --git a/fuzzylite/fl/imex/JavaExporter.h b/fuzzylite/fl/imex/JavaExporter.h
index e882d4a..a1817f6 100644
--- a/fuzzylite/fl/imex/JavaExporter.h
+++ b/fuzzylite/fl/imex/JavaExporter.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_JAVAEXPORTER_H
@@ -38,30 +30,122 @@ namespace fl {
class Norm;
class SNorm;
class TNorm;
-
+ class Activation;
+
+ /**
+ The JavaExporter class is an Exporter that translates an Engine and its
+ components to the `Java` programming language using the `jfuzzylite`
+ library.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see CppExporter
+ @see Exporter
+ @since 4.0
+ */
class FL_API JavaExporter : public Exporter {
+ private:
+ bool _usingVariableNames;
public:
- JavaExporter();
+ explicit JavaExporter(bool usingVariableNames = true);
virtual ~JavaExporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(JavaExporter)
virtual std::string name() const FL_IOVERRIDE;
+ /**
+ Sets whether variables are exported using their names
+ (e.g., `power.setValue(Double.NaN)`) instead of numbered identifiers
+ (e.g., `inputVariable1.setValue(Double.NaN)`)
+ @param usingVariableNames indicates whether variables are exported using
+ their names
+ */
+ virtual void setUsingVariableNames(bool usingVariableNames);
+
+ /**
+ Gets whether variables are exported using their names
+ (e.g., `power.setValue(Double.NaN)`) instead of numbered identifiers
+ (e.g., `inputVariable1.setValue(Double.NaN)`)
+ @return whether variables are exported using their names
+ */
+ virtual bool isUsingVariableNames() const;
+
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
+ /**
+ Returns a string representation of the InputVariable in the Java
+ programming language
+ @param inputVariable is the input variable
+ @param engine is the engine in which the input variable is registered
+ @return a string representation of the input variable in the Java
+ programming language
+ */
virtual std::string toString(const InputVariable* inputVariable, const Engine* engine) const;
+ /**
+ Returns a string representation of the OutputVariable in the Java
+ programming language
+ @param outputVariable is the output variable
+ @param engine is the engine in which the output variable is registered
+ @return a string representation of the output variable in the Java
+ programming language
+ */
virtual std::string toString(const OutputVariable* outputVariable, const Engine* engine) const;
+ /**
+ Returns a string representation of the RuleBlock in the Java
+ programming language
+ @param ruleBlock is the rule block
+ @param engine is the engine in which the rule block is registered
+ @return a string representation of the rule block in the Java
+ programming language
+ */
virtual std::string toString(const RuleBlock* ruleBlock, const Engine* engine) const;
+
+ /**
+ Returns a string representation of the Term in the Java programming
+ language
+ @param term is the term
+ @return a string representation of the term in the Java programming
+ language
+ */
virtual std::string toString(const Term* term) const;
+
+ /**
+ Returns a string representation of the Activation method in the Java
+ programming language
+ @param activation is the activation method
+ @return a string representation of the activation method in the Java
+ programming language
+ */
+ virtual std::string toString(const Activation* activation) const;
+
+ /**
+ Returns a string representation of the Defuzzifier in the Java
+ programming language
+ @param defuzzifier is the defuzzifier
+ @return a string representation of the defuzzifier in the Java
+ programming language
+ */
virtual std::string toString(const Defuzzifier* defuzzifier) const;
+
+ /**
+ Returns a string representation of the Norm in the Java programming
+ language
+ @param norm is the norm
+ @return a string representation of the norm in the Java programming
+ language
+ */
virtual std::string toString(const Norm* norm) const;
- virtual std::string toString(const SNorm* norm) const;//TODO: delete in v6.0
- virtual std::string toString(const TNorm* norm) const;//TODO: delete in v6.0
+
+ /**
+ Returns a string representation of the scalar value in the Java
+ programming language
+ @param value is the scalar value
+ @return a string representation of the scalar value in the Java
+ programming language
+ */
virtual std::string toString(scalar value) const;
virtual JavaExporter* clone() const FL_IOVERRIDE;
};
-
}
#endif /* FL_JAVAEXPORTER_H */
diff --git a/fuzzylite/fl/imex/RScriptExporter.h b/fuzzylite/fl/imex/RScriptExporter.h
new file mode 100644
index 0000000..c53c751
--- /dev/null
+++ b/fuzzylite/fl/imex/RScriptExporter.h
@@ -0,0 +1,246 @@
+/*
+ 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_RSCRIPTEXPORTER_H
+#define FL_RSCRIPTEXPORTER_H
+
+#include "fl/imex/Exporter.h"
+#include "fl/imex/FldExporter.h"
+
+#include <vector>
+
+namespace fl {
+ class Engine;
+ class InputVariable;
+ class OutputVariable;
+
+ /**
+ The RScriptExporter class is an Exporter that creates an R script to plot one or
+ more surfaces of an engine for two input variables and any number of output
+ variables.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see FldExporter
+ @see Exporter
+ @since 6.0
+ */
+ class FL_API RScriptExporter : public Exporter {
+ private:
+ std::string _minimumColor;
+ std::string _maximumColor;
+ std::string _contourColor;
+
+ public:
+ RScriptExporter();
+ virtual ~RScriptExporter() FL_IOVERRIDE;
+ FL_DEFAULT_COPY_AND_MOVE(RScriptExporter)
+
+ virtual std::string name() const FL_IOVERRIDE;
+
+ /**
+ Sets the color to represent the minimum values.
+ @param minimumColor is the color to represent the minimum values
+ */
+ void setMinimumColor(const std::string& minimumColor);
+ /**
+ Gets the color to represent the minimum values.
+ @return the color to represent the minimum values
+ */
+ std::string getMinimumColor() const;
+
+ /**
+ Sets the color to represent the maximum values.
+ @param maximumColor is the color to represent the maximum values
+ */
+ void setMaximumColor(const std::string& maximumColor);
+ /**
+ Gets the color to represent the maximum values.
+ @return maximumColor is the color to represent the maximum values
+ */
+ std::string getMaximumColor() const;
+
+ /**
+ Sets the color to draw the contour lines
+ @param contourColor is the color to draw the contour lines
+ */
+ void setContourColor(const std::string& contourColor);
+ /**
+ Gets the color to draw the contour lines
+ @return the color to draw the contour lines
+ */
+ std::string getContourColor() const;
+
+ /**
+ Returns an R script plotting multiple surfaces based on a data frame
+ generated with 1024 values in the scope of FldExporter::AllVariables
+ for the first two input variables.
+ @param engine is the engine to export
+ @return an R script plotting multiple surfaces for the first two input
+ variables in the engine.
+ */
+ virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
+
+ /**
+ Returns an R script plotting multiple surfaces based on a data frame
+ generated with the given number of values and scope for the two input
+ variables.
+ @param engine is the engine to export
+ @param a is the first input variable
+ @param b is the second input variable
+ @param values is the number of values to evaluate the engine
+ @param scope is the scope of the number of values to evaluate the engine
+ @param outputVariables are the output variables to create the surface for
+ @return an R script plotting multiple surfaces for the two input
+ variables on the output variables.
+ */
+ virtual std::string toString(Engine* engine, InputVariable* a, InputVariable* b,
+ int values, FldExporter::ScopeOfValues scope,
+ const std::vector<OutputVariable*>& outputVariables) const;
+
+ /**
+ Returns an R script plotting multiple surfaces based on the input stream
+ of values for the two input variables.
+ @param engine is the engine to export
+ @param a is the first input variable
+ @param b is the second input variable
+ @param reader is an input stream of data whose lines contain space-separated
+ input values
+ @param outputVariables are the output variables to create the surface for
+ @return an R script plotting multiple surfaces for the two input
+ variables on the output variables
+ */
+ virtual std::string toString(Engine* engine, InputVariable* a, InputVariable* b,
+ std::istream& reader, const std::vector<OutputVariable*>& outputVariables) const;
+
+ /**
+ Creates an R script file plotting multiple surfaces based on a data frame
+ generated with 1024 values in the scope of FldExporter::AllVariables
+ for the two input variables
+ @param filePath is the full path of the R script file
+ @param engine is the engine to export
+ */
+ virtual void toFile(const std::string& filePath, const Engine* engine) const FL_IOVERRIDE;
+
+ /**
+ Creates an R script file plotting multiple surfaces based on a data frame
+ generated with the given number of values and scope for the two input
+ variables
+ @param filePath is the full path of the R script file
+ @param engine is the engine to export
+ @param a is the first input variable
+ @param b is the second input variable
+ @param values is the number of values to evaluate the engine
+ @param scope is the scope of the number of values to evaluate the engine
+ @param outputVariables are the output variables to create the surface for
+ */
+ virtual void toFile(const std::string& filePath, Engine* engine,
+ InputVariable* a, InputVariable* b,
+ int values, FldExporter::ScopeOfValues scope,
+ const std::vector<OutputVariable*>& outputVariables) const;
+
+ /**
+ Creates an R script file plotting multiple surfaces based on the input stream
+ of values for the two input variables.
+ @param filePath is the full path of the R script file
+ @param engine is the engine to export
+ @param a is the first input variable
+ @param b is the second input variable
+ @param reader is an input stream of data whose lines contain space-separated
+ input values
+ @param outputVariables are the output variables to create the surface for
+ */
+ virtual void toFile(const std::string& filePath, Engine* engine,
+ InputVariable* a, InputVariable* b, std::istream& reader,
+ const std::vector<OutputVariable*>& outputVariables) const;
+
+
+ /**
+ Writes an R script plotting multiple surfaces based on a manually
+ imported data frame containing the data for the two input variables
+ on the output variables.
+ @param engine is the engine to export
+ @param writer is the output where the engine will be written to
+ @param a is the first input variable
+ @param b is the second input variable
+ @param dataFramePath is the path where the data frame should be located
+ (the path will not be accessed, it will only be written to script)
+ @param outputVariables are the output variables to create the surface for
+ */
+ virtual void writeScriptImportingDataFrame(const Engine* engine, std::ostream& writer,
+ InputVariable* a, InputVariable* b, const std::string& dataFramePath,
+ const std::vector<OutputVariable*>& outputVariables) const;
+
+ /**
+ Writes an R script plotting multiple surfaces based on a data frame
+ generated with the given number of values and scope for the two input
+ variables on the output variables.
+ @param engine is the engine to export
+ @param writer is the output where the engine will be written to
+ @param a is the first input variable
+ @param b is the second input variable
+ @param values is the number of values to evaluate the engine
+ @param scope is the scope of the number of values to evaluate the engine
+ @param outputVariables are the output variables to create the surface for
+ */
+ virtual void writeScriptExportingDataFrame(Engine* engine, std::ostream& writer,
+ InputVariable* a, InputVariable* b, int values, FldExporter::ScopeOfValues scope,
+ const std::vector<OutputVariable*>& outputVariables) const;
+
+ /**
+ Writes an R script plotting multiple surfaces based on a data frame
+ generated with the given number of values and scope for the two input
+ variables on the output variables.
+ @param engine is the engine to export
+ @param writer is the output where the engine will be written to
+ @param a is the first input variable
+ @param b is the second input variable
+ @param reader is an input stream of data whose lines contain space-separated
+ input values
+ @param outputVariables are the output variables to create the surface for
+ */
+ virtual void writeScriptExportingDataFrame(Engine* engine, std::ostream& writer,
+ InputVariable* a, InputVariable* b, std::istream& reader,
+ const std::vector<OutputVariable*>& outputVariables) const;
+
+ protected:
+ /**
+ Writes the header of the R script (e.g., import libraries)
+ @param writer is the output where the header will be written to
+ @param engine is the engine to export
+ */
+ virtual void writeScriptHeader(std::ostream& writer, const Engine* engine) const;
+
+ /**
+ Writes the code to generate the surface plots for the input variables
+ on the output variables.
+ @param writer is the output where the engine will be written to
+ @param a is the first input variable
+ @param b is the second input variable
+ @param outputVariables are the output variables to create the surface for
+ */
+ virtual void writeScriptPlots(std::ostream& writer,
+ InputVariable* a, InputVariable* b,
+ const std::vector<OutputVariable*>& outputVariables) const;
+
+
+ virtual RScriptExporter* clone() const FL_IOVERRIDE;
+
+ };
+
+}
+
+#endif /* FL_RSCRIPTEXPORTER_H */
+
diff --git a/fuzzylite/fl/norm/Norm.h b/fuzzylite/fl/norm/Norm.h
index 5f1b578..682d2ad 100644
--- a/fuzzylite/fl/norm/Norm.h
+++ b/fuzzylite/fl/norm/Norm.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_NORM_H
@@ -27,12 +19,22 @@
#include "fl/fuzzylite.h"
-#include "fl/Operation.h"
+#include "fl/Complexity.h"
#include <string>
namespace fl {
+ /**
+ The Norm class is the abstract class for norms.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see TNorm
+ @see SNorm
+ @see TNormFactory
+ @see SNormFactory
+ @since 4.0
+ */
class FL_API Norm {
public:
@@ -43,13 +45,31 @@ namespace fl {
}
FL_DEFAULT_COPY_AND_MOVE(Norm)
-
+ /**
+ Returns the name of the class of the norm
+ @return the name of the class of the norm
+ */
virtual std::string className() const = 0;
+
+ /**
+ Computes the estimated complexity of computing the hedge
+ @return the complexity of computing the hedge
+ */
+ virtual Complexity complexity() const = 0;
+ /**
+ Computes the norm for @f$a@f$ and @f$b@f$
+ @param a is a membership function value
+ @param b is a membership function value
+ @return the norm between @f$a@f$ and @f$b@f$
+ */
virtual scalar compute(scalar a, scalar b) const = 0;
+ /**
+ Creates a clone of the norm
+ @return a clone of the norm
+ */
virtual Norm* clone() const = 0;
};
}
#endif /* FL_NORM_H */
-
diff --git a/fuzzylite/fl/norm/SNorm.h b/fuzzylite/fl/norm/SNorm.h
index a281f52..a68081c 100644
--- a/fuzzylite/fl/norm/SNorm.h
+++ b/fuzzylite/fl/norm/SNorm.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_SNORM_H
@@ -29,6 +21,19 @@
namespace fl {
+ /**
+ The SNorm class is the base class for all S-Norms, and it is utilized as
+ the disjunction fuzzy logic operator and as the aggregation (or
+ `accumulation` in versions 5.0 and earlier) fuzzy logic operator.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see RuleBlock::getDisjunction()
+ @see OutputVariable::fuzzyOutput()
+ @see Aggregated::getAggregation()
+ @see SNormFactory
+ @see Norm
+ @since 4.0
+ */
class FL_API SNorm : public Norm {
public:
@@ -44,4 +49,3 @@ namespace fl {
};
}
#endif /* FL_SNORM_H */
-
diff --git a/fuzzylite/fl/norm/TNorm.h b/fuzzylite/fl/norm/TNorm.h
index 8ba8538..b1f7cb7 100644
--- a/fuzzylite/fl/norm/TNorm.h
+++ b/fuzzylite/fl/norm/TNorm.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_TNORM_H
@@ -29,6 +21,18 @@
namespace fl {
+ /**
+ The TNorm class is the base class for T-Norms, and it is utilized as the
+ conjunction fuzzy logic operator and as the implication (or `activation`
+ in versions 5.0 and earlier) fuzzy logic operator.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see RuleBlock::getConjunction()
+ @see RuleBlock::getImplication()
+ @see TNormFactory
+ @see Norm
+ @since 4.0
+ */
class FL_API TNorm : public Norm {
public:
@@ -44,4 +48,3 @@ namespace fl {
};
}
#endif /* TNORM_H */
-
diff --git a/fuzzylite/fl/norm/s/AlgebraicSum.h b/fuzzylite/fl/norm/s/AlgebraicSum.h
index 786bcbd..2fbf4c1 100644
--- a/fuzzylite/fl/norm/s/AlgebraicSum.h
+++ b/fuzzylite/fl/norm/s/AlgebraicSum.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_ALGEBRAICSUM_H
@@ -27,20 +19,35 @@
#include "fl/norm/SNorm.h"
-
namespace fl {
- class FL_API AlgebraicSum : public SNorm {
+ /**
+ The AlgebraicSum class is an SNorm that computes the algebraic sum of
+ values any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see AlgebraicProduct
+ @see SNorm
+ @see SNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API AlgebraicSum FL_IFINAL : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the algebraic sum of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$a+b-(a \times b)@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
AlgebraicSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
-
-
}
-
#endif /* FL_ALGEBRAICSUM_H */
-
diff --git a/fuzzylite/fl/norm/s/BoundedSum.h b/fuzzylite/fl/norm/s/BoundedSum.h
index 5231856..cd9438e 100644
--- a/fuzzylite/fl/norm/s/BoundedSum.h
+++ b/fuzzylite/fl/norm/s/BoundedSum.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_BOUNDEDSUM_H
@@ -29,15 +21,34 @@
namespace fl {
- class FL_API BoundedSum : public SNorm {
+ /**
+ The BoundedSum class is an SNorm that computes the bounded sum of any two
+ values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see BoundedDifference
+ @see SNorm
+ @see SNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API BoundedSum FL_IFINAL : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the bounded sum of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$\min(1, a+b)@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
BoundedSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
+
}
#endif /* FL_BOUNDEDSUM_H */
-
diff --git a/fuzzylite/fl/norm/s/DrasticSum.h b/fuzzylite/fl/norm/s/DrasticSum.h
index 65d4d4c..a1e33fe 100644
--- a/fuzzylite/fl/norm/s/DrasticSum.h
+++ b/fuzzylite/fl/norm/s/DrasticSum.h
@@ -1,43 +1,55 @@
/*
- 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_DRASTICSUM_H
#define FL_DRASTICSUM_H
#include "fl/norm/SNorm.h"
+
namespace fl {
- class FL_API DrasticSum : public SNorm {
+ /**
+ The DrasticSum class is an SNorm that computes the drastic sum of any two
+ values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see DrasticProduct
+ @see SNorm
+ @see SNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API DrasticSum FL_IFINAL : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the drastic sum of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$\begin{cases}
+ \max(a,b) & \mbox{if $\min(a,b)=0$} \cr
+ 1 & \mbox{otherwise}
+ \end{cases}@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
DrasticSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
-
}
-
#endif /* FL_DRASTICSUM_H */
-
diff --git a/fuzzylite/fl/norm/s/EinsteinSum.h b/fuzzylite/fl/norm/s/EinsteinSum.h
index 8114c68..7450330 100644
--- a/fuzzylite/fl/norm/s/EinsteinSum.h
+++ b/fuzzylite/fl/norm/s/EinsteinSum.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_EINSTEINSUM_H
@@ -29,16 +21,32 @@
namespace fl {
- class FL_API EinsteinSum : public SNorm {
+ /**
+ The EinsteinSum class is an SNorm that computes the einstein sum of any
+ two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see EinsteinProduct
+ @see SNorm
+ @see SNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API EinsteinSum FL_IFINAL : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the Einstein sum of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$a+b/(1+a \times b)@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
EinsteinSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
-
}
-
#endif /* FL_EINSTEINSUM_H */
-
diff --git a/fuzzylite/fl/norm/s/HamacherSum.h b/fuzzylite/fl/norm/s/HamacherSum.h
index 3daf852..0242512 100644
--- a/fuzzylite/fl/norm/s/HamacherSum.h
+++ b/fuzzylite/fl/norm/s/HamacherSum.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_HAMACHERSUM_H
@@ -29,16 +21,32 @@
namespace fl {
- class FL_API HamacherSum : public SNorm {
+ /**
+ The HamacherSum class is an SNorm that computes the Hamacher sum of any
+ two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see HamacherProduct
+ @see SNorm
+ @see SNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API HamacherSum FL_IFINAL : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the Hamacher sum of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$a+b-(2\times a \times b)/(1-a\times b)@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
HamacherSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
-
}
-
#endif /* FL_HAMACHERSUM_H */
-
diff --git a/fuzzylite/fl/norm/s/Maximum.h b/fuzzylite/fl/norm/s/Maximum.h
index 28a3b6d..c8ce488 100644
--- a/fuzzylite/fl/norm/s/Maximum.h
+++ b/fuzzylite/fl/norm/s/Maximum.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_MAXIMUM_H
@@ -29,17 +21,31 @@
namespace fl {
- class FL_API Maximum : public SNorm {
+ /**
+ The Maximum class is an SNorm that computes the maximum of any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Minimum
+ @see SNorm
+ @see SNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API Maximum FL_IFINAL : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the maximum of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$\max(a,b)@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
Maximum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
-
-
}
-
#endif /* FL_MAXIMUM_H */
-
diff --git a/fuzzylite/fl/norm/s/NilpotentMaximum.h b/fuzzylite/fl/norm/s/NilpotentMaximum.h
index 151d92d..13e9793 100644
--- a/fuzzylite/fl/norm/s/NilpotentMaximum.h
+++ b/fuzzylite/fl/norm/s/NilpotentMaximum.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_NILPOTENTMAXIMUM_H
@@ -29,9 +21,31 @@
namespace fl {
- class FL_API NilpotentMaximum : public SNorm {
+ /**
+ The NilpotentMaximum class is an SNorm that computes the nilpotent
+ maximum of any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see NilpotentMinimum
+ @see SNorm
+ @see SNormFactory
+ @see Norm
+ @since 5.0
+ */
+ class FL_API NilpotentMaximum FL_IFINAL : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the nilpotent maximum of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$\begin{cases}
+ \max(a,b) & \mbox{if $a+b<0$} \cr
+ 1 & \mbox{otherwise}
+ \end{cases}@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
NilpotentMaximum* clone() const FL_IOVERRIDE;
@@ -40,4 +54,3 @@ namespace fl {
}
#endif /* FL_NILPOTENTMAXIMUM_H */
-
diff --git a/fuzzylite/fl/norm/s/NormalizedSum.h b/fuzzylite/fl/norm/s/NormalizedSum.h
index 59063a6..e2e757b 100644
--- a/fuzzylite/fl/norm/s/NormalizedSum.h
+++ b/fuzzylite/fl/norm/s/NormalizedSum.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_NORMALIZEDSUM_H
@@ -29,16 +21,32 @@
namespace fl {
- class FL_API NormalizedSum : public SNorm {
+ /**
+ The NormalizedSum class is an SNorm that computes the normalized sum of
+ any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see SNorm
+ @see SNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API NormalizedSum FL_IFINAL : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the normalized sum of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$(a+b)/\max(1, a + b)@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
NormalizedSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
-
}
#endif /* FL_NORMALIZEDSUM_H */
-
diff --git a/fuzzylite/fl/norm/s/SNormFunction.h b/fuzzylite/fl/norm/s/SNormFunction.h
new file mode 100644
index 0000000..a78b1aa
--- /dev/null
+++ b/fuzzylite/fl/norm/s/SNormFunction.h
@@ -0,0 +1,81 @@
+/*
+ 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_SNORMFUNCTION_H
+#define FL_SNORMFUNCTION_H
+
+#include "fl/norm/SNorm.h"
+
+#include "fl/term/Function.h"
+
+namespace fl {
+
+ /**
+ The SNormFunction class is a customizable SNorm via Function, which
+ computes any function based on the @f$a@f$ and @f$b@f$ values.
+ This SNorm is not registered with the SNormFactory.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Function
+ @see SNorm
+ @see Norm
+ @see SNormFactory
+ @since 6.0
+ */
+
+ class FL_API SNormFunction FL_IFINAL : public SNorm {
+ private:
+ Function _function;
+ public:
+ explicit SNormFunction(const std::string& formula = "");
+
+ /**
+ Returns the reference to the Function
+ @return the reference to the Function
+ */
+ Function& function();
+
+ /**
+ Loads the function with the given formula
+ @param formula is a valid formula in infix notation
+ */
+ void setFormula(const std::string& formula);
+ /**
+ Returns the formula loaded into the function
+ @return the formula loaded into the function
+ */
+ std::string getFormula() const;
+
+ std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the S-Norm utilizing the given function via
+ SNormFunction::setFormula(), which automatically assigns the values
+ of @f$a@f$ and @f$b@f$.
+
+ @param a is a membership function value
+ @param b is a membership function value
+ @return the evaluation of the function
+ */
+ scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
+ SNormFunction* clone() const FL_IOVERRIDE;
+
+ static SNorm* constructor();
+ };
+}
+#endif /* FL_SNORMFUNCTION_H */
+
diff --git a/fuzzylite/fl/norm/s/UnboundedSum.h b/fuzzylite/fl/norm/s/UnboundedSum.h
new file mode 100644
index 0000000..695fdfd
--- /dev/null
+++ b/fuzzylite/fl/norm/s/UnboundedSum.h
@@ -0,0 +1,52 @@
+/*
+ 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_UNBOUNDEDSUM_H
+#define FL_UNBOUNDEDSUM_H
+
+#include "fl/norm/SNorm.h"
+
+namespace fl {
+
+ /**
+ The UnboundedSum class is an SNorm that computes the sum of any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see BoundedSum
+ @see SNorm
+ @see SNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API UnboundedSum FL_IFINAL : public SNorm {
+ public:
+ std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the bounded sum of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$\min(1, a+b)@f$
+ */
+ scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
+ UnboundedSum* clone() const FL_IOVERRIDE;
+
+ static SNorm* constructor();
+ };
+}
+
+#endif /* FL_BOUNDEDSUM_H */
diff --git a/fuzzylite/fl/norm/t/AlgebraicProduct.h b/fuzzylite/fl/norm/t/AlgebraicProduct.h
index e4b0865..d19cb64 100644
--- a/fuzzylite/fl/norm/t/AlgebraicProduct.h
+++ b/fuzzylite/fl/norm/t/AlgebraicProduct.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_ALGEBRAICPRODUCT_H
@@ -29,17 +21,32 @@
namespace fl {
- class FL_API AlgebraicProduct : public TNorm {
+ /**
+ The AlgebraicProduct class is a TNorm that computes the algebraic product
+ of any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see AlgebraicSum
+ @see TNorm
+ @see TNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API AlgebraicProduct FL_IFINAL : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the algebraic product of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$a\times b@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
AlgebraicProduct* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
-
-
}
-
#endif /* FL_ALGEBRAICPRODUCT_H */
-
diff --git a/fuzzylite/fl/norm/t/BoundedDifference.h b/fuzzylite/fl/norm/t/BoundedDifference.h
index 3dc9d3a..250512b 100644
--- a/fuzzylite/fl/norm/t/BoundedDifference.h
+++ b/fuzzylite/fl/norm/t/BoundedDifference.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_BOUNDEDDIFFERENCE_H
@@ -29,16 +21,32 @@
namespace fl {
- class FL_API BoundedDifference : public TNorm {
+ /**
+ The BoundedDifference class is a TNorm that computes the bounded
+ difference between any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see BoundedSum
+ @see TNorm
+ @see TNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API BoundedDifference FL_IFINAL : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the bounded difference between two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$\max(0, a+b - 1)@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
BoundedDifference* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
-
}
-
#endif /* FL_BOUNDEDDIFFERENCE_H */
-
diff --git a/fuzzylite/fl/norm/t/DrasticProduct.h b/fuzzylite/fl/norm/t/DrasticProduct.h
index efd589d..d0d490e 100644
--- a/fuzzylite/fl/norm/t/DrasticProduct.h
+++ b/fuzzylite/fl/norm/t/DrasticProduct.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_DRASTICPRODUCT_H
@@ -29,17 +21,35 @@
namespace fl {
- class FL_API DrasticProduct : public TNorm {
+ /**
+ The DrasticProduct class is a TNorm that computes the drastic product of
+ any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see DrasticSum
+ @see TNorm
+ @see TNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API DrasticProduct FL_IFINAL : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the drastic product of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$\begin{cases}
+ \min(a,b) & \mbox{if $\max(a,b)=1$} \cr
+ 0 & \mbox{otherwise}
+ \end{cases}@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
DrasticProduct* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
-
-
}
-
#endif /* FL_DRASTICPRODUCT_H */
-
diff --git a/fuzzylite/fl/norm/t/EinsteinProduct.h b/fuzzylite/fl/norm/t/EinsteinProduct.h
index a4c1141..9d3a71b 100644
--- a/fuzzylite/fl/norm/t/EinsteinProduct.h
+++ b/fuzzylite/fl/norm/t/EinsteinProduct.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_EINSTEINPRODUCT_H
@@ -29,17 +21,32 @@
namespace fl {
- class FL_API EinsteinProduct : public TNorm {
+ /**
+ The EinsteinProduct class is a TNorm that computes the Einstein product
+ of any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see EinsteinSum
+ @see TNorm
+ @see TNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API EinsteinProduct FL_IFINAL : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the Einstein product of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$(a\times b)/(2-(a+b-a\times b))@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
EinsteinProduct* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
-
-
}
-
#endif /* FL_EINSTEINPRODUCT_H */
-
diff --git a/fuzzylite/fl/norm/t/HamacherProduct.h b/fuzzylite/fl/norm/t/HamacherProduct.h
index 9bc6b40..79c56ee 100644
--- a/fuzzylite/fl/norm/t/HamacherProduct.h
+++ b/fuzzylite/fl/norm/t/HamacherProduct.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_HAMACHERPRODUCT_H
@@ -29,16 +21,32 @@
namespace fl {
- class FL_API HamacherProduct : public TNorm {
+ /**
+ The HamacherProduct class is a TNorm that computes the Hamacher product
+ of any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see HamacherSum
+ @see TNorm
+ @see TNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API HamacherProduct FL_IFINAL : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the Hamacher product of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$(a \times b) / (a+b- a \times b)@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
HamacherProduct* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
-
}
-
#endif /* FL_HAMACHERPRODUCT_H */
-
diff --git a/fuzzylite/fl/norm/t/Minimum.h b/fuzzylite/fl/norm/t/Minimum.h
index 3590e42..5df1ae2 100644
--- a/fuzzylite/fl/norm/t/Minimum.h
+++ b/fuzzylite/fl/norm/t/Minimum.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_MINIMUM_H
@@ -29,16 +21,31 @@
namespace fl {
- class FL_API Minimum : public TNorm {
+ /**
+ The Minimum class is a TNorm that computes the minimum of any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Maximum
+ @see TNorm
+ @see TNormFactory
+ @see Norm
+ @since 4.0
+ */
+ class FL_API Minimum FL_IFINAL : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the minimum of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$\min(a,b)@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
Minimum* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
-
}
-
#endif /* FL_MINIMUM_H */
-
diff --git a/fuzzylite/fl/norm/t/NilpotentMinimum.h b/fuzzylite/fl/norm/t/NilpotentMinimum.h
index b3c11e0..2ea7f3c 100644
--- a/fuzzylite/fl/norm/t/NilpotentMinimum.h
+++ b/fuzzylite/fl/norm/t/NilpotentMinimum.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_NILPOTENTMINIMUM_H
@@ -29,15 +21,35 @@
namespace fl {
- class FL_API NilpotentMinimum : public TNorm {
+ /**
+ The NilpotentMinimum class is a TNorm that computes the nilpotent minimum
+ of any two values.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see NilpotentMaximum
+ @see TNorm
+ @see TNormFactory
+ @see Norm
+ @since 5.0
+ */
+ class FL_API NilpotentMinimum FL_IFINAL : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the nilpotent minimum of two membership function values
+ @param a is a membership function value
+ @param b is a membership function value
+ @return @f$\begin{cases}
+ \min(a,b) & \mbox{if $a+b>1$} \cr
+ 0 & \mbox{otherwise}
+ \end{cases}@f$
+ */
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
NilpotentMinimum* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
}
-
#endif /* FL_NILPOTENTMINIMUM_H */
-
diff --git a/fuzzylite/fl/norm/t/TNormFunction.h b/fuzzylite/fl/norm/t/TNormFunction.h
new file mode 100644
index 0000000..1193a40
--- /dev/null
+++ b/fuzzylite/fl/norm/t/TNormFunction.h
@@ -0,0 +1,81 @@
+/*
+ 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_TNORMFUNCTION_H
+#define FL_TNORMFUNCTION_H
+
+#include "fl/norm/TNorm.h"
+
+#include "fl/term/Function.h"
+
+namespace fl {
+
+ /**
+ The TNormFunction class is a customizable TNorm via Function, which
+ computes any function based on the @f$a@f$ and @f$b@f$ values.
+ This TNorm is not registered with the TNormFactory.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Function
+ @see TNorm
+ @see Norm
+ @see TNormFactory
+ @since 6.0
+ */
+
+ class FL_API TNormFunction FL_IFINAL : public TNorm {
+ private:
+ Function _function;
+ public:
+ explicit TNormFunction(const std::string& formula = "");
+
+ /**
+ Returns the reference to the Function
+ @return the reference to the Function
+ */
+ Function& function();
+
+ /**
+ Loads the function with the given formula
+ @param formula is a valid formula in infix notation
+ */
+ void setFormula(const std::string& formula);
+ /**
+ Returns the formula loaded into the function
+ @return the formula loaded into the function
+ */
+ std::string getFormula() const;
+
+ std::string className() const FL_IOVERRIDE;
+
+ Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the S-Norm utilizing the given function via
+ SNormFunction::setFormula(), which automatically assigns the values
+ of @f$a@f$ and @f$b@f$.
+
+ @param a is a membership function value
+ @param b is a membership function value
+ @return the evaluation of the function
+ */
+ scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
+ TNormFunction* clone() const FL_IOVERRIDE;
+
+ static TNorm* constructor();
+ };
+}
+#endif /* FL_TNORMFUNCTION_H */
+
diff --git a/fuzzylite/fl/rule/Antecedent.h b/fuzzylite/fl/rule/Antecedent.h
index 02724e5..a424d95 100644
--- a/fuzzylite/fl/rule/Antecedent.h
+++ b/fuzzylite/fl/rule/Antecedent.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_ANTECEDENT_H
@@ -27,6 +19,8 @@
#include "fl/fuzzylite.h"
+#include "fl/Complexity.h"
+
#include <string>
namespace fl {
@@ -36,42 +30,156 @@ namespace fl {
class SNorm;
class Expression;
+ /**
+ The Antecedent class is an expression tree that represents and evaluates
+ the antecedent of a Rule. The structure of a rule is: `if (antecedent)
+ then (consequent)`. The structure of the antecedent of a rule is:
+
+ `if variable is [hedge]* term [(and|or) variable is [hedge]* term]*`
+
+ where `*`-marked elements may appear zero or more times, elements in
+ brackets are optional, and elements in parentheses are compulsory.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Consequent
+ @see Rule
+ @since 4.0
+ */
class FL_API Antecedent {
- protected:
+ private:
std::string _text;
- Expression* _expression;
+ FL_unique_ptr<Expression> _expression;
public:
Antecedent();
virtual ~Antecedent();
+ /**
+ Sets the antecedent in text
+ @param text is the antecedent in text
+ */
virtual void setText(const std::string& text);
+ /**
+ Gets the antecedent in text
+ @return the antecedent in text
+ */
virtual std::string getText() const;
+ /**
+ Gets the expression tree of the antecedent
+ @return the expression tree of the antecedent
+ */
virtual Expression* getExpression() const;
+ /**
+ Sets the expression tree of the antecedent
+ @param expression is the expression tree of the antecedent
+ */
+ virtual void setExpression(Expression* expression);
+
+ /**
+ Indicates whether the antecedent is loaded
+ @return whether the antecedent is loaded
+ */
virtual bool isLoaded() const;
+ /**
+ Unloads the antecedent
+ */
virtual void unload();
- virtual void load(Rule* rule, const Engine* engine);
- virtual void load(const std::string& antecedent, Rule* rule, const Engine* engine);
+ /**
+ Loads the antecedent with the text obtained from
+ Antecedent::getText() and uses the engine to identify and retrieve
+ references to the input variables and output variables as required
+
+ @param engine is the engine from which the rules are part of
+ */
+ virtual void load(const Engine* engine);
+ /**
+ Loads the antecedent with the given text and uses the engine to
+ identify and retrieve references to the input variables and output
+ variables as required
+
+ @param antecedent is the antecedent of the rule in text
+ @param engine is the engine from which the rules are part of
+ */
+ virtual void load(const std::string& antecedent, const Engine* engine);
+
+ /**
+ Computes the estimated complexity of calculating the activation degree
+ @return the estimated complexity of calculating the activation degree
+ */
+ virtual Complexity complexity(const TNorm* conjunction, const SNorm* disjunction) const;
+ /**
+ Computes the estimated complexity of recursively calculating the
+ activation degree from the given node
+ @return the estimated complexity of recursively calculating the
+ activation degree from the given node
+ */
+ virtual Complexity complexity(const TNorm* conjunction, const SNorm* disjunction,
+ const Expression* node) const;
+
+
+ /**
+ Computes the activation degree of the antecedent on the expression
+ tree from the given node
+
+ @param conjunction is the conjunction operator from the RuleBlock
+ @param disjunction is the disjunction operator from the RuleBlock
+ @param node is a node in the expression tree of the antecedent
+ @return the activation degree of the antecedent
+ */
virtual scalar activationDegree(const TNorm* conjunction, const SNorm* disjunction,
const Expression* node) const;
+ /**
+ Computes the activation degree of the antecedent on the expression
+ tree from the root node
+
+ @param conjunction is the conjunction operator from the RuleBlock
+ @param disjunction is the disjunction operator from the RuleBlock
+ @return the activation degree of the antecedent on the expression tree
+ */
virtual scalar activationDegree(const TNorm* conjunction, const SNorm* disjunction) const;
+ /**
+ Returns a string representation of the expression tree in infix
+ notation
+
+ @return a string representation of the expression tree in infix
+ notation
+ */
virtual std::string toString() const;
+ /**
+ Returns a string represention of the given expression tree utilizing
+ prefix notation
+ @param node is a node in the expression tree of the antecedent
+ @return a string represention of the given expression tree utilizing
+ prefix notation
+ */
virtual std::string toPrefix(const Expression* node = fl::null) const;
+ /**
+ Returns a string represention of the given expression tree utilizing
+ infix notation
+ @param node is a node in the expression tree of the antecedent
+ @return a string represention of the given expression tree utilizing
+ infix notation
+ */
virtual std::string toInfix(const Expression* node = fl::null) const;
+ /**
+ Returns a string represention of the given expression tree utilizing
+ postfix notation
+ @param node is a node in the expression tree of the antecedent
+ @return a string represention of the given expression tree utilizing
+ postfix notation
+ */
virtual std::string toPostfix(const Expression* node = fl::null) const;
private:
FL_DISABLE_COPY(Antecedent)
};
-
}
-
#endif /* FL_ANTECEDENT_H */
diff --git a/fuzzylite/fl/rule/Consequent.h b/fuzzylite/fl/rule/Consequent.h
index 5394dc0..275d1e7 100644
--- a/fuzzylite/fl/rule/Consequent.h
+++ b/fuzzylite/fl/rule/Consequent.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_CONSEQUENT_H
@@ -27,6 +19,8 @@
#include "fl/fuzzylite.h"
+#include "fl/Complexity.h"
+
#include <string>
#include <vector>
@@ -36,8 +30,26 @@ namespace fl {
class Proposition;
class TNorm;
+ /**
+ The Consequent class is a proposition set that represents and evaluates
+ the consequent of a Rule.. The structure of a rule is: `if (antecedent)
+ then (consequent)`. The structure of the consequent of a rule is:
+
+ `then variable is [hedge]* term [and variable is [hedge]* term]* [with
+ w]?`
+
+ where `*`-marked elements may appear zero or more times, elements in
+ brackets are optional, elements in parentheses are compulsory, and
+ `?`-marked elements may appear once or not at all.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Antecedent
+ @see Rule
+ @since 4.0
+ */
+
class FL_API Consequent {
- protected:
+ private:
std::string _text;
std::vector<Proposition*> _conclusions;
@@ -45,24 +57,82 @@ namespace fl {
Consequent();
virtual ~Consequent();
+ /**
+ Sets the text of the consequent
+ @param text is the text of the consequent
+ */
virtual void setText(const std::string& text);
+ /**
+ Gets the text of the consequent
+ @return the text of the consequent
+ */
virtual std::string getText() const;
+ /**
+ Computes the estimated complexity of modifying the consequents
+ @return the estimated complexity of modifying the consequents
+ */
+ virtual Complexity complexity(const TNorm* implication) const;
+ /**
+ Returns an immutable vector of the propositions that represent the
+ Consequent of a Rule
+ @return an immutable vector of the set of propositions that represent
+ the Consequent of a Rule
+ */
virtual const std::vector<Proposition*>& conclusions() const;
+ /**
+ Returns the vector of propositions that represent the Consequent of a
+ Rule
+ @return the vector of propositions that represent the Consequent of a
+ Rule
+ */
+ virtual std::vector<Proposition*>& conclusions();
+
+ /**
+ Indicates whether the consequent is loaded
+ @return whether the consequent is loaded
+ */
virtual bool isLoaded();
+ /**
+ Unloads the consequent
+ */
virtual void unload();
- virtual void load(Rule* rule, const Engine* engine);
- virtual void load(const std::string& consequent, Rule* rule, const Engine* engine);
-
- virtual void modify(scalar activationDegree, const TNorm* activation);
-
+ /**
+ Loads the consequent with text given from Consequent::getText() and
+ uses the engine to identify and retrieve references to the input
+ variables and output variables as required
+ @param engine is the engine from which the rules are part of
+ */
+ virtual void load(const Engine* engine);
+ /**
+ Loads the consequent with the given text and uses the engine to
+ identify and retrieve references to the input variables and output
+ variables as required
+ @param consequent is the consequent of the rule in text
+ @param engine is the engine from which the rules are part of
+ */
+ virtual void load(const std::string& consequent, const Engine* engine);
+
+ /**
+ Modifies the proposition set according to the activation degree
+ (computed in the Antecedent of the Rule) and the implication operator
+ (given in the RuleBlock)
+ @param activationDegree is the activation degree computed in the
+ Antecedent of the Rule
+ @param implication is the implication operator configured in the
+ RuleBlock
+ */
+ virtual void modify(scalar activationDegree, const TNorm* implication);
+
+ /**
+ Returns a string representation of the Consequent
+ @return a string representation of the Consequent
+ */
virtual std::string toString() const;
private:
FL_DISABLE_COPY(Consequent)
};
-
}
-
#endif /* FL_CONSEQUENT_H */
diff --git a/fuzzylite/fl/rule/Expression.h b/fuzzylite/fl/rule/Expression.h
index cb48355..dbacc60 100644
--- a/fuzzylite/fl/rule/Expression.h
+++ b/fuzzylite/fl/rule/Expression.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_EXPRESSION_H
@@ -37,48 +29,105 @@ namespace fl {
class Hedge;
class Term;
+ /**
+ The Expression class is the base class to build an expression tree.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Antecedent
+ @see Consequent
+ @see Rule
+ @since 4.0
+ */
class FL_API Expression {
public:
+ enum Type {
+ Proposition, Operator
+ };
Expression();
virtual ~Expression();
+ /**
+ Returns the type of the expression
+ @return the type of the expression
+ */
+ virtual Type type() const = 0;
virtual std::string toString() const = 0;
private:
FL_DISABLE_COPY(Expression)
};
- class FL_API Proposition : public Expression {
+ /**
+ The Proposition class is an Expression that represents a terminal node in
+ the expression tree as `variable is [hedge]* term`.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Antecedent
+ @see Consequent
+ @see Rule
+ @since 4.0
+ */
+ class FL_API Proposition FL_IFINAL : public Expression {
public:
+ /**Variable in `variable is [hedge]* term`*/
Variable* variable;
+ /**Hedge%s in `variable is [hedge]* term`, owned by the object,
+ destroyed on destructor*/
std::vector<Hedge*> hedges;
+ /**Term in `variable is [hedge]* term`*/
Term* term;
Proposition();
- virtual ~Proposition() FL_IOVERRIDE;
+ ~Proposition() FL_IOVERRIDE;
+
+ Expression::Type type() const FL_IOVERRIDE;
+
+ /**
+ Returns a string representation of the proposition
+ @return a string representation of the proposition
+ */
+ std::string toString() const FL_IOVERRIDE;
- virtual std::string toString() const FL_IOVERRIDE;
private:
FL_DISABLE_COPY(Proposition)
};
- class FL_API Operator : public Expression {
+ /**
+ The Operator class is an Expression that represents a non-terminal node
+ in the expression tree as a binary operator (i.e., `and` or `or`) on two
+ Expression nodes.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Antecedent
+ @see Consequent
+ @see Rule
+ @since 4.0
+ */
+ class FL_API Operator FL_IFINAL : public Expression {
public:
+ /**Name of the operator*/
std::string name;
+ /**Left expression in the binary tree*/
Expression* left;
+ /**Right expression in the binary tree*/
Expression* right;
Operator();
- virtual ~Operator() FL_IOVERRIDE;
+ ~Operator() FL_IOVERRIDE;
+
+ Expression::Type type() const FL_IOVERRIDE;
- virtual std::string toString() const FL_IOVERRIDE;
+ /**
+ Returns the name of the operator
+ @return the name of the operator
+ */
+ std::string toString() const FL_IOVERRIDE;
private:
FL_DISABLE_COPY(Operator)
};
-
}
#endif /* FL_FUZZYEXPRESSION_H */
diff --git a/fuzzylite/fl/rule/Rule.h b/fuzzylite/fl/rule/Rule.h
index 20d39fb..b123d15 100644
--- a/fuzzylite/fl/rule/Rule.h
+++ b/fuzzylite/fl/rule/Rule.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_RULE_H
@@ -27,25 +19,59 @@
#include "fl/fuzzylite.h"
+#include "fl/rule/Consequent.h"
+#include "fl/rule/Antecedent.h"
+
#include <map>
#include <string>
namespace fl {
class Engine;
- class Antecedent;
- class Consequent;
class Hedge;
class TNorm;
class SNorm;
+ /**
+ The Rule class is a conditional statement that contributes to the control
+ of an Engine. Each rule consists of an Antecedent and a Consequent, each
+ of which comprises propositions in the form `variable is term`. The
+ propositions in the Antecedent can be connected by the conjunctive `and`
+ or the disjunctive `or`, both of which are fuzzy logic operators (TNorm
+ and SNorm, respectively). Differently, the propositions in the Consequent
+ are independent from each other and are separated with a symbolic `and`.
+ The Term in any proposition can be preceded by a Hedge that modifies its
+ membership function to model cases such as Very, Somewhat, Seldom and
+ Not. Additionally, the contribution of a rule to the control of the
+ engine can be determined by its weight @f$w \in [0.0, 1.0]@f$, which is
+ equal to 1.0 if omitted. The structure of a rule is the following: `if
+ (antecedent) then (consequent) [with weight]`. The structures of
+ the antecedent and the consequent are:
+
+ `if variable is [hedge]* term [(and|or) variable is [hedge]* term]*`
+
+ `then variable is [hedge]* term [and variable is [hedge]* term]* [with w]?`
+
+ where elements in brackets are optional, elements in parentheses are
+ compulsory, `*`-marked elements may appear zero or more times, and
+ `?`-marked elements may appear once or not at all.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Antecedent
+ @see Consequent
+ @see Hedge
+ @see RuleBlock
+ @since 4.0
+ */
class FL_API Rule {
- protected:
+ private:
+ bool _enabled;
std::string _text;
scalar _weight;
+ scalar _activationDegree;
+ bool _triggered;
FL_unique_ptr<Antecedent> _antecedent;
FL_unique_ptr<Consequent> _consequent;
- std::map<std::string, Hedge*> _hedges;
public:
explicit Rule(const std::string& text = "", scalar weight = 1.0);
@@ -54,68 +80,226 @@ namespace fl {
virtual ~Rule();
FL_DEFAULT_MOVE(Rule)
+ /**
+ Sets whether the rule is enabled. An enabled rule will be fired, whereas
+ a disabled rule will not.
+ @param enabled determines whether the rule is enabled
+ */
+ virtual void setEnabled(bool enabled);
+
+ /**
+ Gets whether the rule is enabled. An enabled rule will be fired, whereas
+ a disabled rule will not.
+ @return whether the rule is enabled
+ */
+ virtual bool isEnabled() const;
+
+ /**
+ Sets the text of the rule
+ @param text is the text of the rule
+ */
virtual void setText(const std::string& text);
+ /**
+ Gets the text of the rule
+ @return the text of the rule
+ */
virtual std::string getText() const;
+ /**
+ Sets the weight of the rule
+ @param weight is the weight of the rule
+ */
virtual void setWeight(scalar weight);
+ /**
+ Gets the weight of the rule
+ @return the weight of the rule
+ */
virtual scalar getWeight() const;
+ /**
+ Sets the antecedent of the rule
+ @param antecedent is the antecedent of the rule
+ */
virtual void setAntecedent(Antecedent* antecedent);
+ /**
+ Gets the antecedent of the rule
+ @return the antecedent of the rule
+ */
virtual Antecedent* getAntecedent() const;
+ /**
+ Sets the consequent of the rule
+ @param consequent the consequent of the rule
+ */
virtual void setConsequent(Consequent* consequent);
+ /**
+ Gets the consequent of the rule
+ @return the consequent of the rule
+ */
virtual Consequent* getConsequent() const;
- virtual void addHedge(Hedge* hedge);
- virtual Hedge* getHedge(const std::string& name) const;
- virtual Hedge* removeHedge(const std::string& hedge);
- virtual bool hasHedge(const std::string& name) const;
- virtual int numberOfHedges() const;
- virtual void setHedges(const std::map<std::string, Hedge*>& hedges);
- virtual const std::map<std::string, Hedge*>& hedges() const;
- virtual std::map<std::string, Hedge*>& hedges();
-
- virtual scalar activationDegree(const TNorm* conjunction, const SNorm* disjunction) const;
- virtual void activate(scalar degree, const TNorm* activation) const;
-
+ /**
+ Sets the activation degree of the rule
+ @param activationDegree is the activation degree of the rule
+ */
+ virtual void setActivationDegree(scalar activationDegree);
+
+ /**
+ Gets the activation degree of the rule
+ @return the activation degree of the rule
+ */
+ virtual scalar getActivationDegree() const;
+
+ /**
+ Activates the rule by computing its activation degree using the given
+ conjunction and disjunction operators
+ @param conjunction is the conjunction operator
+ @param disjunction is the disjunction operator
+ @return the activation degree of the rule
+ */
+ virtual scalar activateWith(const TNorm* conjunction, const SNorm* disjunction);
+
+ /**
+ Deactivates the rule
+ */
+ virtual void deactivate();
+
+ /**
+ Triggers the rule's implication (if the rule is enabled) using the
+ given implication operator and the underlying activation degree
+ @param implication is the implication operator
+ */
+ virtual void trigger(const TNorm* implication);
+
+ /**
+ Indicates whether the rule's implication was triggered
+ @return whether the rule's implication was triggered
+ */
+ virtual bool isTriggered() const;
+
+ /**
+ Returns a string representation of the rule in the FuzzyLite Language
+ @return a string representation of the rule in the FuzzyLite Language
+ */
virtual std::string toString() const;
+ /**
+ Indicates whether the rule is loaded
+ @return whether the rule is loaded
+ */
virtual bool isLoaded() const;
+ /**
+ Unloads the rule
+ */
virtual void unload();
+ /**
+ Loads the rule with the text from Rule::getText(), and uses the
+ engine to identify and retrieve references to the input variables and
+ output variables as required
+ @param engine is the engine from which the rule is part of
+ */
virtual void load(const Engine* engine);
+ /**
+ Loads the rule with the given text, and uses the engine to identify
+ and retrieve references to the input variables and output variables
+ as required
+
+ @param rule is the rule in text
+ @param engine is the engine from which the rule is part of
+ */
virtual void load(const std::string& rule, const Engine* engine);
-
+
+ /**
+ Creates a clone of the rule without the rule being loaded
+ @return a clone of the rule without the rule being loaded
+ */
virtual Rule* clone() const;
+ /**
+ Parses and creates a new rule based on the text passed
+ @param rule is the rule in text
+ @param engine is the engine from which the rule is part of
+ @return a new rule parsed from the given text
+ */
static Rule* parse(const std::string& rule, const Engine* engine);
- static std::string ifKeyword() {
+ /**
+ Returns a string representation of the `if` keyword in rules
+ @return a string representation of the `if` keyword in rules
+ */
+ inline static std::string ifKeyword() {
return "if";
}
- static std::string isKeyword() {
+ /**
+ Returns a string representation of the `is` keyword in rules
+ @return a string representation of the `is` keyword in rules
+ */
+ inline static std::string isKeyword() {
return "is";
}
- static std::string thenKeyword() {
+ /**
+ Returns a string representation of the `then` keyword in rules
+ @return a string representation of the `then` keyword in rules
+ */
+ inline static std::string thenKeyword() {
return "then";
}
- static std::string andKeyword() {
+ /**
+ Returns a string representation of the `and` keyword in rules
+ @return a string representation of the `and` keyword in rules
+ */
+ inline static std::string andKeyword() {
return "and";
}
- static std::string orKeyword() {
+ /**
+ Returns a string representation of the `or` keyword in rules
+ @return a string representation of the `or` keyword in rules
+ */
+ inline static std::string orKeyword() {
return "or";
}
- static std::string withKeyword() {
+ /**
+ Returns a string representation of the `with` keyword in rules
+ @return a string representation of the `with` keyword in rules
+ */
+ inline static std::string withKeyword() {
return "with";
}
- };
+ /**
+ Computes the estimated complexity of calculating the activation degree
+ of the rule
+ @param conjunction is the conjunction operator
+ @param disjunction is the disjunction operator
+ @return the estimated complexity of calculating the activation degree
+ of the rule
+ */
+ virtual Complexity complexityOfActivation(const TNorm* conjunction,
+ const SNorm* disjunction) const;
+
+ /**
+ Computes the estimated complexity of firing the rule
+ @param implication is the implication operator
+ @return the estimated complexity of firing the rule
+ */
+ virtual Complexity complexityOfFiring(const TNorm* implication) const;
+
+ /**
+ Returns the estimated complexity of activating and firing the rule
+ @param conjunction is the conjunction operator
+ @param disjunction is the disjunction operator
+ @param implication is the implication operator
+ @return the estimated complexity of activating and firing the rule
+ */
+ virtual Complexity complexity(const TNorm* conjunction,
+ const SNorm* disjunction, const TNorm* implication) const;
+ };
}
-
#endif /* FL_RULE_H */
diff --git a/fuzzylite/fl/rule/RuleBlock.h b/fuzzylite/fl/rule/RuleBlock.h
index 35fe62e..d4ccace 100644
--- a/fuzzylite/fl/rule/RuleBlock.h
+++ b/fuzzylite/fl/rule/RuleBlock.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_RULEBLOCK_H
@@ -27,6 +19,9 @@
#include "fl/fuzzylite.h"
+#include "fl/activation/Activation.h"
+#include "fl/Complexity.h"
+
#include <string>
#include <vector>
@@ -38,16 +33,29 @@ namespace fl {
class TNorm;
class SNorm;
+ /**
+ The RuleBlock class contains a set of Rule%s and fuzzy logic
+ operators required to control an Engine.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Engine
+ @see Rule
+ @see Antecedent
+ @see Consequent
+ @since 4.0
+ */
class FL_API RuleBlock {
private:
- void copyFrom(const RuleBlock& source);
- protected:
+ bool _enabled;
std::string _name;
+ std::string _description;
std::vector<Rule*> _rules;
FL_unique_ptr<TNorm> _conjunction;
FL_unique_ptr<SNorm> _disjunction;
- FL_unique_ptr<TNorm> _activation;
- bool _enabled;
+ FL_unique_ptr<TNorm> _implication;
+ FL_unique_ptr<Activation> _activation;
+
+ void copyFrom(const RuleBlock& source);
public:
explicit RuleBlock(const std::string& name = "");
@@ -56,42 +64,170 @@ namespace fl {
virtual ~RuleBlock();
FL_DEFAULT_MOVE(RuleBlock)
+ /**
+ Enables the rule block
+ @param enabled whether the rule block is enabled
+ */
+ virtual void setEnabled(bool enabled);
+ /**
+ Indicates whether the rule block is enabled
+ @return whether the rule block is enabled
+ */
+ virtual bool isEnabled() const;
+
+ /**
+ Activates the rule block
+ */
virtual void activate();
+ /**
+ Sets the name of the rule block
+ @param name is the name of the rule block
+ */
virtual void setName(std::string name);
+ /**
+ Gets the name of the rule block
+ @return the name of the rule block
+ */
virtual std::string getName() const;
+ /**
+ Gets the description of the rule block
+ @return the description of the rule block
+ */
+ virtual std::string getDescription() const;
+
+ /**
+ Sets the description of the rule block
+ @param description is the description of the rule block
+ */
+ virtual void setDescription(const std::string& description);
+ /**
+ Sets the conjunction operator
+ @param conjunction is the conjunction operator
+ */
virtual void setConjunction(TNorm* conjunction);
+ /**
+ Gets the conjunction operator
+ @return the conjunction operator
+ */
virtual TNorm* getConjunction() const;
+ /**
+ Sets the disjunction operator
+ @param disjunction is the disjunction operator
+ */
virtual void setDisjunction(SNorm* disjunction);
+ /**
+ Gets the disjunction operator
+ @return the disjunction operator
+ */
virtual SNorm* getDisjunction() const;
- virtual void setActivation(TNorm* activation);
- virtual TNorm* getActivation() const;
+ /**
+ Sets the implication operator
+ @param implication is the implication operator
+ */
+ virtual void setImplication(TNorm* implication);
+ /**
+ Gets the implication operator
+ @return the implication operator
+ */
+ virtual TNorm* getImplication() const;
- virtual void setEnabled(bool enabled);
- virtual bool isEnabled() const;
+ /**
+ Sets the activation method
+ @param activation is the activation method
+ */
+ virtual void setActivation(Activation* activation);
+ /**
+ Gets the activation method
+ @return the activation method
+ */
+ virtual Activation* getActivation() const;
+ /**
+ Unloads all the rules in the rule block
+ */
virtual void unloadRules() const;
+ /**
+ Loads all the rules into the rule block
+ @param engine is the engine where this rule block is registered
+ */
virtual void loadRules(const Engine* engine);
+
+ /**
+ Unloads all the rules in the rule block and then loads each rule again
+ @param engine is the engine where this rule block is registered
+ */
virtual void reloadRules(const Engine* engine);
+ /**
+ Returns a string representation of the rule block in the FuzzyLite
+ Language
+ @return a string representation of the rule block in the FuzzyLite
+ Language
+ */
virtual std::string toString() const;
/**
- * Operations for iterable datatype _rules
+ Returns the estimated complexity of activating the rule block
+ @return the estimated complexity of activating the rule block
+ */
+ virtual Complexity complexity() const;
+
+ /**
+ Adds the given rule to the rule block
+ @param rule is the rule to add
*/
virtual void addRule(Rule* rule);
- virtual void insertRule(Rule* rule, int index);
- virtual Rule* getRule(int index) const;
- virtual Rule* removeRule(int index);
- virtual int numberOfRules() const;
+ /**
+ Inserts the rule at the specified index, shifting other rules to
+ the right
+ @param rule is the rule to insert
+ @param index is the index at which to insert the rule
+ */
+ virtual void insertRule(Rule* rule, std::size_t index);
+ /**
+ Gets the rule at the specified index
+ @param index is the index at which the rule is retrieved
+ @return the rule at the specified index
+ */
+ virtual Rule* getRule(std::size_t index) const;
+ /**
+ Removes the rule at the specified index
+ @param index is the index at which the rule will be removed,
+ shifting other rules to the left
+ @return the rule at the specified index
+ */
+ virtual Rule* removeRule(std::size_t index);
+ /**
+ Returns the number of rules added to the rule block
+ @return the number of rules added to the rule block
+ */
+ virtual std::size_t numberOfRules() const;
+ /**
+ Sets the rules of the rule block
+ @param rules is a vector of rules
+ */
virtual void setRules(const std::vector<Rule*>& rules);
+ /**
+ Returns an immutable vector of the rules added to the rule block
+ @return an immutable vector of the rules added to the rule block
+ */
virtual const std::vector<Rule*>& rules() const;
+ /**
+ Returns a mutable vector of the rules added to the rule block
+ @return a mutable vector of the rules added to the rule block
+ */
virtual std::vector<Rule*>& rules();
- };
+ /**
+ Creates a clone of the rule block without the rules being loaded
+ @return a clone of the rule block without the rules being loaded
+ */
+ virtual RuleBlock* clone() const;
+ };
}
#endif /* RULEBLOCK_H */
diff --git a/fuzzylite/fl/term/Accumulated.h b/fuzzylite/fl/term/Accumulated.h
deleted file mode 100644
index 51625d0..0000000
--- a/fuzzylite/fl/term/Accumulated.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- Author: Juan Rada-Vilela, Ph.D.
- Copyright (C) 2010-2014 FuzzyLite Limited
- All rights reserved
-
- 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.
-
- 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.
-
- */
-
-#ifndef FL_ACCUMULATED_H
-#define FL_ACCUMULATED_H
-
-#include "fl/term/Term.h"
-
-#include <vector>
-
-namespace fl {
-
- class Activated;
- class SNorm;
- class TNorm;
-
- class FL_API Accumulated : public Term {
- private:
- void copyFrom(const Accumulated& source);
- protected:
- std::vector<Activated*> _terms;
- scalar _minimum, _maximum;
- FL_unique_ptr<SNorm> _accumulation;
- public:
- explicit Accumulated(const std::string& name = "",
- scalar minimum = fl::nan,
- scalar maximum = fl::nan,
- SNorm* accumulation = fl::null);
- Accumulated(const Accumulated& other);
- Accumulated& operator=(const Accumulated& other);
- virtual ~Accumulated() FL_IOVERRIDE;
- FL_DEFAULT_MOVE(Accumulated)
-
- virtual std::string className() const FL_IOVERRIDE;
- virtual std::string parameters() const FL_IOVERRIDE;
- virtual void configure(const std::string& parameters) FL_IOVERRIDE;
-
- virtual Accumulated* clone() const FL_IOVERRIDE;
-
- virtual scalar membership(scalar x) const FL_IOVERRIDE;
- virtual scalar activationDegree(const Term* forTerm) const;
-
- virtual std::string toString() const FL_IOVERRIDE;
-
-
- virtual void setMinimum(scalar minimum);
- virtual scalar getMinimum() const;
-
- virtual void setMaximum(scalar maximum);
- virtual scalar getMaximum() const;
-
- virtual void setRange(scalar minimum, scalar maximum);
- virtual scalar range() const;
-
- virtual void setAccumulation(SNorm* accumulation);
- virtual SNorm* getAccumulation() const;
-
- /**
- * Operations for std::vector _terms
- */
- virtual void addTerm(const Term* term, scalar degree, const TNorm* activation);
- virtual void addTerm(Activated* term);
- virtual Activated* getTerm(int index) const;
- virtual Activated* removeTerm(int index);
- virtual int numberOfTerms() const;
- virtual const std::vector<Activated*>& terms() const;
- virtual std::vector<Activated*>& terms();
- virtual bool isEmpty() const;
- virtual void clear();
- };
-
-}
-#endif /* FL_ACCUMULATED_H */
diff --git a/fuzzylite/fl/term/Activated.h b/fuzzylite/fl/term/Activated.h
index 10c1b40..f122a25 100644
--- a/fuzzylite/fl/term/Activated.h
+++ b/fuzzylite/fl/term/Activated.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_ACTIVATED_H
@@ -30,36 +22,86 @@
namespace fl {
class TNorm;
+ /**
+ The Activated class is a special Term that contains pointers to the
+ necessary information of a term that has been activated as part of the
+ Antecedent of a Rule. The ownership of the pointers is not transferred to
+ objects of this class. The Activated class was named
+ `Thresholded` in versions 4.0 and earlier.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see OutputVariable
+ @see Term
+ @since 5.0
+ */
class FL_API Activated : public Term {
- protected:
+ private:
const Term* _term;
scalar _degree;
- const TNorm* _activation;
+ const TNorm* _implication;
public:
explicit Activated(const Term* term = fl::null, scalar degree = 1.0,
- const TNorm* activationOperator = fl::null);
+ const TNorm* implication = fl::null);
virtual ~Activated() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Activated)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"degree implication term"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Does nothing.
+ @param parameters are irrelevant
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the implication of the activation degree and the membership
+ function value of @f$x@f$
+ @param x is a value
+ @return @f$d \otimes \mu(x)@f$, where @f$d@f$ is the activation degree
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual std::string toString() const FL_IOVERRIDE;
+ /**
+ Sets the activated term
+ @param term is the activated term
+ */
virtual void setTerm(const Term* term);
+ /**
+ Gets the activated term
+ @return the activated term
+ */
virtual const Term* getTerm() const;
+ /**
+ Sets the activation degree of the term
+ @param degree is the activation degree of the term
+ */
virtual void setDegree(scalar degree);
+ /**
+ Gets the activation degree of the term
+ @return the activation degree of the term
+ */
virtual scalar getDegree() const;
- virtual void setActivation(const TNorm* activation);
- virtual const TNorm* getActivation() const;
+ /**
+ Sets the implication operator
+ @param implication is the implication operator
+ */
+ virtual void setImplication(const TNorm* implication);
+ /**
+ Gets the implication operator
+ @return the implication operator
+ */
+ virtual const TNorm* getImplication() const;
virtual Activated* clone() const FL_IOVERRIDE;
};
-
}
#endif /* FL_ACTIVATED_H */
diff --git a/fuzzylite/fl/term/Aggregated.h b/fuzzylite/fl/term/Aggregated.h
new file mode 100644
index 0000000..af08c75
--- /dev/null
+++ b/fuzzylite/fl/term/Aggregated.h
@@ -0,0 +1,212 @@
+/*
+ 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_AGGREGATED_H
+#define FL_AGGREGATED_H
+
+#include "fl/term/Term.h"
+
+#include "fl/term/Activated.h"
+
+#include <vector>
+
+namespace fl {
+
+ class SNorm;
+ class TNorm;
+
+ /**
+ The Aggregated class is a special Term that stores a fuzzy set with the
+ Activated terms from the Antecedent%s of a Rule, thereby serving mainly
+ as the fuzzy output value of the OutputVariable%s. The ownership of the
+ activated terms will be transfered to objects of this class, and
+ therefore their destructors will be called upon destruction of this term
+ (or calling Aggregated::clear()).
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Antecedent
+ @see Rule
+ @see OutputVariable
+ @see Activated
+ @see Term
+ @since 6.0
+ */
+ class FL_API Aggregated : public Term {
+ private:
+ std::vector<Activated> _terms;
+ scalar _minimum, _maximum;
+ FL_unique_ptr<SNorm> _aggregation;
+
+ void copyFrom(const Aggregated& source);
+ public:
+ explicit Aggregated(const std::string& name = "",
+ scalar minimum = fl::nan,
+ scalar maximum = fl::nan,
+ SNorm* aggregation = fl::null);
+ Aggregated(const Aggregated& other);
+ Aggregated& operator=(const Aggregated& other);
+ virtual ~Aggregated() FL_IOVERRIDE;
+ FL_DEFAULT_MOVE(Aggregated)
+
+ virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"aggregation minimum maximum terms"`
+ */
+ virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Does nothing
+ @param parameters are irrelevant
+ */
+ virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+
+ virtual Aggregated* clone() const FL_IOVERRIDE;
+
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ virtual Complexity complexityOfMembership() const;
+ virtual Complexity complexityOfActivationDegree() const;
+
+ /**
+ Aggregates the membership function values of @f$x@f$ utilizing the
+ aggregation operator
+ @param x is a value
+ @return @f$\sum_i{\mu_i(x)}, i \in \mbox{terms}@f$
+ */
+ virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ /**
+ Computes the aggregated activation degree for the given term.
+ If the same term is present multiple times, the aggregation operator
+ is utilized to sum the activation degrees of the term. If the
+ aggregation operator is fl::null, a regular sum is performed.
+ @param forTerm is the term for which to compute the aggregated
+ activation degree
+ @return the aggregated activation degree for the given term
+ */
+ virtual scalar activationDegree(const Term* forTerm) const;
+
+ /**
+ Iterates over the Activated terms to find the term with the maximum
+ activation degree
+ @return the term with the maximum activation degree
+ */
+ virtual const Activated* highestActivatedTerm() const;
+
+ virtual std::string toString() const FL_IOVERRIDE;
+
+ /**
+ Sets the minimum of the range of the fuzzy set
+ @param minimum is the minimum of the range of the fuzzy set
+ */
+ virtual void setMinimum(scalar minimum);
+ /**
+ Gets the minimum of the range of the fuzzy set
+ @return the minimum of the range of the fuzzy set
+ */
+ virtual scalar getMinimum() const;
+
+ /**
+ Sets the maximum of the range of the fuzzy set
+ @param maximum is the maximum of the range of the fuzzy set
+ */
+ virtual void setMaximum(scalar maximum);
+ /**
+ Gets the maximum of the range of the fuzzy set
+ @return the maximum of the range of the fuzzy set
+ */
+ virtual scalar getMaximum() const;
+
+ /**
+ Sets the range of the fuzzy set to `[minimum, maximum]`
+ @param minimum is the minimum of the range of the fuzzy set
+ @param maximum is the maximum of the range of the fuzzy set
+ */
+ virtual void setRange(scalar minimum, scalar maximum);
+ /**
+ Returns the magnitude of the range of the fuzzy set,
+ @return the magnitude of the range of the fuzzy set,
+ i.e., `maximum - minimum`
+ */
+ virtual scalar range() const;
+
+ /**
+ Sets the aggregation operator
+ @param aggregation is the aggregation operator
+ */
+ virtual void setAggregation(SNorm* aggregation);
+ /**
+ Gets the aggregation operator
+ @return the aggregation operator
+ */
+ virtual SNorm* getAggregation() const;
+
+ /**
+ Adds a new Activated term (from the parameters) to the fuzzy set
+ @param term is the activated term
+ @param degree is the activation degree
+ @param implication is the implication operator
+ */
+ virtual void addTerm(const Term* term, scalar degree, const TNorm* implication);
+ /**
+ Adds the activated term to the fuzzy set. The activated term
+ will be deleted when Aggregated::clear()
+ @param term is the activated term
+ */
+ virtual void addTerm(const Activated& term);
+ /**
+ Gets the term at the given index
+ @param index is the index of the term
+ @return the activated term at the given index
+ */
+ virtual const Activated& getTerm(std::size_t index) const;
+ /**
+ Removes the term at the given index without deleting the term
+ @param index is the index of the term
+ @return the removed term
+ */
+ virtual const Activated& removeTerm(std::size_t index);
+ /**
+ Returns the number of activated terms
+ @return the number of activated terms
+ */
+ virtual std::size_t numberOfTerms() const;
+
+ /**
+ Sets the activated terms
+ @param terms is the activated terms
+ */
+ virtual void setTerms(const std::vector<Activated>& terms);
+ /**
+ Returns an immutable vector of activated terms
+ @return an immutable vector of activated terms
+ */
+ virtual const std::vector<Activated>& terms() const;
+ /**
+ Returns a mutable vector of activated terms
+ @return a mutable vector of activated terms
+ */
+ virtual std::vector<Activated>& terms();
+ /**
+ Indicates whether the vector of activated terms is empty
+ @return whether the vector of activated terms is empty
+ */
+ virtual bool isEmpty() const;
+ /**
+ Clears and deletes the activated terms
+ */
+ virtual void clear();
+ };
+}
+#endif /* FL_AGGREGATED_H */
diff --git a/fuzzylite/fl/term/Bell.h b/fuzzylite/fl/term/Bell.h
index 115479c..e27d9c9 100644
--- a/fuzzylite/fl/term/Bell.h
+++ b/fuzzylite/fl/term/Bell.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_BELL_H
@@ -29,8 +21,19 @@
namespace fl {
+ /**
+ The Bell class is an extended Term that represents the generalized bell
+ curve membership function.
+
+ @image html bell.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API Bell : public Term {
- protected:
+ private:
scalar _center;
scalar _width;
scalar _slope;
@@ -44,18 +47,62 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Bell)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"center width slope [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"center width slope [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$h / (1 + \left(|x-c|/w\right)^{2s}@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$c@f$ is the center of the Bell,
+ @f$w@f$ is the width of the Bell,
+ @f$s@f$ is the slope of the Bell
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ /**
+ Sets the center of the bell curve
+ @param center is the center of the bell curve
+ */
virtual void setCenter(scalar center);
+ /**
+ Gets the center of the bell curve
+ @return the center of the bell curve
+ */
virtual scalar getCenter() const;
+ /**
+ Sets the width of the bell curve
+ @param width is the width of the bell curve
+ */
virtual void setWidth(scalar width);
+ /**
+ Gets the width of the bell curve
+ @return the width of the bell curve
+ */
virtual scalar getWidth() const;
+ /**
+ Sets the slope of the bell curve
+ @param slope is the slope of the bell curve
+ */
virtual void setSlope(scalar slope);
+ /**
+ Gets the slope of the bell curve
+ @return the slope of the bell curve
+ */
virtual scalar getSlope() const;
virtual Bell* clone() const FL_IOVERRIDE;
@@ -63,6 +110,5 @@ namespace fl {
static Term* constructor();
};
-
}
#endif /* FL_BELL_H */
diff --git a/fuzzylite/fl/term/Binary.h b/fuzzylite/fl/term/Binary.h
new file mode 100644
index 0000000..c22a9e1
--- /dev/null
+++ b/fuzzylite/fl/term/Binary.h
@@ -0,0 +1,132 @@
+/*
+ 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_BINARY_H
+#define FL_BINARY_H
+
+#include "fl/term/Term.h"
+
+namespace fl {
+
+ /**
+ The Binary class is an edge Term that represents the binary membership
+ function.
+
+ @image html binary.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 6.0
+ */
+ class FL_API Binary : public Term {
+ private:
+ scalar _start;
+ scalar _direction;
+ public:
+
+ /**
+ Direction is an enumerator that indicates the direction of the
+ edge.
+ */
+ enum Direction {
+ /** `(_|)` increases to the right (infinity)*/
+ Positive,
+ /** `(--)` direction is NaN */
+ Undefined,
+ /** `(|_)` increases to the left (-infinity)*/
+ Negative
+ };
+
+ explicit Binary(const std::string& name = "", scalar start = fl::nan,
+ scalar direction = fl::nan, scalar height = 1.0);
+ virtual ~Binary() FL_IOVERRIDE;
+ FL_DEFAULT_COPY_AND_MOVE(Binary)
+
+ virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"start direction [height]"`
+ */
+ virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"start direction [height]"`
+ */
+ virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+
+ virtual Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$\begin{cases}
+ 1h & \mbox{if $ \left(s < d \vedge x \in [s, d)\right) \wedge
+ \left( s > d \vedge x \in (d, s] \right) $} \cr
+ 0h & \mbox{otherwise}
+ \end{cases}@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$s@f$ is the start of the Binary edge,
+ @f$d@f$ is the direction of the Binary edge.
+ */
+ virtual scalar membership(scalar x) const FL_IOVERRIDE;
+
+ /**
+ Sets the start of the binary edge
+ @param start is the start of the binary edge
+ */
+ virtual void setStart(scalar start);
+ /**
+ Gets the start of the binary edge
+ @return the start of the binary edge
+ */
+ virtual scalar getStart() const;
+
+ /**
+ Sets the direction of the binary edge.
+
+ @f$\begin{cases}
+ \text{Positive} & \mbox{if $ d > s $}\cr
+ \text{Negative} & \mbox{if $ d < s $}\cr
+ \mbox{\tt NaN} & \mbox{otherwise}
+ \end{cases}
+ @f$
+
+ where @f$d@f$ is the given direction, and
+ @f$s@f$ is the start of the Binary edge
+
+ @param direction is the direction of the binary edge
+ */
+ virtual void setDirection(scalar direction);
+ /**
+ Gets the direction of the binary edge
+ @return the direction of the binary edge
+ */
+ virtual scalar getDirection() const;
+
+ /**
+ Gets the Direction of the binary edge as an enumerator
+ @return the Direction of the binary edge as an enumerator
+ */
+ virtual Direction direction() const;
+
+ virtual Binary* clone() const FL_IOVERRIDE;
+
+ static Term* constructor();
+ };
+}
+#endif /* FL_BINARY_H */
diff --git a/fuzzylite/fl/term/Concave.h b/fuzzylite/fl/term/Concave.h
index b3aabe6..12d7160 100644
--- a/fuzzylite/fl/term/Concave.h
+++ b/fuzzylite/fl/term/Concave.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_CONCAVE_H
@@ -27,11 +19,21 @@
#include "fl/term/Term.h"
-
namespace fl {
+ /**
+ The Concave class is an edge Term that represents the concave membership
+ function.
+
+ @image html concave.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 5.0
+ */
class FL_API Concave : public Term {
- protected:
+ private:
scalar _inflection, _end;
public:
explicit Concave(const std::string& name = "",
@@ -42,15 +44,61 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Concave)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term as
+ @return `"inflection end [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters given
+ @param parameters as `"inflection end [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$\begin{cases}
+ h \times (e - i) / (2e - i - x) & \mbox{if $i \leq e \wedge x < e$
+ (increasing concave)} \cr
+ h \times (i - e) / (-2e + i + x) & \mbox{if $i > e \wedge x > e$
+ (decreasing concave)} \cr
+ h & \mbox{otherwise} \cr
+ \end{cases}@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$i@f$ is the inflection of the Concave,
+ @f$e@f$ is the end of the Concave
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ virtual scalar tsukamoto(scalar activationDegree,
+ scalar minimum, scalar maximum) const FL_IOVERRIDE;
+
+ virtual bool isMonotonic() const FL_IOVERRIDE;
+
+ /**
+ Sets the inflection of the curve
+ @param inflection is the inflection of the curve
+ */
virtual void setInflection(scalar inflection);
+ /**
+ Gets the inflection of the curve
+ @return the inflection of the curve
+ */
virtual scalar getInflection() const;
+ /**
+ Sets the end of the curve
+ @param end is the end of the curve
+ */
virtual void setEnd(scalar end);
+ /**
+ Gets the end of the curve
+ @return the end of the curve
+ */
virtual scalar getEnd() const;
virtual Concave* clone() const FL_IOVERRIDE;
@@ -58,7 +106,5 @@ namespace fl {
static Term* constructor();
};
}
-
-
#endif /* FL_CONCAVE_H */
diff --git a/fuzzylite/fl/term/Constant.h b/fuzzylite/fl/term/Constant.h
index c4ed17d..40ba77b 100644
--- a/fuzzylite/fl/term/Constant.h
+++ b/fuzzylite/fl/term/Constant.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_CONSTANT_H
@@ -29,8 +21,17 @@
namespace fl {
+ /**
+ The Constant class is a (zero) polynomial Term that represents a constant
+ value @f$ f(x) = k @f$
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API Constant : public Term {
- protected:
+ private:
scalar _value;
public:
@@ -40,12 +41,35 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Constant)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"value"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"value"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x is irrelevant
+ @return @f$c@f$, where @f$c@f$ is the constant value
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ /**
+ Sets the constant value
+ @param value is the constant value
+ */
virtual void setValue(scalar value);
+ /**
+ Gets the constant value
+ @return the constant value
+ */
virtual scalar getValue() const;
virtual Constant* clone() const FL_IOVERRIDE;
@@ -53,6 +77,5 @@ namespace fl {
static Term* constructor();
};
}
-
#endif /* FL_CONSTANT_H */
diff --git a/fuzzylite/fl/term/Cosine.h b/fuzzylite/fl/term/Cosine.h
index 510669f..b45ab85 100644
--- a/fuzzylite/fl/term/Cosine.h
+++ b/fuzzylite/fl/term/Cosine.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_COSINE_H
@@ -29,8 +21,20 @@
namespace fl {
+ /**
+ The Cosine class is an extended Term that represents the cosine
+ membership function.
+
+ @image html cosine.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 5.0
+ */
+
class FL_API Cosine : public Term {
- protected:
+ private:
scalar _center, _width;
public:
explicit Cosine(const std::string& name = "",
@@ -41,15 +45,51 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Cosine)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"center width [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"center width [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$\begin{cases}
+ 0h & \mbox{if $x < c - 0.5w \vee x > c + 0.5w$} \cr
+ 0.5h \times ( 1 + \cos(2.0 / w\pi(x-c))) & \mbox{otherwise}
+ \end{cases}@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$c@f$ is the center of the Cosine,
+ @f$w@f$ is the width of the Cosine
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
-
+ /**
+ Sets the center of the cosine
+ @param center is the center of the cosine
+ */
virtual void setCenter(scalar center);
+ /**
+ Gets the center of the cosine
+ @return the center of the cosine
+ */
virtual scalar getCenter() const;
+ /**
+ Sets the width of the cosine
+ @param width is the width of the cosine
+ */
virtual void setWidth(scalar width);
+ /**
+ Gets the width of the cosine
+ @return the width of the cosine
+ */
virtual scalar getWidth() const;
virtual Cosine* clone() const FL_IOVERRIDE;
@@ -57,6 +97,5 @@ namespace fl {
static Term* constructor();
};
}
-
#endif /* FL_COSINE_H */
diff --git a/fuzzylite/fl/term/Discrete.h b/fuzzylite/fl/term/Discrete.h
index fc554b3..ba5ae70 100644
--- a/fuzzylite/fl/term/Discrete.h
+++ b/fuzzylite/fl/term/Discrete.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_DISCRETE_H
@@ -27,15 +19,30 @@
#include "fl/term/Term.h"
+#include "fl/defuzzifier/IntegralDefuzzifier.h"
+
#include <vector>
#include <utility>
namespace fl {
+ /**
+ The Discrete class is a basic Term that represents a discrete membership
+ function. The pairs of values in any Discrete term **must** be sorted
+ ascendently because the membership function is computed using binary search
+ to find the lower and upper bounds of @f$x@f$.
+
+ @image html discrete.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API Discrete : public Term {
public:
typedef std::pair<scalar, scalar> Pair;
- protected:
+ private:
std::vector<Pair> _xy;
public:
explicit Discrete(const std::string& name = "",
@@ -45,37 +52,229 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Discrete)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term as `x1 y1 xn yn [height]`
+ @return `x1 y1 xn yn [height]`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters given as `x1 y1 xn yn [height]`
+ @param parameters as `x1 y1 xn yn [height]`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
- //Warning: this method is unsafe. Make sure you use it correctly.
- template <typename T>
- static Discrete* create(const std::string& name, int argc,
- T x1, T y1, ...); // throw (fl::Exception);
+ /**
+ Ascendantly sorts the given pairs of values by the @f$x@f$-value,
+ as it is required by the Discrete term.
+ @param pairs is a vector of pairs of values in the form @f$(x,y)@f$
+ */
+ static void sort(std::vector<Pair>& pairs);
+
+ /**
+ Ascendantly sorts the pairs of values in this Discrete term by the
+ @f$x@f$-coordinate
+ */
+ virtual void sort();
+
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the membership function evaluated at @f$x@f$ by using binary
+ search to find the lower and upper bounds of @f$x@f$ and then linearly
+ interpolating the membership function between the bounds.
+ @param x
+ @return @f$ \dfrac{h (y_{\max} - y_{\min})}{(x_{\max}- x_{\min})} (x - x_{\min}) + y_{\min}@f$
+ where @f$h@f$ is the height of the Term,
+ @f$x_{\min}@f$ and @f$x_{\max}@f$is are the lower and upper limits
+ of @f$x@f$ in `xy` (respectively),
+ @f$y_{\min}@f$ and @f$y_{\max}@f$is are the membership functions
+ of @f$\mu(x_{\min})@f$ and @f$\mu(x_{\max})@f$ (respectively)
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ /**
+ Sets the vector of pairs defining the discrete membership function
+ @param pairs is the vector of pairs defining the discrete membership function
+ */
virtual void setXY(const std::vector<Pair>& pairs);
+ /**
+ Gets an immutable vector of pairs defining the discrete membership function
+ @return an immutable vector of pairs defining the discrete membership function
+ */
virtual const std::vector<Pair>& xy() const;
+ /**
+ Gets a mutable vector of pairs defining the discrete membership function
+ @return a mutable vector of pairs defining the discrete membership function
+ */
virtual std::vector<Pair>& xy();
- virtual const Pair& xy(int index) const;
- virtual Pair& xy(int index);
+ /**
+ Gets the immutable pair @f$(x_i,y_i)@f$ at index @f$i@f$
+ @param index is the index @f$i@f$
+ @return the immutable pair @f$(x_i,y_i)@f$
+ */
+ virtual const Pair& xy(std::size_t index) const;
+ /**
+ Gets the mutable pair @f$(x_i,y_i)@f$ at index @f$i@f$
+ @param index is the index @f$i@f$
+ @return a mutable pair @f$(x_i,y_i)@f$
+ */
+ virtual Pair& xy(std::size_t index);
+
+ /**
+ Creates, fills and returns a vector containing the @f$x@f$ values
+ @return a vector containing the @f$x@f$ values
+ */
+ virtual std::vector<scalar> x() const;
+
+ /**
+ Gets the @f$x@f$ value at the given index
+ @return the @f$x@f$ value at the given index
+ */
+ virtual scalar x(std::size_t index) const;
+ /**
+ Gets the reference to the @f$x@f$ value at the given index
+ @return the reference to the @f$x@f$ value at the given index
+ */
+ virtual scalar& x(std::size_t index);
+ /**
+ Creates, fills and returns a vector containing the @f$y@f$ values
+ @return a vector containing the @f$y@f$ values
+ */
+ virtual std::vector<scalar> y() const;
+
+ /**
+ Gets the @f$y@f$ value at the given index
+ @param index is the index
+ @return the @f$y@f$ value at the given index
+ */
+ virtual scalar y(std::size_t index) const;
+
+ /**
+ Gets the reference to the @f$y@f$ value at the given index
+ @param index is the index
+ @return the reference to the @f$y@f$ value at the given index
+ */
+ virtual scalar& y(std::size_t index);
+ /**
+ Creates a vector of fl::scalar from a vector of Pair given in the
+ form @f$\left(\{x_1,y_1\},...,\{x_n,y_n\}\right)@f$
+ @param xy is the vector of Pair
+ @return a vector of fl::scalar as @f$(x_1,y_1,...,x_n,y_n)@f$
+ */
static std::vector<scalar> toVector(const std::vector<Pair>& xy);
+ /**
+ Creates a vector of Pair from a vector of fl::scalar given in the
+ form @f$(x_1,y_1,...,x_n,y_n)@f$
+ @param xy is a vector of fl::scalar given as
+ @f$(x_1,y_1,...,x_n,y_n)@f$
+ @return a vector of Pair in the form
+ @f$\left(\{x_1,y_1\},...,\{x_n,y_n\}\right)@f$
+ @throws fl::Exception if a value is missing, that is, if the length
+ of @f$xy@f$ is odd: @f$|xy|\mod 2 = 1@f$
+ */
static std::vector<Pair> toPairs(const std::vector<scalar>& xy);
+ /**
+ Creates a vector of Pair from a vector of fl::scalar given in the
+ form @f$(x_1,y_1,...,x_n,y_n)@f$
+ @param xy is a vector of fl::scalar given as
+ @f$(x_1,y_1,...,x_n,y_n)@f$ possibly missing a value
+ @param missingValue is the replacement in the case a value is missing
+ from @f$xy@f$
+ @return a vector of Pair in the form
+ @f$\left(\{x_1,y_1\},...,\{x_n,y_n\}\right)@f$
+ */
static std::vector<Pair> toPairs(const std::vector<scalar>& xy,
scalar missingValue) FL_INOEXCEPT;
+ /**
+ Formats a vector of Pair into a std::string in the form
+ @f$(x_1,y_1) ... (x_n,y_n)@f$
+ @param xy is the vector of Pair
+ @param prefix indicates the prefix of a Pair, e.g., `(` results in
+ @f$(x_i@f$
+ @param innerSeparator indicates the separator between
+ @f$x@f$ and @f$y@f$, e.g., `,` results in @f$x_i,y_i@f$
+ @param suffix indicates the postfix of a Pair, e.g., `]` results in
+ @f$y_i]@f$
+ @param outerSeparator indicates the separator between Pair, e.g.,
+ `;` results in @f$(x_i,y_i);(x_j,y_j)@f$
+ @return a formatted string containing the pairs of @f$(x,y)@f$ values
+ */
static std::string formatXY(const std::vector<Pair>& xy,
const std::string& prefix = "(", const std::string& innerSeparator = ",",
- const std::string& postfix = ")", const std::string& outerSeparator = " ");
+ const std::string& suffix = ")", const std::string& outerSeparator = " ");
+
+ /**
+ Discretizes the given term
+ @param term is the term to discretize
+ @param start is the value from which discretization starts
+ @param end is the value at which discretization ends
+ @param resolution is the number of equally-distributed samples to
+ perform between start and end
+ @param boundedMembershipFunction indicates whether to ensure that
+ @f$\mu(x)\in[0.0,1.0]@f$
+ @return a Discrete term that approximates the given term
+ */
+ static Discrete* discretize(const Term* term, scalar start, scalar end,
+ int resolution = IntegralDefuzzifier::defaultResolution(),
+ bool boundedMembershipFunction = true);
virtual Discrete* clone() const FL_IOVERRIDE;
static Term* constructor();
+ /**
+ Creates a Discrete term from a variadic set of values.
+ Beware: this method is unsafe and must be used with care by
+ ensuring:
+ - the value `argc` correctly and exactly determines the number of
+ values passed,
+ - the data type of each variadic arguments is the same, e.g.,
+ @f$(1.0, 2.0, 3.0)@f$ are all fl::scalar, whereas in
+ @f$(1.0, 2, 3.0)@f$ the second term is an integer, which will cause
+ memory access issues due to the difference in size between
+ `int` and `fl::scalar`.
+ @param name is the name of the resulting term
+ @param argc is the number of values passed
+ @param x1 is the @f$x@f$ value of the first Pair
+ @param y1 is the @f$y@f$ value of the first Pair
+ @param ... are the remaining pairs of values @f$x_i@f$ and @f$y_i@f$
+ @return a new Discrete term with the given parameters
+ */
+ template <typename T>
+ static Discrete* create(const std::string& name, int argc,
+ T x1, T y1, ...);
};
+}
+
+/**
+ Template implementation
+ */
+
+namespace fl {
+
+ template <typename T>
+ inline Discrete* Discrete::create(const std::string& name, int argc,
+ T x1, T y1, ...) {
+ std::vector<scalar> xy(argc);
+ xy.at(0) = x1;
+ xy.at(1) = y1;
+ va_list args;
+ va_start(args, y1);
+ for (int i = 2; i < argc; ++i) {
+ xy.at(i) = (scalar) va_arg(args, T);
+ }
+ va_end(args);
+ FL_unique_ptr<Discrete> result(new Discrete(name));
+ if (xy.size() % 2 != 0) {
+ result->setHeight(xy.back());
+ xy.pop_back();
+ }
+ result->setXY(toPairs(xy));
+ return result.release();
+ }
}
#endif /* FL_DISCRETE_H */
diff --git a/fuzzylite/fl/term/Function.h b/fuzzylite/fl/term/Function.h
index 99580b7..14e3427 100644
--- a/fuzzylite/fl/term/Function.h
+++ b/fuzzylite/fl/term/Function.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_FUNCTION_H
@@ -34,27 +26,77 @@ namespace fl {
class Engine;
+ /**
+ The Function class is a polynomial Term that represents a generic
+ function @f$ f : x \mapsto f(x) @f$. Every Function object has a public
+ key-value map, namely Function::variables, that links variable names to
+ fl::scalar values, which are utilized to replace the variable names for
+ their respective values in the given formula whenever the function
+ @f$f@f$ is evaluated. Specifically, when the method
+ Function::membership() is called, the name and value of the variable
+ @f$x@f$ are automatically loaded into the map. Furthermore, if an Engine
+ is given, the names of its InputVariable%s and OutputVariable%s will also
+ be automatically loaded into the map linking to their respective input
+ values and (previously defuzzified) output values. The
+ Function::variables need to be manually loaded whenever variables other
+ than @f$x@f$, input variables, and output variables, are expressed in the
+ given formula, always having in mind that (a) the map replaces existing
+ keys, and (b) the variable @f$x@f$, and input variables and output
+ variables of an engine will automatically be replaced and will also take
+ precedence over previously loaded variables.
+
+ Besides the use of Function as a linguistic Term, it is also utilized to
+ convert the text of the Antecedent of a Rule, expressed in infix
+ notation, into postfix notation.
+
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @see FunctionFactory
+ @see Antecedent::load()
+ @since 4.0
+ */
class FL_API Function : public Term {
- /****************************
- * Parsing Elements
- ****************************/
-
public:
typedef scalar(*Unary)(scalar);
typedef scalar(*Binary)(scalar, scalar);
+ /**
+ The Element class represents a single element in a formula, be that
+ either a function or an operator. If the Element represents a
+ function, the function can be Unary or Binary, that is, the function
+ take one or two parameters (respectively). Else, if the Element
+ represents an operator, the parameters to be defined are its `arity`,
+ its `precedence`, and its `associativity`.
+ */
struct FL_API Element {
+ /**
+ Determines the type of the element
+ */
enum Type {
- OPERATOR, FUNCTION
+ Operator, Function
};
+ /**Name of the element*/
std::string name;
+ /**Description of the element*/
std::string description;
+ /**Type of the element*/
Type type;
+ /**Pointer to unary method*/
Unary unary;
+ /**Pointer to binary method*/
Binary binary;
+ /**Number of operands required*/
int arity;
- int precedence; //Operator
+ /**Precedence of the element: clarifies which procedures should be
+ performed first in a given mathematical expression
+ (https://en.wikipedia.org/wiki/Order_of_operations)*/
+ int precedence;
+ /**Associativity of the element: determines how operators of the
+ same precedence are grouped in the absence of parentheses
+ (https://en.wikipedia.org/wiki/Operator_associativity)*/
int associativity;
Element(const std::string& name, const std::string& description, Type type);
Element(const std::string& name, const std::string& description,
@@ -64,24 +106,46 @@ namespace fl {
virtual ~Element();
FL_DEFAULT_COPY_AND_MOVE(Element)
+ /**
+ Indicates whether the element is a Type::Operator
+ @return whether the element is a Type::Operator
+ */
virtual bool isOperator() const;
+ /**
+ Indicates whether the element is a Type::Function
+ @return whether the element is a Type::Function
+ */
virtual bool isFunction() const;
-
+ /**
+ Clones the element
+ @return a clone of the element
+ */
virtual Element* clone() const;
+ /**
+ Returns a description of the element and its members
+ @return a description of the element and its members
+ */
virtual std::string toString() const;
};
- /**************************
- * Tree elements, wrap Elements into Nodes.
- **************************/
-
+ /**
+ The Node class structures a binary tree by storing pointers to a left
+ Node and a right Node, and storing its content as a
+ Function::Element, the name of an InputVariable or OutputVariable, or
+ a constant value.
+ */
struct FL_API Node {
+ /**The node takes an operation or a function*/
FL_unique_ptr<Element> element;
+ /**The node can have an expression tree on the left*/
FL_unique_ptr<Node> left;
+ /**The node can have an expression tree on the right*/
FL_unique_ptr<Node> right;
+ /**The node can refer to a variable by name*/
std::string variable;
+ /**The node can take an arbitrary floating-point value*/
scalar value;
explicit Node(Element* element, Node* left = fl::null, Node* right = fl::null);
@@ -92,14 +156,79 @@ namespace fl {
virtual ~Node();
FL_DEFAULT_MOVE(Node)
+ /**
+ Evaluates the node and substitutes the variables therein for the
+ values passed in the map. The expression tree is evaluated
+ recursively.
+
+ @param variables is a map of substitutions of variable names for
+ fl::scalar%s
+
+ @return a fl::scalar indicating the result of the evaluation of
+ the node
+ */
virtual scalar evaluate(const std::map<std::string, scalar>*
variables = fl::null) const;
+ /**
+ Computes the size of the subtree under the given node. The complexity
+ of calling this method is O(n).
+ @param node is the root of the subtree, which is this node if
+ fl::null is given
+ @return the size of the subtree under the given node
+ */
+ virtual std::size_t treeSize(const Node* node = fl::null) const;
+
+ /**
+ Computes the size of the subtree under the given node whose elements
+ are of the given type. The complexity of calling this method is O(n).
+ @param type is the type of elements to account for
+ @param node is the root of the subtree, which is this node if
+ fl::null is given
+ @return
+ */
+ virtual std::size_t treeSize(Element::Type type,
+ const Node* node = fl::null) const;
+
+ /**
+ Creates a clone of the node.
+ @return a clone of the node
+ */
virtual Node* clone() const;
+ /**
+ Returns a string with the name of the element, the name of the
+ variable, or the constant value, accordingly.
+ @return a string with the name of the element, the name of the
+ variable, or the constant value, accordingly.
+ */
virtual std::string toString() const;
+ /**
+ Returns a prefix representation of the expression tree under the
+ given node
+ @param node is the node to start the prefix representation from.
+ If the node is `fl::null`, then the starting point is `this` node
+ @return a prefix representation of the expression tree under the
+ given node
+ */
virtual std::string toPrefix(const Node* node = fl::null) const;
+ /**
+ Returns an infix representation of the expression tree under the
+ given node
+ @param node is the node to start the infix representation from.
+ If the node is `fl::null`, then the starting point is `this` node
+ @return an infix representation of the expression tree under the
+ given node
+ */
virtual std::string toInfix(const Node* node = fl::null) const;
+ /**
+ Returns a postfix representation of the expression tree under the
+ given node
+ @param node is the node to start the postfix representation from.
+ If the node is `fl::null`, then the starting point is `this` node
+ @return a postfix representation of the expression tree under the
+ given node
+ */
virtual std::string toPostfix(const Node* node = fl::null) const;
private:
void copyFrom(const Node& source);
@@ -112,11 +241,12 @@ namespace fl {
* Term
******************************/
- protected:
+ private:
FL_unique_ptr<Node> _root;
std::string _formula;
const Engine* _engine;
public:
+ /**A map of variables and substitution values**/
mutable std::map<std::string, scalar> variables;
explicit Function(const std::string& name = "",
const std::string& formula = "", const Engine* engine = fl::null);
@@ -125,47 +255,145 @@ namespace fl {
virtual ~Function() FL_IOVERRIDE;
FL_DEFAULT_MOVE(Function)
+ /**
+ Creates a Function term with the given parameters
+ @param name is the name of the term
+ @param formula is the formula defining the membership function
+ @param engine is the engine to which the Function can have access
+ @return a Function term configured with the given parameters
+ @throws fl::Exception if the formula has a syntax error
+ */
static Function* create(const std::string& name,
const std::string& formula,
- const Engine* engine = fl::null); // throw (fl::Exception);
-
+ const Engine* engine = fl::null);
+
+ virtual Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the membership function value of @f$x@f$ at the root node.
+ If the engine has been set, the current values of the input variables
+ and output variables are added to the map of Function::variables. In
+ addition, the variable @f$x@f$ will also be added to the map.
+ @param x
+ @return the membership function value of @f$x@f$ at the root node
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
- virtual scalar evaluate(const std::map<std::string, scalar>* variables) const;
+ /**
+ Computes the function value of this term using the given map of
+ variable substitutions.
+ @param variables is a map of substitution variables
+ @return the function value of this term using the given map of
+ variable substitutions.
+ */
+ virtual scalar evaluate(const std::map<std::string, scalar>* variables = fl::null) const;
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term as `formula`
+ @return `formula`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters given as `formula`
+ @param parameters as `formula`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ /**
+ Sets the formula of the function
+ @param formula is the formula of the function
+ */
virtual void setFormula(const std::string& formula);
+ /**
+ Gets the formula of the function
+ @return the formula of the function
+ */
virtual std::string getFormula() const;
+ /**
+ Sets the engine to which the formula can refer
+ @param engine is the engine to which the formula can refer
+ */
virtual void setEngine(const Engine* engine);
+ /**
+ Gets the engine to which the formula can refer
+ @return the engine to which the formula can refer
+ */
virtual const Engine* getEngine() const;
+ /**
+ Gets the root node of the expression tree defining the Function. The
+ root is `fl::null` if the formula has not been loaded.
+ @return the root node of the expression tree defining the Function,
+ or `fl::null` if the formula has not been loaded
+ */
virtual Node* root() const;
+ /**
+ Indicates whether the formula is loaded
+ @return whether the formula is loaded
+ */
virtual bool isLoaded() const;
+ /**
+ Unloads the formula and resets the map of substitution variables.
+ */
virtual void unload();
- virtual void load(); // throw (fl::Exception);
- virtual void load(const std::string& formula); // throw (fl::Exception);
- virtual void load(const std::string& formula, const Engine* engine); // throw (fl::Exception);
-
- virtual Node* parse(const std::string& formula); // throw (fl::Exception);
-
- virtual std::string toPostfix(const std::string& formula) const; //throw (fl::Exception);
-
+ /**
+ Loads the current formula expressed in infix notation
+ */
+ virtual void load();
+ /**
+ Loads the given formula expressed in infix notation
+ @param formula is the right-hand side of a mathematical equation
+ @throws fl::Exception if the formula has syntax errors
+ */
+ virtual void load(const std::string& formula);
+ /**
+ Loads the given formula expressed in infix notation, and sets the
+ engine holding the variables to which the formula refers.
+ @param formula is the right-hand side of a mathematical equation
+ expressed in infix notation
+ @param engine is the engine to which the formula can refer
+ @throws fl::Exception if the formula has syntax errors
+ */
+ virtual void load(const std::string& formula, const Engine* engine);
+ /**
+ Creates a node representing a binary expression tree from the given formula
+ @param formula is the right-hand side of a mathematical equation
+ expressed in infix notation
+ @return a node representing a binary expression tree from the given formula
+ @throws fl::Exception if the formula has syntax errors
+ */
+ virtual Node* parse(const std::string& formula);
+
+ /**
+ Translates the given formula to postfix notation
+ @param formula is the right-hand side of a mathematical equation
+ expressed in infix notation
+ @return the formula represented in postfix notation
+ @throws fl::Exception if the formula has syntax errors
+ */
+ virtual std::string toPostfix(const std::string& formula) const;
+
+ /**
+ Adds spaces to the formula to separate parentheses, commas and
+ function operators such that these are treated as tokens when parsing
+ the function.
+ @param formula is the right-hand side of a mathematical equation
+ expressed in infix notation
+ @return the formula with spaces before and after parentheses, commas
+ and function operators
+ */
virtual std::string space(const std::string& formula) const;
+ virtual void updateReference(const Engine* engine) FL_IOVERRIDE;
+
virtual Function* clone() const FL_IOVERRIDE;
static Term* constructor();
- static void main();
-
};
-
}
-
#endif /* FL_FUNCTION_H */
diff --git a/fuzzylite/fl/term/Gaussian.h b/fuzzylite/fl/term/Gaussian.h
index a5b8055..9a7475d 100644
--- a/fuzzylite/fl/term/Gaussian.h
+++ b/fuzzylite/fl/term/Gaussian.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_GAUSSIAN_H
@@ -29,8 +21,19 @@
namespace fl {
+ /**
+ The Gaussian class is an extended Term that represents the %Gaussian
+ curve membership function.
+
+ @image html gaussian.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API Gaussian : public Term {
- protected:
+ private:
scalar _mean;
scalar _standardDeviation;
@@ -43,21 +46,54 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Gaussian)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"mean standardDeviation [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"mean standardDeviation [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$ h \times \exp(-(x-\mu)^2/(2\sigma^2))@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$\mu@f$ is the mean of the Gaussian,
+ @f$\sigma@f$ is the standard deviation of the Gaussian
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
- virtual void setMean(scalar c);
+ /**
+ Sets the mean of the Gaussian curve
+ @param mean is the mean of the Gaussian curve
+ */
+ virtual void setMean(scalar mean);
+ /**
+ Gets the mean of the Gaussian curve
+ @return the mean of the Gaussian curve
+ */
virtual scalar getMean() const;
- virtual void setStandardDeviation(scalar sigma);
+ /**
+ Sets the standard deviation of the Gaussian curve
+ @param standardDeviation is the standard deviation of the Gaussian curve
+ */
+ virtual void setStandardDeviation(scalar standardDeviation);
+ /**
+ Gets the standard deviation of the Gaussian curve
+ @return the standard deviation of the Gaussian curve
+ */
virtual scalar getStandardDeviation() const;
virtual Gaussian* clone() const FL_IOVERRIDE;
static Term* constructor();
};
-
}
#endif /* FL_GAUSSIAN_H */
diff --git a/fuzzylite/fl/term/GaussianProduct.h b/fuzzylite/fl/term/GaussianProduct.h
index bd1eaaa..e4a500c 100644
--- a/fuzzylite/fl/term/GaussianProduct.h
+++ b/fuzzylite/fl/term/GaussianProduct.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_GAUSSIANPRODUCT_H
@@ -29,8 +21,19 @@
namespace fl {
+ /**
+ The GaussianProduct class is an extended Term that represents the
+ two-sided %Gaussian membership function.
+
+ @image html gaussianProduct.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API GaussianProduct : public Term {
- protected:
+ private:
scalar _meanA;
scalar _standardDeviationA;
scalar _meanB;
@@ -47,21 +50,83 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(GaussianProduct)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Provides the parameters of the term
+ @return `"meanA standardDeviationA meanB standardDeviationB [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"meanA standardDeviationA meanB
+ standardDeviationB [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$ h \left((1 - i) + i \times \exp(-(x - \mu_a)^2 /
+ (2\sigma_a^2))\right)
+ \left((1 - j) + j \times \exp(-(x - \mu_b)^2 / (2 \sigma_b)^2)\right)
+ @f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$\mu_a@f$ is the mean of the first GaussianProduct,
+ @f$\sigma_a@f$ is the standard deviation of the first
+ GaussianProduct,
+ @f$\mu_b@f$ is the mean of the second GaussianProduct,
+ @f$\sigma_b@f$ is the standard deviation of the second
+ GaussianProduct,
+ @f$i=\begin{cases}1 & \mbox{if $x \leq \mu_a$} \cr 0
+ &\mbox{otherwise}\end{cases}@f$,
+ @f$j=\begin{cases}1 & \mbox{if $x \geq \mu_b$} \cr 0
+ &\mbox{otherwise}\end{cases}@f$
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ /**
+ Sets the mean of the first %Gaussian curve
+ @param meanA is the mean of the first %Gaussian curve
+ */
virtual void setMeanA(scalar meanA);
+ /**
+ Gets the mean of the first %Gaussian curve
+ @return the mean of the first %Gaussian curve
+ */
virtual scalar getMeanA() const;
- virtual void setStandardDeviationA(scalar sigmaA);
+ /**
+ Sets the standard deviation of the first %Gaussian curve
+ @param standardDeviationA is the standard deviation of the first %Gaussian curve
+ */
+ virtual void setStandardDeviationA(scalar standardDeviationA);
+ /**
+ Gets the standard deviation of the first %Gaussian curve
+ @return the standard deviation of the first %Gaussian curve
+ */
virtual scalar getStandardDeviationA() const;
+ /**
+ Sets the mean of the second %Gaussian curve
+ @param meanB is the mean of the second %Gaussian curve
+ */
virtual void setMeanB(scalar meanB);
+ /**
+ Gets the mean of the second %Gaussian curve
+ @return the mean of the second %Gaussian curve
+ */
virtual scalar getMeanB() const;
- virtual void setStandardDeviationB(scalar sigmaB);
+ /**
+ Sets the standard deviation of the second %Gaussian curve
+ @param standardDeviationB is the standard deviation of the second %Gaussian curve
+ */
+ virtual void setStandardDeviationB(scalar standardDeviationB);
+ /**
+ Gets the standard deviation of the second %Gaussian curve
+ @return the standard deviation of the second %Gaussian curve
+ */
virtual scalar getStandardDeviationB() const;
virtual GaussianProduct* clone() const FL_IOVERRIDE;
diff --git a/fuzzylite/fl/term/Linear.h b/fuzzylite/fl/term/Linear.h
index 67ede04..1105a1d 100644
--- a/fuzzylite/fl/term/Linear.h
+++ b/fuzzylite/fl/term/Linear.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_LINEAR_H
@@ -30,8 +22,23 @@
namespace fl {
class Engine;
+ /**
+ The Linear class is a linear polynomial Term expressed as @f$f(x)=
+ \mathbf{c}\mathbf{v}+k = \sum_i c_iv_i + k@f$, where variable @f$x@f$ is
+ not utilized, @f$\mathbf{v}@f$ is a vector of values from the input
+ variables, @f$\mathbf{c}@f$ is a vector of coefficients, and @f$k@f$ is a
+ constant. Hereinafter, the vector @f$\mathbf{c}^\star=\{c_1, \ldots, c_i,
+ \ldots, c_n, k\}@f$ refers to a vector containing the coefficients of
+ @f$\mathbf{c}@f$ and the constant @f$k@f$.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API Linear : public Term {
- protected:
+ private:
+ /**Contains the coefficients @f$c_i@f$ and the constant @f$k@f$*/
std::vector<scalar> _coefficients;
const Engine* _engine;
public:
@@ -42,31 +49,131 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Linear)
virtual std::string className() const FL_IOVERRIDE;
+
+ /**
+ Returns the vector @f$\mathbf{c}^\star@f$
+ @return `"c1 ... ci ... cn k"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the values of @f$\mathbf{c}^\star@f$
+ @param parameters as `"c1 ... ci ... cn k"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
- virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
- virtual void set(const std::vector<scalar>& coeffs, const Engine* engine);
+ /**
+ Computes the linear function @f$f(x)=\sum_i c_iv_i +k@f$,
+ where @f$v_i@f$ is the value of the input variable @f$i@f$ registered
+ in the Linear::getEngine()
+ @param x is not utilized
+ @return @f$\sum_i c_ix_i +k@f$
+ */
+ virtual scalar membership(scalar x) const FL_IOVERRIDE;
- virtual void setCoefficients(const std::vector<scalar>& coeffs);
+ /**
+ Sets the vector @f$\mathbf{c}^\star@f$ and the Engine from which
+ vector @f$\mathbf{v}@f$ will be retrieved when necessary
+ @param coefficients is the vector @f$\mathbf{c}^\star@f$
+ @param engine is the engine from which @f$\mathbf{v}@f$ will be
+ retrieved when necessary
+ */
+ virtual void set(const std::vector<scalar>& coefficients, const Engine* engine);
+
+ /**
+ Sets the vector @f$\mathbf{c}^\star@f$ of the linear function
+ @param coefficients is the vector @f$\mathbf{c}^\star@f$
+ */
+ virtual void setCoefficients(const std::vector<scalar>& coefficients);
+ /**
+ Gets the immutable vector @f$\mathbf{c}^\star@f$
+ @return the immutable vector @f$\mathbf{c}^\star@f$
+ */
virtual const std::vector<scalar>& coefficients() const;
+ /**
+ Gets the mutable vector @f$\mathbf{c}^\star@f$
+ @return the mutable vector @f$\mathbf{c}^\star@f$
+ */
virtual std::vector<scalar>& coefficients();
+ /**
+ Sets the engine from which the vector @f$\mathbf{v}@f$ will be
+ obtained upon computing the Linear::membership()
+ @param engine is the engine from which the vector @f$\mathbf{v}@f$
+ will be obtained
+ */
virtual void setEngine(const Engine* engine);
+ /**
+ Gets the engine from which the vector @f$\mathbf{v}@f$ will be
+ obtained upon computing the Linear::membership()
+ @return the engine from which the vector @f$\mathbf{v}@f$ will be
+ obtained
+ */
virtual const Engine* getEngine() const;
virtual Linear* clone() const FL_IOVERRIDE;
+ virtual void updateReference(const Engine* engine) FL_IOVERRIDE;
+
static Term* constructor();
- //Warning: this method is unsafe, make sure you use it correctly.
+ /**
+ Creates a Linear term from a variadic set of coefficients.
+ Beware: this method is unsafe and must be used with care by
+ ensuring:
+
+ - the data type of each variadic arguments is the same, e.g.,
+ @f$(1.0, 2.0, 3.0)@f$ are all fl::scalar%s. You *need* to avoid the
+ case of @f$(1.0, 2, 3.0)@f$, where the second term will be
+ considered as an `int` (different from the others) and cause memory
+ issues due to the difference in size between an `int` and
+ `fl::scalar`; and
+
+ - the number of variadic arguments is exactly the same as the number
+ of input variables in the engine plus one in order to match the
+ size of the vector @f$\mathbf{c}^\star@f$
+
+ @param name is the name of the term
+ @param engine is the engine from which the vector @f$\mathbf{v}@f$
+ will be obtained
+ @param firstCoefficient is the coefficient for the first input
+ variable, namely @f$c_1@f$
+ @param ... is a variadic number of coefficients whose type need to be
+ the same as the first coefficient
+ @return a new Linear term with the given parameters
+ */
template <typename T>
static Linear* create(const std::string& name, const Engine* engine,
- T firstCoefficient, ...); // throw (fl::Exception);
+ T firstCoefficient, ...);
};
-
}
+/**
+ Template implementation
+ */
+
+#include "fl/Engine.h"
+
+namespace fl {
+
+ template <typename T>
+ inline Linear* Linear::create(const std::string& name,
+ const Engine* engine, T firstCoefficient, ...) {
+ if (not engine) throw Exception("[linear error] cannot create term <" + name + "> "
+ "without a reference to the engine", FL_AT);
+ std::vector<scalar> coefficients;
+ coefficients.push_back((scalar) firstCoefficient);
+
+ va_list args;
+ va_start(args, firstCoefficient);
+ for (std::size_t i = 0; i < engine->inputVariables().size(); ++i) {
+ coefficients.push_back((scalar) va_arg(args, T));
+ }
+ va_end(args);
+
+ return new Linear(name, coefficients, engine);
+ }
+}
#endif /* FL_LINEAR_H */
diff --git a/fuzzylite/fl/term/PiShape.h b/fuzzylite/fl/term/PiShape.h
index a0c2f78..24e98ed 100644
--- a/fuzzylite/fl/term/PiShape.h
+++ b/fuzzylite/fl/term/PiShape.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_PISHAPE_H
@@ -29,8 +21,19 @@
namespace fl {
+ /**
+ The PiShape class is an extended Term that represents the Pi-shaped curve
+ membership function.
+
+ @image html piShape.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API PiShape : public Term {
- protected:
+ private:
scalar _bottomLeft;
scalar _topLeft;
scalar _topRight;
@@ -47,21 +50,82 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(PiShape)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"bottomLeft topLeft topRight bottomRight [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"bottomLeft topLeft topRight bottomRight
+ [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$\begin{cases}
+ 0h & \mbox{if $x \leq b_l$}\cr
+ 2h \left((x - b_l) / (t_l-b_l)\right)^2 & \mbox{if $x \leq 0.5(a+b)$}\cr
+ h (1 - 2 \left((x - t_l) / (t_l-b_l)\right)^2) & \mbox{if $ x < t_l$}\cr
+ h & \mbox{if $x \leq t_r$}\cr
+ h (1 - 2\left((x - t_r) / (b_r - t_r)\right)^2) & \mbox{if $x \leq 0.5(t_r + b_r)$}\cr
+ 2h \left((x - b_r) / (b_r-t_r)\right)^2 & \mbox{if $x < b_r$} \cr
+ 0h & \mbox{otherwise}
+ \end{cases}@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$b_l@f$ is the bottom left of the PiShape,
+ @f$t_l@f$ is the top left of the PiShape,
+ @f$t_r@f$ is the top right of the PiShape
+ @f$b_r@f$ is the bottom right of the PiShape,
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
- virtual void setBottomLeft(scalar a);
+ /**
+ Sets the bottom-left value of the curve
+ @param bottomLeft is the bottom-left value of the curve
+ */
+ virtual void setBottomLeft(scalar bottomLeft);
+ /**
+ Gets the bottom-left value of the curve
+ @return the bottom-left value of the curve
+ */
virtual scalar getBottomLeft() const;
- virtual void setTopLeft(scalar b);
+ /**
+ Sets the top-left value of the curve
+ @param topLeft is the top-left value of the curve
+ */
+ virtual void setTopLeft(scalar topLeft);
+ /**
+ Gets the top-left value of the curve
+ @return the top-left value of the curve
+ */
virtual scalar getTopLeft() const;
- virtual void setTopRight(scalar d);
+ /**
+ Sets the top-right value of the curve
+ @param topRight is the top-right value of the curve
+ */
+ virtual void setTopRight(scalar topRight);
+ /**
+ Gets the top-right value of the curve
+ @return the top-right value of the curve
+ */
virtual scalar getTopRight() const;
- virtual void setBottomRight(scalar c);
+ /**
+ Sets the bottom-right value of the curve
+ @param bottomRight is the bottom-right value of the curve
+ */
+ virtual void setBottomRight(scalar bottomRight);
+ /**
+ Gets the bottom-right value of the curve
+ @return the bottom-right value of the curve
+ */
virtual scalar getBottomRight() const;
virtual PiShape* clone() const FL_IOVERRIDE;
@@ -69,6 +133,5 @@ namespace fl {
static Term* constructor();
};
}
-
#endif /* FL_PISHAPE_H */
diff --git a/fuzzylite/fl/term/Ramp.h b/fuzzylite/fl/term/Ramp.h
index 63a683c..dc49301 100644
--- a/fuzzylite/fl/term/Ramp.h
+++ b/fuzzylite/fl/term/Ramp.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_RAMP_H
@@ -29,14 +21,30 @@
namespace fl {
+ /**
+ The Ramp class is an edge Term that represents the ramp membership
+ function.
+
+ @image html ramp.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API Ramp : public Term {
- protected:
+ private:
scalar _start, _end;
public:
+ /**
+ Direction is an enumerator that indicates the direction of the ramp.
+ */
enum Direction {
- POSITIVE, ZERO, NEGATIVE
+ /** `(_/)` increases to the right */ Positive,
+ /** `(--)` slope is zero */ Zero,
+ /** `(\\_)` increases to the left */ Negative
};
explicit Ramp(const std::string& name = "",
scalar start = fl::nan,
@@ -46,17 +54,76 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Ramp)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"start end [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"start end [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return
+ @f$\begin{cases}
+
+ 0h & \mbox{if $x = e$}\cr
+
+ \begin{cases}
+ 0h & \mbox{if $x \leq s$}\cr
+ 1h & \mbox{if $x \geq e$}\cr
+ h (x - s) / (e - s) & \mbox{otherwise}\cr
+ \end{cases} & \mbox{if $s < e$}\cr
+
+ \begin{cases}
+ 0h & \mbox{if $x \geq s$}\cr
+ 1h & \mbox{if $x \leq e$}\cr
+ h (s - x) / (s - e) & \mbox{otherwise}
+ \end{cases} & \mbox{if $s > e$}\cr
+ \end{cases}@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$s@f$ is the start of the Ramp,
+ @f$e@f$ is the end of the Ramp
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ virtual scalar tsukamoto(scalar activationDegree,
+ scalar minimum, scalar maximum) const FL_IOVERRIDE;
+
+ virtual bool isMonotonic() const FL_IOVERRIDE;
+
+ /**
+ Sets the start of the ramp
+ @param start is the start of the ramp
+ */
virtual void setStart(scalar start);
+ /**
+ Gets the start of the ramp
+ @return the start of the ramp
+ */
virtual scalar getStart() const;
+ /**
+ Sets the end of the ramp
+ @param end is the end of the ramp
+ */
virtual void setEnd(scalar end);
+ /**
+ Gets the end of the ramp
+ @return the end of the ramp
+ */
virtual scalar getEnd() const;
+ /**
+ Returns the direction of the ramp
+ @return the direction of the ramp
+ */
virtual Direction direction() const;
virtual Ramp* clone() const FL_IOVERRIDE;
diff --git a/fuzzylite/fl/term/Rectangle.h b/fuzzylite/fl/term/Rectangle.h
index 23b5eda..0e29cd2 100644
--- a/fuzzylite/fl/term/Rectangle.h
+++ b/fuzzylite/fl/term/Rectangle.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_RECTANGLE_H
@@ -29,8 +21,19 @@
namespace fl {
+ /**
+ The Rectangle class is a basic Term that represents the rectangle
+ membership function.
+
+ @image html rectangle.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API Rectangle : public Term {
- protected:
+ private:
scalar _start, _end;
public:
@@ -42,21 +45,58 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Rectangle)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"start end [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"start end [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$\begin{cases}
+ 1h & \mbox{if $x \in [s, e]$} \cr
+ 0h & \mbox{otherwise}
+ \end{cases}@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$s@f$ is the start of the Rectangle,
+ @f$e@f$ is the end of the Rectangle.
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ /**
+ Sets the start of the rectangle
+ @param start is the start of the rectangle
+ */
virtual void setStart(scalar start);
+ /**
+ Gets the start of the rectangle
+ @return the start of the rectangle
+ */
virtual scalar getStart() const;
+ /**
+ Sets the end of the rectangle
+ @param end is the end of the rectangle
+ */
virtual void setEnd(scalar end);
+ /**
+ Gets the end of the rectangle
+ @return the end of the rectangle
+ */
virtual scalar getEnd() const;
virtual Rectangle* clone() const FL_IOVERRIDE;
static Term* constructor();
};
-
}
#endif /* FL_RECTANGLE_H */
diff --git a/fuzzylite/fl/term/SShape.h b/fuzzylite/fl/term/SShape.h
index 0891357..1d107a5 100644
--- a/fuzzylite/fl/term/SShape.h
+++ b/fuzzylite/fl/term/SShape.h
@@ -1,28 +1,19 @@
/*
- 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_SSHAPE_H
#define FL_SSHAPE_H
@@ -30,8 +21,19 @@
namespace fl {
+ /**
+ The SShape class is an edge Term that represents the S-shaped membership
+ function.
+
+ @image html sShape.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API SShape : public Term {
- protected:
+ private:
scalar _start, _end;
public:
@@ -43,15 +45,59 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(SShape)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"start end [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"start end [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$\begin{cases}
+ 0h & \mbox{if $x \leq s$} \cr
+ h(2 \left((x - s) / (e-s)\right)^2) & \mbox{if $x \leq 0.5(s+e)$}\cr
+ h(1 - 2\left((x - e) / (e-s)\right)^2) & \mbox{if $x < e$}\cr
+ 1h & \mbox{otherwise}
+ \end{cases}@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$s@f$ is the start of the SShape,
+ @f$e@f$ is the end of the SShape.
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ virtual scalar tsukamoto(scalar activationDegree,
+ scalar minimum, scalar maximum) const FL_IOVERRIDE;
+
+ virtual bool isMonotonic() const FL_IOVERRIDE;
+
+ /**
+ Sets the start of the edge
+ @param start is the start of the edge
+ */
virtual void setStart(scalar start);
+ /**
+ Gets the start of the edge
+ @return the start of the edge
+ */
virtual scalar getStart() const;
+ /**
+ Sets the end of the edge
+ @param end is the end of the edge
+ */
virtual void setEnd(scalar end);
+ /**
+ Gets the end of the edge
+ @return the end of the edge
+ */
virtual scalar getEnd() const;
virtual SShape* clone() const FL_IOVERRIDE;
@@ -59,6 +105,5 @@ namespace fl {
static Term* constructor();
};
}
-
#endif /* FL_SSHAPE_H */
diff --git a/fuzzylite/fl/term/Sigmoid.h b/fuzzylite/fl/term/Sigmoid.h
index b37b1be..bde9c2f 100644
--- a/fuzzylite/fl/term/Sigmoid.h
+++ b/fuzzylite/fl/term/Sigmoid.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_SIGMOID_H
@@ -29,14 +21,31 @@
namespace fl {
+ /**
+ The Sigmoid class is an edge Term that represents the sigmoid membership
+ function.
+
+ @image html sigmoid.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API Sigmoid : public Term {
- protected:
+ private:
scalar _inflection;
scalar _slope;
public:
+ /**
+ Direction is an enumerator that indicates the direction of the
+ sigmoid.
+ */
enum Direction {
- POSITIVE, ZERO, NEGATIVE
+ /** `(_/)` increases to the right */ Positive,
+ /** `(--)` slope is zero */ Zero,
+ /** `(\\_)` increases to the left */ Negative
};
explicit Sigmoid(const std::string& name = "",
scalar inflection = fl::nan,
@@ -46,23 +55,66 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Sigmoid)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"inflection slope [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"inflection slope [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$ h / (1 + \exp(-s(x-i)))@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$s@f$ is the slope of the Sigmoid,
+ @f$i@f$ is the inflection of the Sigmoid
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ virtual scalar tsukamoto(scalar activationDegree,
+ scalar minimum, scalar maximum) const FL_IOVERRIDE;
+
+ virtual bool isMonotonic() const FL_IOVERRIDE;
+
+ /**
+ Sets the inflection of the sigmoid
+ @param inflection is the inflection of the sigmoid
+ */
virtual void setInflection(scalar inflection);
+ /**
+ Gets the inflection of the sigmoid
+ @return the inflection of the sigmoid
+ */
virtual scalar getInflection() const;
+ /**
+ Sets the slope of the sigmoid
+ @param slope is the slope of the sigmoid
+ */
virtual void setSlope(scalar slope);
+ /**
+ Gets the slope of the sigmoid
+ @return the slope of the sigmoid
+ */
virtual scalar getSlope() const;
+ /**
+ Returns the direction of the sigmoid
+ @return the direction of the sigmoid
+ */
virtual Direction direction() const;
virtual Sigmoid* clone() const FL_IOVERRIDE;
static Term* constructor();
};
-
}
#endif /* FL_SIGMOID_H */
diff --git a/fuzzylite/fl/term/SigmoidDifference.h b/fuzzylite/fl/term/SigmoidDifference.h
index 020f164..4861584 100644
--- a/fuzzylite/fl/term/SigmoidDifference.h
+++ b/fuzzylite/fl/term/SigmoidDifference.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_SIGMOIDDIFFERENCE_H
@@ -29,8 +21,19 @@
namespace fl {
+ /**
+ The SigmoidDifference class is an extended Term that represents the
+ difference between two sigmoidal membership functions.
+
+ @image html sigmoidDifference.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API SigmoidDifference : public Term {
- protected:
+ private:
scalar _left;
scalar _rising;
scalar _falling;
@@ -47,21 +50,76 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(SigmoidDifference)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"left rising falling right [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"left rising falling right [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$ h (a-b)@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$a= 1 / (1 + \exp(-s_l \times (x - i_l))) @f$,
+ @f$b = 1 / (1 + \exp(-s_r \times (x - i_r)))@f$,
+ @f$i_l@f$ is the left inflection of the SigmoidDifference,
+ @f$s_l@f$ is the left slope of the SigmoidDifference,
+ @f$i_r@f$ is the right inflection of the SigmoidDifference,
+ @f$s_r@f$ is the right slope of the SigmoidDifference
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ /**
+ Sets the inflection of the left sigmoidal curve
+ @param leftInflection is the inflection of the left sigmoidal curve
+ */
virtual void setLeft(scalar leftInflection);
+ /**
+ Gets the inflection of the left sigmoidal curve
+ @return the inflection of the left sigmoidal curve
+ */
virtual scalar getLeft() const;
+ /**
+ Sets the slope of the left sigmoidal curve
+ @param risingSlope is the slope of the left sigmoidal curve
+ */
virtual void setRising(scalar risingSlope);
+ /**
+ Gets the slope of the left sigmoidal curve
+ @return the slope of the left sigmoidal curve
+ */
virtual scalar getRising() const;
+ /**
+ Sets the slope of the right sigmoidal curve
+ @param fallingSlope is the slope of the right sigmoidal curve
+ */
virtual void setFalling(scalar fallingSlope);
+ /**
+ Gets the slope of the right sigmoidal curve
+ @return the slope of the right sigmoidal curve
+ */
virtual scalar getFalling() const;
+ /**
+ Sets the inflection of the right sigmoidal curve
+ @param rightInflection is the inflection of the right sigmoidal curve
+ */
virtual void setRight(scalar rightInflection);
+ /**
+ Gets the inflection of the right sigmoidal curve
+ @return the inflection of the right sigmoidal curve
+ */
virtual scalar getRight() const;
virtual SigmoidDifference* clone() const FL_IOVERRIDE;
diff --git a/fuzzylite/fl/term/SigmoidProduct.h b/fuzzylite/fl/term/SigmoidProduct.h
index cb83f30..19cd4d7 100644
--- a/fuzzylite/fl/term/SigmoidProduct.h
+++ b/fuzzylite/fl/term/SigmoidProduct.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_SIGMOIDPRODUCT_H
@@ -29,8 +21,19 @@
namespace fl {
+ /**
+ The SigmoidProduct class is an extended Term that represents the product
+ of two sigmoidal membership functions.
+
+ @image html sigmoidProduct.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API SigmoidProduct : public Term {
- protected:
+ private:
scalar _left;
scalar _rising;
scalar _falling;
@@ -47,23 +50,79 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(SigmoidProduct)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"left rising falling right [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"left rising falling right [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$ h (a \times b)@f$
+
+ where @f$h@f$ is the height,
+ @f$a= 1 / (1 + \exp(-s_l *\times (x - i_l))) @f$,
+ @f$b = 1 / (1 + \exp(-s_r \times (x - i_r)))@f$,
+ @f$i_l@f$ is the left inflection of the SigmoidProduct,
+ @f$s_l@f$ is the left slope of the SigmoidProduct,
+ @f$i_r@f$ is the right inflection of the SigmoidProduct,
+ @f$s_r@f$ is the right slope of the SigmoidProduct
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ /**
+ Sets the inflection of the left sigmoidal curve
+ @param leftInflection is the inflection of the left sigmoidal curve
+ */
virtual void setLeft(scalar leftInflection);
+ /**
+ Gets the inflection of the left sigmoidal curve
+ @return the inflection of the left sigmoidal curve
+ */
virtual scalar getLeft() const;
+ /**
+ Sets the slope of the left sigmoidal curve
+ @param risingSlope is the slope of the left sigmoidal curve
+ */
virtual void setRising(scalar risingSlope);
+ /**
+ Gets the slope of the left sigmoidal curve
+ @return the slope of the left sigmoidal curve
+ */
virtual scalar getRising() const;
+ /**
+ Sets the slope of the right sigmoidal curve
+ @param fallingSlope is the slope of the right sigmoidal curve
+ */
virtual void setFalling(scalar fallingSlope);
+ /**
+ Gets the slope of the right sigmoidal curve
+ @return the slope of the right sigmoidal curve
+ */
virtual scalar getFalling() const;
+ /**
+ Sets the inflection of the right sigmoidal curve
+ @param rightInflection is the inflection of the right sigmoidal curve
+ */
virtual void setRight(scalar rightInflection);
+ /**
+ Gets the inflection of the right sigmoidal curve
+ @return the inflection of the right sigmoidal curve
+ */
virtual scalar getRight() const;
+
virtual SigmoidProduct* clone() const FL_IOVERRIDE;
static Term* constructor();
diff --git a/fuzzylite/fl/term/Spike.h b/fuzzylite/fl/term/Spike.h
index 7e520c9..7349307 100644
--- a/fuzzylite/fl/term/Spike.h
+++ b/fuzzylite/fl/term/Spike.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_SPIKE_H
@@ -29,8 +21,19 @@
namespace fl {
+ /**
+ The Spike class is an extended Term that represents the spike membership
+ function.
+
+ @image html spike.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 5.0
+ */
class FL_API Spike : public Term {
- protected:
+ private:
scalar _center, _width;
public:
explicit Spike(const std::string& name = "",
@@ -41,15 +44,49 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Spike)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"center width [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"center width [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$h \times \exp(-|10 / w (x - c)|)@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$w@f$ is the width of the Spike,
+ @f$c@f$ is the center of the Spike
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ /**
+ Sets the center of the spike
+ @param center is the center of the spike
+ */
virtual void setCenter(scalar center);
+ /**
+ Gets the center of the spike
+ @return the center of the spike
+ */
virtual scalar getCenter() const;
+ /**
+ Sets the width of the spike
+ @param width is the width of the spike
+ */
virtual void setWidth(scalar width);
+ /**
+ Gets the width of the spike
+ @return the width of the spike
+ */
virtual scalar getWidth() const;
virtual Spike* clone() const FL_IOVERRIDE;
@@ -57,6 +94,5 @@ namespace fl {
static Term* constructor();
};
}
-
#endif /* FL_SPIKE_H */
diff --git a/fuzzylite/fl/term/Term.h b/fuzzylite/fl/term/Term.h
index 6c2b2b1..31dcabd 100644
--- a/fuzzylite/fl/term/Term.h
+++ b/fuzzylite/fl/term/Term.h
@@ -1,34 +1,26 @@
/*
- 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_TERM_H
#define FL_TERM_H
#include "fl/fuzzylite.h"
#include "fl/Operation.h"
+#include "fl/Complexity.h"
#include <cmath>
#include <string>
@@ -37,9 +29,33 @@
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 {
- protected:
+ private:
std::string _name;
+ protected:
scalar _height;
public:
@@ -47,25 +63,103 @@ namespace fl {
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;
-
- //FIXME: This should not be static, and may not be here either.
- static void updateReference(Term* term, const Engine* engine);
- };
+ /**
+ 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 */
diff --git a/fuzzylite/fl/term/Trapezoid.h b/fuzzylite/fl/term/Trapezoid.h
index f896997..ebf5ed8 100644
--- a/fuzzylite/fl/term/Trapezoid.h
+++ b/fuzzylite/fl/term/Trapezoid.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_TRAPEZOID_H
@@ -29,8 +21,19 @@
namespace fl {
+ /**
+ The Trapezoid class is a basic Term that represents the trapezoidal
+ membership function.
+
+ @image html trapezoid.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API Trapezoid : public Term {
- protected:
+ private:
scalar _vertexA, _vertexB, _vertexC, _vertexD;
public:
explicit Trapezoid(const std::string& name = "",
@@ -43,27 +46,84 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Trapezoid)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"vertexA vertexB vertexC vertexD [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"vertexA vertexB vertexC vertexD [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$\begin{cases}
+ 0h & \mbox{if $x \not\in[a,d]$}\cr
+ h \times \min(1, (x - a) / (b - a)) & \mbox{if $x < b$}\cr
+ 1h & \mbox{if $x \leq c$}\cr
+ h (d - x) / (d - c) & \mbox{if $x < d$}\cr
+ 0h & \mbox{otherwise}
+ \end{cases}@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$a@f$ is the first vertex of the Trapezoid,
+ @f$b@f$ is the second vertex of the Trapezoid,
+ @f$c@f$ is the third vertex of the Trapezoid,
+ @f$d@f$ is the fourth vertex of the Trapezoid
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ /**
+ Sets the first vertex of the trapezoid
+ @param a is the first vertex of the trapezoid
+ */
virtual void setVertexA(scalar a);
+ /**
+ Gets the first vertex of the trapezoid
+ @return the first vertex of the trapezoid
+ */
virtual scalar getVertexA() const;
+ /**
+ Sets the second vertex of the trapezoid
+ @param b is the second vertex of the trapezoid
+ */
virtual void setVertexB(scalar b);
+ /**
+ Gets the second vertex of the trapezoid
+ @return the second vertex of the trapezoid
+ */
virtual scalar getVertexB() const;
+ /**
+ Sets the third vertex of the trapezoid
+ @param c is the third vertex of the trapezoid
+ */
virtual void setVertexC(scalar c);
+ /**
+ Gets the third vertex of the trapezoid
+ @return the third vertex of the trapezoid
+ */
virtual scalar getVertexC() const;
+ /**
+ Sets the fourth vertex of the trapezoid
+ @param d is the fourth vertex of the trapezoid
+ */
virtual void setVertexD(scalar d);
+ /**
+ Gets the fourth vertex of the trapezoid
+ @return the fourth vertex of the trapezoid
+ */
virtual scalar getVertexD() const;
virtual Trapezoid* clone() const FL_IOVERRIDE;
static Term* constructor();
};
-
}
#endif /* FL_TRAPEZOID_H */
diff --git a/fuzzylite/fl/term/Triangle.h b/fuzzylite/fl/term/Triangle.h
index 9311687..8b16fa9 100644
--- a/fuzzylite/fl/term/Triangle.h
+++ b/fuzzylite/fl/term/Triangle.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_TRIANGLE_H
@@ -29,8 +21,19 @@
namespace fl {
+ /**
+ The Triangle class is a basic Term that represents the triangular
+ membership function.
+
+ @image html triangle.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
class FL_API Triangle : public Term {
- protected:
+ private:
scalar _vertexA;
scalar _vertexB;
scalar _vertexC;
@@ -44,18 +47,66 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(Triangle)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"vertexA vertexB vertexC [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"vertexA vertexB vertexC [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$\begin{cases}
+ 0h & \mbox{if $x \not\in [a,c]$}\cr
+ 1h & \mbox{if $x = b$}\cr
+ h (x - a) / (b - a) & \mbox{if $x < b$} \cr
+ h (c - x) / (c - b) & \mbox{otherwise}
+ \end{cases}@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$a@f$ is the first vertex of the Triangle,
+ @f$b@f$ is the second vertex of the Triangle,
+ @f$c@f$ is the third vertex of the Triangle
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ /**
+ Sets the first vertex of the triangle
+ @param a is the first vertex of the triangle
+ */
virtual void setVertexA(scalar a);
+ /**
+ Gets the first vertex of the triangle
+ @return the first vertex of the triangle
+ */
virtual scalar getVertexA() const;
+ /**
+ Sets the second vertex of the triangle
+ @param b is the second vertex of the triangle
+ */
virtual void setVertexB(scalar b);
+ /**
+ Gets the second vertex of the triangle
+ @return the second vertex of the triangle
+ */
virtual scalar getVertexB() const;
+ /**
+ Sets the third vertex of the triangle
+ @param c is the third vertex of the triangle
+ */
virtual void setVertexC(scalar c);
+ /**
+ Gets the third vertex of the triangle
+ @return the third vertex of the triangle
+ */
virtual scalar getVertexC() const;
virtual Triangle* clone() const FL_IOVERRIDE;
@@ -63,6 +114,5 @@ namespace fl {
static Term* constructor();
};
-
}
#endif /* FL_TRIANGLE_H */
diff --git a/fuzzylite/fl/term/ZShape.h b/fuzzylite/fl/term/ZShape.h
index b53906e..1737891 100644
--- a/fuzzylite/fl/term/ZShape.h
+++ b/fuzzylite/fl/term/ZShape.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_ZSHAPE_H
@@ -29,8 +21,20 @@
namespace fl {
+ /**
+ The ZShape class is an edge Term that represents the Z-shaped membership
+ function.
+
+ @image html zShape.svg
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Term
+ @see Variable
+ @since 4.0
+ */
+
class FL_API ZShape : public Term {
- protected:
+ private:
scalar _start, _end;
public:
@@ -42,15 +46,59 @@ namespace fl {
FL_DEFAULT_COPY_AND_MOVE(ZShape)
virtual std::string className() const FL_IOVERRIDE;
+ /**
+ Returns the parameters of the term
+ @return `"start end [height]"`
+ */
virtual std::string parameters() const FL_IOVERRIDE;
+ /**
+ Configures the term with the parameters
+ @param parameters as `"start end [height]"`
+ */
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
+ virtual Complexity complexity() const FL_IOVERRIDE;
+ /**
+ Computes the membership function evaluated at @f$x@f$
+ @param x
+ @return @f$ \begin{cases}
+ 1h & \mbox{if $x \leq s$} \cr
+ h(1 - 2\left((x - s) / (e-s)\right)^2) & \mbox{if $x \leq 0.5(s+e)$}\cr
+ h(2 \left((x - e) / (e-s)\right)^2) & \mbox{if $x < e$}\cr
+ 0h & \mbox{otherwise}
+ \end{cases}@f$
+
+ where @f$h@f$ is the height of the Term,
+ @f$s@f$ is the start of the ZShape,
+ @f$e@f$ is the end of the ZShape.
+ */
virtual scalar membership(scalar x) const FL_IOVERRIDE;
+ virtual scalar tsukamoto(scalar activationDegree,
+ scalar minimum, scalar maximum) const FL_IOVERRIDE;
+
+ virtual bool isMonotonic() const FL_IOVERRIDE;
+
+ /**
+ Sets the start of the edge
+ @param start is the start of the edge
+ */
virtual void setStart(scalar start);
+ /**
+ Gets the start of the edge
+ @return the start of the edge
+ */
virtual scalar getStart() const;
+ /**
+ Sets the end of the edge
+ @param end is the end of the edge
+ */
virtual void setEnd(scalar end);
+ /**
+ Gets the end of the edge
+ @return the end of the edge
+ */
virtual scalar getEnd() const;
virtual ZShape* clone() const FL_IOVERRIDE;
diff --git a/fuzzylite/fl/variable/InputVariable.h b/fuzzylite/fl/variable/InputVariable.h
index bba3c7d..3201e3d 100644
--- a/fuzzylite/fl/variable/InputVariable.h
+++ b/fuzzylite/fl/variable/InputVariable.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_INPUTVARIABLE_H
@@ -29,9 +21,17 @@
namespace fl {
+ /**
+ The InputVariable class is a Variable that represents an input of the
+ fuzzy logic controller.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Variable
+ @see OutputVariable
+ @see Term
+ @since 4.0
+ */
class FL_API InputVariable : public Variable {
- protected:
- scalar _inputValue;
public:
explicit InputVariable(const std::string& name = "",
scalar minimum = -fl::inf,
@@ -39,14 +39,22 @@ namespace fl {
virtual ~InputVariable() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(InputVariable)
- virtual void setInputValue(scalar inputValue);
- virtual scalar getInputValue() const;
+ /**
+ Evaluates the membership function of the current input value @f$x@f$
+ for each term @f$i@f$, resulting in a fuzzy input value in the form
+ @f$\tilde{x}=\sum_i{\mu_i(x)/i}@f$. This is equivalent to a call to
+ Variable::fuzzify() passing @f$x@f$ as input value
+ @return the fuzzy input value expressed as @f$\sum_i{\mu_i(x)/i}@f$
+ */
virtual std::string fuzzyInputValue() const;
+ virtual Variable::Type type() const FL_IOVERRIDE;
+
virtual std::string toString() const FL_IOVERRIDE;
- };
+ virtual InputVariable* clone() const FL_IOVERRIDE;
+ };
}
#endif /* FL_INPUTVARIABLE_H */
diff --git a/fuzzylite/fl/variable/OutputVariable.h b/fuzzylite/fl/variable/OutputVariable.h
index 9d00aaf..b79b13c 100644
--- a/fuzzylite/fl/variable/OutputVariable.h
+++ b/fuzzylite/fl/variable/OutputVariable.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_OUTPUTVARIABLE_H
@@ -27,64 +19,208 @@
#include "fl/variable/Variable.h"
+#include "fl/term/Activated.h"
+#include "fl/term/Aggregated.h"
+
+#include "fl/defuzzifier/Defuzzifier.h"
+
namespace fl {
- class Accumulated;
- class Defuzzifier;
+ /**
+ The OutputVariable class is a Variable that represents an output of the
+ fuzzy logic controller. During the activation of a RuleBlock, the
+ Activated terms of each Rule will be Aggregated in the
+ OutputVariable::fuzzyOutput(), which represents a fuzzy set hereinafter
+ referred to as @f$\tilde{y}@f$. The defuzzification of @f$\tilde{y}@f$
+ translates the fuzzy output value @f$\tilde{y}@f$ into a crisp output
+ value @f$y@f$, which can be retrieved using Variable::getValue(). The
+ value of the OutputVariable is computed and automatically stored when
+ calling OutputVariable::defuzzify(), but the value depends on the
+ following properties (expressed in the FuzzyLite Language):
+
+ - Property `default: scalar` overrides the output value @f$y@f$ with
+ the given fl::scalar whenever the defuzzification process results in
+ a non-finite value (i.e., fl::nan and fl::inf). For example,
+ considering `default: 0.0`, if RuleBlock::activate() does not
+ activate any rules whose Consequent contribute to the OutputVariable,
+ then the fuzzy output value is empty, the Defuzzifier does not
+ operate, and hence @f$y=0.0@f$. By default, `default: NaN`. Relevant
+ methods are OutputVariable::getDefaultValue() and
+ OutputVariable::setDefaultValue().
+
+ - Property `lock-previous: boolean`, if enabled, overrides the output
+ value @f$y^t@f$ at time @f$t@f$ with the previously defuzzified valid
+ output value @f$y^{t-1}@f$ if defuzzification process results in a
+ non-finite value (i.e., fl::nan and fl::inf). When enabled, the
+ property takes precedence over `default` if @f$y^{t-1}@f$ is a finite
+ value. By default, `lock-previous: false`, @f$y^{t-1}=\mbox{NaN}@f$
+ for @f$t=0@f$, and @f$y^{t-1}=\mbox{NaN}@f$ when
+ OutputVariable::clear(). Relevant methods are
+ OutputVariable::lockPreviousValue(),
+ OutputVariable::isLockPreviousValue,
+ OutputVariable::getPreviousValue(), and
+ OutputVariable::setPreviousValue().
+
+ - Property `lock-range: boolean` overrides the output value @f$y@f$ to
+ enforce it lies within the range of the variable determined by
+ Variable::getMinimum() and Variable::getMaximum(). When enabled, this
+ property takes precedence over `lock-previous` and `default`. For
+ example, considering `range: -1.0 1.0` and `lock-range: true`,
+ @f$y=-1.0@f$ if the result from the Defuzzifier is smaller than
+ `-1.0`, and @f$y=1.0@f$ if the result from the Defuzzifier is greater
+ than `1.0`. The property `lock-range` was introduced in version 5.0
+ to substitute the property `lock-valid` in version 4.0. By default,
+ `lock-range: false`. Relevant methods are
+ Variable::lockValueInRange(), Variable::isLockValueInRange(),
+ Variable::getMinimum(), and Variable::getMaximum()
+
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see Variable
+ @see InputVariable
+ @see RuleBlock::activate()
+ @see Term
+ @since 4.0
+ */
class FL_API OutputVariable : public Variable {
private:
- void copyFrom(const OutputVariable& other);
- protected:
- FL_unique_ptr<Accumulated> _fuzzyOutput;
+ FL_unique_ptr<Aggregated> _fuzzyOutput;
FL_unique_ptr<Defuzzifier> _defuzzifier;
- scalar _outputValue;
- scalar _previousOutputValue;
+ scalar _previousValue;
scalar _defaultValue;
- bool _lockOutputValueInRange;
- bool _lockPreviousOutputValue;
+ bool _lockPreviousValue;
+
+ void copyFrom(const OutputVariable& other);
public:
explicit OutputVariable(const std::string& name = "",
scalar minimum = -fl::inf, scalar maximum = fl::inf);
- OutputVariable(const OutputVariable& other);
+ explicit OutputVariable(const OutputVariable& other);
OutputVariable& operator=(const OutputVariable& other);
virtual ~OutputVariable() FL_IOVERRIDE;
FL_DEFAULT_MOVE(OutputVariable)
- virtual Accumulated* fuzzyOutput() const;
+ /**
+ Gets the fuzzy output value @f$\tilde{y}@f$
+ @return the fuzzy output value @f$\tilde{y}@f$
+ @todo rename to fuzzyValue
+ */
+ virtual Aggregated* fuzzyOutput() const;
virtual void setName(const std::string& name) FL_IOVERRIDE;
virtual void setMinimum(scalar minimum) FL_IOVERRIDE;
virtual void setMaximum(scalar maximum) FL_IOVERRIDE;
+ /**
+ Sets the defuzzifier of the output variable
+ @param defuzzifier is the defuzzifier of the output variable
+ */
virtual void setDefuzzifier(Defuzzifier* defuzzifier);
+ /**
+ Gets the defuzzifier of the output variable
+ @return the defuzzifier of the output variable
+ */
virtual Defuzzifier* getDefuzzifier() const;
- virtual void setOutputValue(scalar outputValue);
- virtual scalar getOutputValue() const;
-
- virtual void setPreviousOutputValue(scalar defuzzifiedValue);
- virtual scalar getPreviousOutputValue() const;
-
+ /**
+ Sets the aggregation operator
+ @param aggregation is the aggregation
+ */
+ virtual void setAggregation(SNorm* aggregation);
+
+ /**
+ Gets the aggregation operator
+ @return the aggregation operator
+ */
+ virtual SNorm* getAggregation() const;
+
+ /**
+ Sets the previous value of the output variable
+ @param previousValue is the previous value of the output variable
+ */
+ virtual void setPreviousValue(scalar previousValue);
+ /**
+ Gets the previous value of the output variable
+ @return the previous value of the output variable
+ */
+ virtual scalar getPreviousValue() const;
+
+ /**
+ Sets the default value of the output variable
+ @param defaultValue is the default value of the output variable
+ */
virtual void setDefaultValue(scalar defaultValue);
+ /**
+ Gets the default value of the output variable
+ @return the default value of the output variable
+ */
virtual scalar getDefaultValue() const;
- virtual void setLockOutputValueInRange(bool lockOutputValueInRange);
- virtual bool isLockedOutputValueInRange() const;
-
- virtual void setLockPreviousOutputValue(bool lockPreviousOutputValue);
- virtual bool isLockedPreviousOutputValue() const;
-
+ /**
+ Sets whether to lock the previous value of the output variable
+ @param lockPreviousValue indicates whether to lock the previous value
+ of the output variable
+ */
+ virtual void setLockPreviousValue(bool lockPreviousValue);
+ /**
+ Gets whether to lock the previous value of the output variable
+ @return whether the previous output value of the output variable is
+ locked
+ */
+ virtual bool isLockPreviousValue() const;
+
+ using Variable::complexity;
+ /**
+ Computes the estimated complexity of defuzzifying the activated term
+ with the current configuration of the variable (namely aggregation and
+ defuzzifier
+ @param term is the activated term
+ @return the estimated complexity of defuzzifying the activated term
+ with the current configuration of the variable
+ */
+ virtual Complexity complexity(const Activated& term) const;
+ /**
+ Computes the estimated complexity of aggregating and defuzzifying all
+ the terms in the variable.
+ @return the estimated complexity of aggregating and defuzzifying all
+ the terms in the variable.
+ */
+ virtual Complexity complexityOfDefuzzification() const;
+
+ /**
+ Computes the estimated complexity of aggregating and defuzzifying the
+ terms currently found in the fuzzy output variable.
+ @return the estimated complexity of aggregating and defuzzifying the
+ terms currently found in the fuzzy output variable
+ */
+ virtual Complexity currentComplexity() const;
+
+ /**
+ Defuzzifies the output variable and stores the output value and the
+ previous output value
+ */
virtual void defuzzify();
+ /**
+ Gets a string representation of the fuzzy output value @f$\tilde{y}@f$
+ @return a string representation of the fuzzy output value
+ @f$\tilde{y}@f$
+ */
virtual std::string fuzzyOutputValue() const;
+ /**
+ Clears the output variable by setting @f$\tilde{y}=\{\}@f$,
+ @f$y^{t}=\mbox{NaN}@f$, @f$y^{t-1}=\mbox{NaN}@f$
+ */
virtual void clear();
+ virtual Variable::Type type() const FL_IOVERRIDE;
+
virtual std::string toString() const FL_IOVERRIDE;
- };
+ virtual OutputVariable* clone() const FL_IOVERRIDE;
+ };
}
#endif /* FL_OUTPUTVARIABLE_H */
diff --git a/fuzzylite/fl/variable/Variable.h b/fuzzylite/fl/variable/Variable.h
index 61870af..47530c0 100644
--- a/fuzzylite/fl/variable/Variable.h
+++ b/fuzzylite/fl/variable/Variable.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_VARIABLE_H
@@ -35,62 +27,272 @@ namespace fl {
class Term;
+ /**
+ The Variable class is the base class for linguistic variables.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see InputVariable
+ @see OutputVariable
+ @see Term
+ @since 4.0
+ */
class FL_API Variable {
- private:
- void copyFrom(const Variable& source);
+ public:
+ /**
+ Indicates the type of the variable to avoid costly `dynamic_casts`
+ */
+ enum Type {
+ None,
+ Input,
+ Output
+ };
protected:
std::string _name;
+ std::string _description;
std::vector<Term*> _terms;
+ scalar _value;
scalar _minimum, _maximum;
bool _enabled;
+ bool _lockValueInRange;
+
+ private:
+ void copyFrom(const Variable& source);
public:
explicit Variable(const std::string& name = "",
scalar minimum = -fl::inf,
scalar maximum = fl::inf);
- Variable(const Variable& other);
+ explicit Variable(const Variable& other);
Variable& operator=(const Variable& other);
virtual ~Variable();
FL_DEFAULT_MOVE(Variable)
+ /**
+ Sets the name of the variable
+ @param name is the name of the variable
+ */
virtual void setName(const std::string& name);
+
+ /**
+ Gets the name of the variable
+ @return the name of the variable
+ */
virtual std::string getName() const;
+ /**
+ Gets the description of the variable
+ @return the description of the variable
+ */
+ virtual std::string getDescription() const;
+
+ /**
+ Sets the description of the variable
+ @param description is the description of the variable
+ */
+ virtual void setDescription(const std::string& description);
+
+ /**
+ Sets the value of the variable
+ @param value is the input value of an InputVariable, or the output
+ value of an OutputVariable
+ */
+ virtual void setValue(scalar value);
+
+ /**
+ Gets the value of the variable
+ @return the input value of an InputVariable, or the output value of
+ an OutputVariable
+ */
+ virtual scalar getValue() const;
+
+ /**
+ Sets the range of the variable between `[minimum, maximum]`
+ @param minimum is the minimum value in range
+ @param maximum is the maximum value in range
+ */
virtual void setRange(scalar minimum, scalar maximum);
+ /**
+ Gets the magnitude of the range of the variable
+ @return `maximum - minimum`
+ */
virtual scalar range() const;
+ /**
+ Sets the minimum value of the range of the variable
+ @param minimum is the minimum value of the range
+ */
virtual void setMinimum(scalar minimum);
+ /**
+ Gets the minimum value of the range of the variable
+ @return the minimum value of the range of the variable
+ */
virtual scalar getMinimum() const;
+ /**
+ Sets the maximum value of the range of the variable
+ @param maximum is the maximum value of the range
+ */
virtual void setMaximum(scalar maximum);
+ /**
+ Gets the maximum value of the range of the variable
+ @return the maximum value of the range of the variable
+ */
virtual scalar getMaximum() const;
+ /**
+ Sets whether the variable is enabled
+ @param enabled determines whether to enable the variable
+ */
virtual void setEnabled(bool enabled);
+ /**
+ Gets whether the variable is enabled
+ @return whether the variable is enabled
+ */
virtual bool isEnabled() const;
+ /**
+ Sets whether the variable locks the current value to the range of the
+ variable.
+
+ If enabled in an InputVariable @f$i@f$, the input value @f$x_i@f$
+ will be used when computing the Antecedent::activationDegree() as
+ long as @f$x_i \in [\mbox{min}, \mbox{max}]@f$. Else, for the case of
+ @f$x_i \not\in [\mbox{min}, \mbox{max}]@f$, the range values will be
+ used instead but without changing the input value @f$x_i@f$.
+
+ If enabled in an OutputVariable @f$j@f$, the output value @f$y_j@f$
+ will be overriden by the range values when @f$y_j \not\in
+ [\mbox{min}, \mbox{max}]@f$. See OutputVariable for more information.
+
+ @param lockValueInRange indicates whether to lock the value to the
+ range of the variable
+ */
+ virtual void setLockValueInRange(bool lockValueInRange);
+
+ /**
+ Gets whether the variable locks the current value to the
+ range of the variable
+
+ If enabled in an InputVariable @f$i@f$, the input value @f$x_i@f$
+ will be used when computing the Antecedent::activationDegree() as
+ long as @f$x_i \in [\mbox{min}, \mbox{max}]@f$. Else, for the case of
+ @f$x_i \not\in [\mbox{min}, \mbox{max}]@f$, the range values will be
+ used instead but without changing the input value @f$x_i@f$.
+
+ If enabled in an OutputVariable @f$j@f$, the output value @f$y_j@f$
+ will be overriden by the range values when @f$y_j \not\in
+ [\mbox{min}, \mbox{max}]@f$. See OutputVariable for more information.
+
+ @return whether the variable locks the current value to the range of
+ the variable
+ */
+ virtual bool isLockValueInRange() const;
+
+ /**
+ Computes the aggregated complexity of the underlying terms
+ @return the aggregated complexity of the underlying terms
+ */
+ virtual Complexity complexity() const;
+
+ /**
+ Evaluates the membership function of value @f$x@f$ for each
+ term @f$i@f$, resulting in a fuzzy value in the form
+ @f$\tilde{x}=\sum_i{\mu_i(x)/i}@f$
+ @param x is the value to fuzzify
+ @return the fuzzy value expressed as @f$\sum_i{\mu_i(x)/i}@f$
+ */
virtual std::string fuzzify(scalar x) const;
+
+ /**
+ Gets the term which has the highest membership function value for
+ @f$x@f$.
+ @param x is the value of interest
+ @param[out] yhighest is a pointer where the highest membership
+ function value will be stored
+ @return the term @f$i@f$ which maximimizes @f$\mu_i(x)@f$
+ */
virtual Term* highestMembership(scalar x, scalar* yhighest = fl::null) const;
+ /**
+ Returns the type of the variable
+ @return the type of the variable
+ */
+ virtual Type type() const;
+
+ /**
+ Gets a string representation of the variable in the FuzzyLite Language
+ @return a string representation of the variable in the FuzzyLite
+ Language
+ @see FllExporter
+ */
virtual std::string toString() const;
/**
- * Operations for iterable datatype _terms
+ Sorts the terms in ascending order according to their centroids
*/
virtual void sort();
+ /**
+ Adds a term to the variable
+ @param term is the term to add
+ */
virtual void addTerm(Term* term);
- virtual void insertTerm(Term* term, int index);
- virtual Term* getTerm(int index) const;
+ /**
+ Inserts the term in the variable
+ @param term is the term to insert
+ @param index is the index where the term will be inserted
+ */
+ virtual void insertTerm(Term* term, std::size_t index);
+ /**
+ Gets the term at the given index
+ @param index is the position of the term in the vector
+ @return the term at the given index
+ */
+ virtual Term* getTerm(std::size_t index) const;
+ /**
+ Gets the term of the given name.
+ @param name is the name of the term to retrieve
+ @return the term of the given name
+ @throws Exception if the term is not found
+ */
virtual Term* getTerm(const std::string& name) const;
+ /**
+ Gets whether a term of the given name has been added
+ @param name the name of the term
+ @return whether the term of the given name is found
+ */
virtual bool hasTerm(const std::string& name) const;
- virtual Term* removeTerm(int index);
- virtual int numberOfTerms() const;
+ /**
+ Removes the term at the given index
+ @param index the index of the term to remove
+ @return the removed term
+ */
+ virtual Term* removeTerm(std::size_t index);
+ /**
+ Gets the number of terms added to the variable
+ @return the number of terms in the variable
+ */
+ virtual std::size_t numberOfTerms() const;
+ /**
+ Sets the terms of the variable
+ @param terms is a vector of terms
+ */
virtual void setTerms(const std::vector<Term*>& terms);
+ /**
+ Gets an immutable vector of the terms
+ @return an immutable vector of terms
+ */
virtual const std::vector<Term*>& terms() const;
+ /**
+ Gets a mutable vector of the terms
+ @return a mutable vector of terms
+ */
virtual std::vector<Term*>& terms();
-
+ /**
+ Creates a clone of the variable
+ @return a clone of the variable
+ */
+ virtual Variable* clone() const;
};
-
}
-
#endif /* FL_VARIABLE_H */