Skip to content

Commit 58bd23a

Browse files
committed
hedges should work with functions now
1 parent 869a24e commit 58bd23a

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

META.stay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: fuzzylogic
33
description: Fuzzy Logic for Python 3
44
license: MIT
55
url: https://github.com/amogorkon/fuzzylogic
6-
version: 0.1.1post3
6+
version: 0.1.1post5
77
author: Anselm Kiefner
88
author_email: fuzzylogic-pypi@anselm.kiefner.de
99
python_requires: >3.6

src/fuzzylogic.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: fuzzylogic
3-
Version: 0.1.1.post3
3+
Version: 0.1.1.post5
44
Summary: Fuzzy Logic for Python 3
55
Home-page: https://github.com/amogorkon/fuzzylogic
66
Author: Anselm Kiefner

src/fuzzylogic/hedges.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,48 @@
22
"""
33
Lingual hedges modify curves of membership values.
44
5-
These work with sets only. It's more trouble than it is worth making
6-
these work with pure functions, so meta-functionality was removed.
5+
These should work with Sets and functions.
76
"""
87

98
from .classes import Set
109

1110
def very(g):
1211
"""Sharpen memberships so that only the values close 1 stay at the top."""
13-
def s_f(g):
12+
if isinstance(g, Set):
13+
def s_f(g):
14+
def f(x):
15+
return g(x) ** 2
16+
return f
17+
return Set(s_f(g.func))
18+
else:
1419
def f(x):
1520
return g(x) ** 2
1621
return f
17-
return Set(s_f(g.func))
1822

1923

2024
def plus(g):
2125
"""Sharpen memberships like 'very' but not as strongly."""
22-
def s_f(g):
26+
if isinstance(g, Set):
27+
def s_f(g):
28+
def f(x):
29+
return g(x) ** 1.25
30+
return f
31+
return Set(s_f(g.func))
32+
else:
2333
def f(x):
2434
return g(x) ** 1.25
2535
return f
26-
return Set(s_f(g.func))
2736

2837

2938
def minus(g):
3039
"""Increase membership support so that more values hit the top."""
31-
def s_f(g):
40+
if isinstance(g, Set):
41+
def s_f(g):
42+
def f(x):
43+
return g(x) ** 0.75
44+
return f
45+
return Set(s_f(g.func))
46+
else:
3247
def f(x):
3348
return g(x) ** 0.75
34-
return f
35-
return Set(s_f(g.func))
49+
return f

0 commit comments

Comments
 (0)