Skip to content

Commit 2acde78

Browse files
authored
added semielliptic membership functions (#25)
1 parent c6b96b7 commit 2acde78

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

docs/src/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## Unreleased
6+
7+
- ![](https://img.shields.io/badge/new%20feature-green.svg) added semi-elliptic membership functions
8+
59
## v0.1.2 -- 2023-03-12
610

711
[view release on GitHub](https://github.com/lucaferranti/FuzzyLogic.jl/releases/tag/v0.1.2)

src/FuzzyLogic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ include("readwrite.jl")
1818

1919
export DifferenceSigmoidMF, LinearMF, GeneralizedBellMF, GaussianMF, ProductSigmoidMF,
2020
SigmoidMF, TrapezoidalMF, TriangularMF, SShapeMF, ZShapeMF, PiShapeMF,
21-
PiecewiseLinearMF, WeightedMF, Type2MF, ..,
21+
SemiEllipticMF, PiecewiseLinearMF, WeightedMF, Type2MF, ..,
2222
ProdAnd, MinAnd, LukasiewiczAnd, DrasticAnd, NilpotentAnd, HamacherAnd, EinsteinAnd,
2323
ProbSumOr, MaxOr, BoundedSumOr, DrasticOr, NilpotentOr, EinsteinOr, HamacherOr,
2424
MinImplication, ProdImplication,

src/membership_functions.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,31 @@ function (p::PiShapeMF)(x::T) where {T <: Real}
278278
return 2 * ((x - p.d) / (p.d - p.c))^2
279279
end
280280

281+
"""
282+
Semi-elliptic membership function.
283+
284+
### Fields
285+
286+
$(TYPEDFIELDS)
287+
288+
### Example
289+
290+
```julia
291+
mf = SemiEllipticMF(5.0, 4.0)
292+
```
293+
"""
294+
struct SemiEllipticMF{T <: Real} <: AbstractMembershipFunction
295+
"center."
296+
cd::T
297+
"semi-axis."
298+
rd::T
299+
end
300+
function (semf::SemiEllipticMF)(x::Real)
301+
cd, rd = semf.cd, semf.rd
302+
cd - rd <= x <= cd + rd || return zero(x)
303+
sqrt(1 - (cd - x)^2 / rd^2)
304+
end
305+
281306
"""
282307
Piecewise linear membership function.
283308

test/test_membership_functions.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ end
117117
@test mf(10) == eval(to_expr(mf, 10)) == 0
118118
end
119119

120+
@testset "Semi-Elliptic MF" begin
121+
mf = SemiEllipticMF(5.0, 4.0)
122+
@test mf(0) == 0
123+
@test mf(1) == 0
124+
@test mf(5) == 1
125+
@test mf(9) == 0
126+
@test mf(10) == 0
127+
end
128+
120129
@testset "Piecewise linear Membership function" begin
121130
mf = PiecewiseLinearMF([(1, 0), (2, 1), (3, 0), (4, 0.5), (5, 0), (6, 1)])
122131
@test mf(0.0) == eval(to_expr(mf, 0.0)) == 0

0 commit comments

Comments
 (0)