diff options
Diffstat (limited to 'fuzzylite/src/hedge')
-rw-r--r-- | fuzzylite/src/hedge/Any.cpp | 47 | ||||
-rw-r--r-- | fuzzylite/src/hedge/Extremely.cpp | 46 | ||||
-rw-r--r-- | fuzzylite/src/hedge/HedgeFunction.cpp | 63 | ||||
-rw-r--r-- | fuzzylite/src/hedge/Not.cpp | 41 | ||||
-rw-r--r-- | fuzzylite/src/hedge/Seldom.cpp | 45 | ||||
-rw-r--r-- | fuzzylite/src/hedge/Somewhat.cpp | 41 | ||||
-rw-r--r-- | fuzzylite/src/hedge/Very.cpp | 41 |
7 files changed, 324 insertions, 0 deletions
diff --git a/fuzzylite/src/hedge/Any.cpp b/fuzzylite/src/hedge/Any.cpp new file mode 100644 index 0000000..9d04262 --- /dev/null +++ b/fuzzylite/src/hedge/Any.cpp @@ -0,0 +1,47 @@ +/* + 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. + */ + +#include "fl/hedge/Any.h" + +namespace fl { + + Any::Any() { } + + Any::~Any() { } + + std::string Any::name() const { + return "any"; + } + + Complexity Any::complexity() const { + return Complexity(); + } + + scalar Any::hedge(scalar x) const { + FL_IUNUSED(x); + return 1.0; + } + + Any* Any::clone() const { + return new Any(*this); + } + + Hedge* Any::constructor() { + return new Any; + } + +} + diff --git a/fuzzylite/src/hedge/Extremely.cpp b/fuzzylite/src/hedge/Extremely.cpp new file mode 100644 index 0000000..60d3abd --- /dev/null +++ b/fuzzylite/src/hedge/Extremely.cpp @@ -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. + */ + +#include "fl/hedge/Extremely.h" + +#include "fl/Operation.h" + +namespace fl { + + std::string Extremely::name() const { + return "extremely"; + } + + Complexity Extremely::complexity() const { + return Complexity().comparison(1).arithmetic(5); + } + + scalar Extremely::hedge(scalar x) const { + return Op::isLE(x, 0.5) + ? 2.0 * x * x + : (1.0 - 2.0 * (1.0 - x) * (1.0 - x)); + } + + Extremely* Extremely::clone() const { + return new Extremely(*this); + } + + Hedge* Extremely::constructor() { + return new Extremely; + } + +} + diff --git a/fuzzylite/src/hedge/HedgeFunction.cpp b/fuzzylite/src/hedge/HedgeFunction.cpp new file mode 100644 index 0000000..c31c72c --- /dev/null +++ b/fuzzylite/src/hedge/HedgeFunction.cpp @@ -0,0 +1,63 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#include "fl/hedge/HedgeFunction.h" + +namespace fl { + + HedgeFunction::HedgeFunction(const std::string& formula) : Hedge() { + _function.variables["x"] = fl::nan; + if (not formula.empty()) { + _function.load(formula); + } + } + + std::string HedgeFunction::name() const { + return "HedgeFunction"; + } + + Complexity HedgeFunction::complexity() const { + if (_function.root()) + return _function.complexity().function(2 * std::log(scalar(_function.variables.size()))); + return _function.complexity(); + } + + scalar HedgeFunction::hedge(scalar x) const { + _function.variables["x"] = x; + return _function.membership(x); + } + + Function& HedgeFunction::function() { + return this->_function; + } + + void HedgeFunction::setFormula(const std::string& formula) { + _function.load(formula); + } + + std::string HedgeFunction::getFormula() const { + return _function.getFormula(); + } + + HedgeFunction* HedgeFunction::clone() const { + return new HedgeFunction(*this); + } + + Hedge* HedgeFunction::constructor() { + return new HedgeFunction; + } + +} diff --git a/fuzzylite/src/hedge/Not.cpp b/fuzzylite/src/hedge/Not.cpp new file mode 100644 index 0000000..defbabd --- /dev/null +++ b/fuzzylite/src/hedge/Not.cpp @@ -0,0 +1,41 @@ +/* + 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. + */ + +#include "fl/hedge/Not.h" + +namespace fl { + + std::string Not::name() const { + return "not"; + } + + Complexity Not::complexity() const { + return Complexity().arithmetic(1); + } + + scalar Not::hedge(scalar x) const { + return 1.0 - x; + } + + Not* Not::clone() const { + return new Not(*this); + } + + Hedge* Not::constructor() { + return new Not; + } + +} diff --git a/fuzzylite/src/hedge/Seldom.cpp b/fuzzylite/src/hedge/Seldom.cpp new file mode 100644 index 0000000..092e873 --- /dev/null +++ b/fuzzylite/src/hedge/Seldom.cpp @@ -0,0 +1,45 @@ +/* + 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. + */ + +#include "fl/hedge/Seldom.h" + +#include "fl/Operation.h" + +namespace fl { + + std::string Seldom::name() const { + return "seldom"; + } + + Complexity Seldom::complexity() const { + return Complexity().comparison(1).function(1).arithmetic(3); + } + + scalar Seldom::hedge(scalar x) const { + return Op::isLE(x, 0.5) + ? std::sqrt(0.5 * x) + : (1.0 - std::sqrt(0.5 * (1.0 - x))); + } + + Seldom* Seldom::clone() const { + return new Seldom(*this); + } + + Hedge* Seldom::constructor() { + return new Seldom; + } + +} diff --git a/fuzzylite/src/hedge/Somewhat.cpp b/fuzzylite/src/hedge/Somewhat.cpp new file mode 100644 index 0000000..4d68c20 --- /dev/null +++ b/fuzzylite/src/hedge/Somewhat.cpp @@ -0,0 +1,41 @@ +/* + 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. + */ + +#include "fl/hedge/Somewhat.h" + +namespace fl { + + std::string Somewhat::name() const { + return "somewhat"; + } + + Complexity Somewhat::complexity() const { + return Complexity().function(1); + } + + scalar Somewhat::hedge(scalar x) const { + return std::sqrt(x); + } + + Somewhat* Somewhat::clone() const { + return new Somewhat(*this); + } + + Hedge* Somewhat::constructor() { + return new Somewhat; + } + +} diff --git a/fuzzylite/src/hedge/Very.cpp b/fuzzylite/src/hedge/Very.cpp new file mode 100644 index 0000000..5ac7a86 --- /dev/null +++ b/fuzzylite/src/hedge/Very.cpp @@ -0,0 +1,41 @@ +/* + 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. + */ + +#include "fl/hedge/Very.h" + +namespace fl { + + std::string Very::name() const { + return "very"; + } + + Complexity Very::complexity() const { + return Complexity().arithmetic(1); + } + + scalar Very::hedge(scalar x) const { + return x * x; + } + + Very* Very::clone() const { + return new Very(*this); + } + + Hedge* Very::constructor() { + return new Very; + } + +} |