Skip to content
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

Real- valued arguments desirable for membership functions #26

Open
bananthahally opened this issue May 26, 2023 · 9 comments
Open

Real- valued arguments desirable for membership functions #26

bananthahally opened this issue May 26, 2023 · 9 comments

Comments

@bananthahally
Copy link

Would like membership functions to be defined on real- valued arguments. Presently only integer- valued arguments are possible. Thanks.

@lucaferranti
Copy link
Owner

lucaferranti commented May 27, 2023

Hi there 👋 ,

thank you for your interest!

Could you clarify what you mean that currently only integers are possible? It should work with floating-point numbers without problems

julia> using FuzzyLogic

julia> mf = TriangularMF(1.0, 2.0, 3.0)
TriangularMF{Float64}(1.0, 2.0, 3.0)

julia> m2 = TriangularMF(1.1, 2.3, 4.5)
TriangularMF{Float64}(1.1, 2.3, 4.5)

julia> mf(1.1)
0.10000000000000009

julia> m2(1.1)
0.0

julia> m2(1.5)
0.3333333333333333

@bananthahally
Copy link
Author

bananthahally commented May 27, 2023 via email

@lucaferranti
Copy link
Owner

lucaferranti commented May 28, 2023

Hi, yes a screen-shot would be very helpful.

Meanwhile, if I had to try to guess your issue, I would guess you encountered the following

julia> mf = TriangularMF(1, 2.1, 3.1)
ERROR: MethodError: no method matching TriangularMF(::Int64, ::Float64, ::Float64)

Closest candidates are:
  TriangularMF(::T, ::T, ::T) where T<:Real
   @ FuzzyLogic ~/.julia/dev/FuzzyLogic/src/membership_functions.jl:63

the problem here is that for many membership functions it expects all parameters to be of the same type, so either all integers or all floats. In that case, you would have to type

mf = TriangularMF(1.0, 2.1, 3.1)

this philosophy (all of the same type) is common in statically typed languages. There would be three possible fixes of this

  1. Leave it as is, and document better the inputs should either be all floats or all integer $^*$
  2. Support automatically promoting inputs, so that TrinagularMF(1, 2.1 3.1) would automatically become TriangularMF(1.0, 2.1, 3.1)
  3. Parametrize each membership function by the type of each parameter.

I can think of small drawbacks of each solution, so none is perfect.

$^*$ For completeness, there is an important exception where mixed types are supported, that is

julia> GeneralizedBellMF(1.0, 2, 3.0)
GeneralizedBellMF{Float64, Int64}(1.0, 2, 3.0)

The reason for this is the following: for other membership functions (triangular, gaussian, etc.) supporting mixed types is just a small short-cut, since one can always type TriangularMF(1.0, 2.1, 3.0) without any drawback. Indeed, it's very likely that the integer will be promoted to float at the first operation of the inference pipeline.

In the case of the Generalized Bell MF, however, the second parameter is significantly different from the others. The first and third are, respectively, a variance and a mean, while the second one is an exponent. It's much more reasonable to expect an exponent to be integer and also float ^ integer is much faster than float ^ float, which is why for the generalized bell membership function I chose from the beginning to support different types

@lucaferranti
Copy link
Owner

(the close issue was a misclick, reopened ;) )

@bananthahally
Copy link
Author

bananthahally commented May 28, 2023 via email

@lucaferranti
Copy link
Owner

I don't see your attached screenshots unfortunately.

For now you should be able to overcome the problem by typing the integer as float (e.g. 1.0 instead of 1), does this get you unblocked?

I'll try to update the user interface to be more friendly and accept mixed inputs in the upcoming days.

@bananthahally
Copy link
Author

bananthahally commented May 29, 2023 via email

@lucaferranti
Copy link
Owner

lucaferranti commented Nov 26, 2023

In an upcoming release, one will be able to automatically create membership functions with mixed precisions, like

GaussianMF(1, 2.0)
TriangularMF(2, 4.0, 5//1)

and the constructor will automatically handle the promotion for all membership functions. This however relies on new features of Julia 1.10, so will have to wait for it to be released. I will notify on this issue, once this is implemented.

Meanwhile, you can manually convert those to floats, e.g. writing GaussianMF(1.0, 2.5) instead of GaussianMF(1, 2.5)

@bananthahally
Copy link
Author

bananthahally commented Nov 26, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants