summaryrefslogtreecommitdiff
path: root/fuzzylite/src/term/Cosine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fuzzylite/src/term/Cosine.cpp')
-rw-r--r--fuzzylite/src/term/Cosine.cpp49
1 files changed, 21 insertions, 28 deletions
diff --git a/fuzzylite/src/term/Cosine.cpp b/fuzzylite/src/term/Cosine.cpp
index a1402ad..78162ea 100644
--- a/fuzzylite/src/term/Cosine.cpp
+++ b/fuzzylite/src/term/Cosine.cpp
@@ -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.
*/
#include "fl/term/Cosine.h"
@@ -27,13 +19,9 @@
namespace fl {
Cosine::Cosine(const std::string& name, scalar center, scalar width, scalar height)
- : Term(name, height), _center(center), _width(width) {
+ : Term(name, height), _center(center), _width(width) { }
- }
-
- Cosine::~Cosine() {
-
- }
+ Cosine::~Cosine() { }
std::string Cosine::className() const {
return "Cosine";
@@ -41,7 +29,7 @@ namespace fl {
std::string Cosine::parameters() const {
return Op::join(2, " ", _center, _width) +
- (not Op::isEq(_height, 1.0) ? " " + Op::str(_height) : "");
+ (not Op::isEq(getHeight(), 1.0) ? " " + Op::str(getHeight()) : "");
}
void Cosine::configure(const std::string& parameters) {
@@ -52,7 +40,7 @@ namespace fl {
std::ostringstream ex;
ex << "[configuration error] term <" << className() << ">"
<< " requires <" << required << "> parameters";
- throw fl::Exception(ex.str(), FL_AT);
+ throw Exception(ex.str(), FL_AT);
}
setCenter(Op::toScalar(values.at(0)));
setWidth(Op::toScalar(values.at(1)));
@@ -61,13 +49,17 @@ namespace fl {
}
+ Complexity Cosine::complexity() const {
+ return Complexity().comparison(3).arithmetic(4 + 1 + 7).function(2);
+ }
+
scalar Cosine::membership(scalar x) const {
- if (fl::Op::isNaN(x)) return fl::nan;
- if (fl::Op::isLt(x, _center - _width / 2.0)
- or fl::Op::isGt(x, _center + _width / 2.0))
- return _height * 0.0;
+ if (Op::isNaN(x)) return fl::nan;
+ if (Op::isLt(x, _center - 0.5 * _width)
+ or Op::isGt(x, _center + 0.5 * _width))
+ return Term::_height * 0.0;
const scalar pi = 4.0 * std::atan(1.0);
- return _height * (0.5 * (1.0 + std::cos(2.0 / _width * pi * (x - _center))));
+ return Term::_height * (0.5 * (1.0 + std::cos(2.0 / _width * pi * (x - _center))));
}
void Cosine::setCenter(scalar center) {
@@ -93,4 +85,5 @@ namespace fl {
Term* Cosine::constructor() {
return new Cosine;
}
+
}