-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Center of gravity not working for singleton function #27
Comments
Hmmmm... hold on a second. What you are actually proposing is the ability to manipulate the layout of the array more directly and add specific sample-points, I guess. Ideally, singleton should add its value to the domain on assignment somehow, yes? That should be feasible. |
Maybe that example was not the best because of the step-size was inappropriate anyway. >>> from fuzzylogic.classes import Domain
>>> from fuzzylogic.functions import singleton
>>> D = Domain("D", 0, 1000)
>>> D.s1 = singleton(500)
>>> D.s1.center_of_gravity # expected 500
500.0
>>> D.s2 = singleton(500.1)
>>> D.s2.center_of_gravity # expected 500.1
0
This could solve the problem. However we need to consider how exactly singleton sets should interact with non-singleton sets. If we union a singleton set with a non-null set, should the singleton influence the centre of gravity at all or not? I think strictly speaking it should not so in that case the extra sample point should be removed again. Another possibility would be to adjust the width of the singleton function to the step-size, such that it always includes exactly one sample point. |
Hi, I am very new and I am not coming from an informatics background. Thus, I may be wrong, but isnt the center_of_gravity in the following line a function and not an attribute? fuzzylogic/src/fuzzylogic/classes.py Line 447 in 1edc8fc
|
Hi and thank you :-) You're absolutely correct. Seems I missed to test that properly when I updated the functionality and added rudimentary caching. However, since you're new I'll point out (so you don't learn the wrong lesson from my mistake) that methods (functions attached to a class) and attributes are not as distinct in python as you may think. In python, you can replace an attribute behind the scene by a function call. This feature of the language is called a "property". It works nicely for simple lookups and as I recall, the center_of_gravity used to be such a property before I realized that the underlying call can be quite computationally heavy. It is recommended to avoid hiding such heavy calls behind properties in general because users of the lib would rightfully assume light-weight operations when they access attributes, so they might make heavy use of such calls, leading to unexpected performance problems. |
The
center_of_gravity
method for sets created with thesingleton
function does not return the correct centre of gravity.Steps to reproduce:
This cannot work reliably since the centre of gravity is calculated by sampling over the domain and chances are high that the support of the singleton function is never hit.
Since the centre of gravity is trivially known for singleton sets, perhaps a feasible approach would be to implement
singleton
as a subclass ofSet
with thecenter_of_gravity
method returning the stored value from the constructor?The text was updated successfully, but these errors were encountered: