Reading / writing functionalities

Parse Julia code

FuzzyLogic.@mamfisMacro

Parse julia code into a MamdaniFuzzySystem. See extended help for an example.

Extended help

Example

fis = @mamfis function tipper(service, food)::tip
    service := begin
      domain = 0:10
      poor = GaussianMF(0.0, 1.5)
      good = GaussianMF(5.0, 1.5)
      excellent = GaussianMF(10.0, 1.5)
    end

    food := begin
      domain = 0:10
      rancid = TrapezoidalMF(-2, 0, 1, 3)
      delicious = TrapezoidalMF(7, 9, 10, 12)
    end

    tip := begin
      domain = 0:30
      cheap = TriangularMF(0, 5, 10)
      average = TriangularMF(10, 15, 20)
      generous = TriangularMF(20, 25, 30)
    end

    and = ProdAnd
    or = ProbSumOr
    implication = ProdImplication

    service == poor || food == rancid --> tip == cheap
    service == good --> tip == average
    service == excellent || food == delicious --> tip == generous

    aggregator = ProbSumAggregator
    defuzzifier = BisectorDefuzzifier
end

# output

tipper

Inputs:
-------
service ∈ [0, 10] with membership functions:
    poor = GaussianMF{Float64}(0.0, 1.5)
    good = GaussianMF{Float64}(5.0, 1.5)
    excellent = GaussianMF{Float64}(10.0, 1.5)

food ∈ [0, 10] with membership functions:
    rancid = TrapezoidalMF{Int64}(-2, 0, 1, 3)
    delicious = TrapezoidalMF{Int64}(7, 9, 10, 12)


Outputs:
--------
tip ∈ [0, 30] with membership functions:
    cheap = TriangularMF{Int64}(0, 5, 10)
    average = TriangularMF{Int64}(10, 15, 20)
    generous = TriangularMF{Int64}(20, 25, 30)


Inference rules:
----------------
(service is poor ∨ food is rancid) --> tip is cheap
service is good --> tip is average
(service is excellent ∨ food is delicious) --> tip is generous


Settings:
---------
- ProdAnd()
- ProbSumOr()
- ProdImplication()
- ProbSumAggregator()
- BisectorDefuzzifier(100)
source
FuzzyLogic.@sugfisMacro

Parse julia code into a SugenoFuzzySystem. See extended help for an example.

Extended help

Example

fis = @sugfis function tipper(service, food)::tip
    service := begin
        domain = 0:10
        poor = GaussianMF(0.0, 1.5)
        good = GaussianMF(5.0, 1.5)
        excellent = GaussianMF(10.0, 1.5)
    end

    food := begin
        domain = 0:10
        rancid = TrapezoidalMF(-2, 0, 1, 3)
        delicious = TrapezoidalMF(7, 9, 10, 12)
    end

    tip := begin
        domain = 0:30
        cheap = 0
        average = food
        generous = 2service, food, -2
    end

    service == poor && food == rancid --> tip == cheap
    service == good --> tip == average
    service == excellent || food == delicious --> tip == generous
end

# output

tipper

Inputs:
-------
service ∈ [0, 10] with membership functions:
    poor = GaussianMF{Float64}(0.0, 1.5)
    good = GaussianMF{Float64}(5.0, 1.5)
    excellent = GaussianMF{Float64}(10.0, 1.5)

food ∈ [0, 10] with membership functions:
    rancid = TrapezoidalMF{Int64}(-2, 0, 1, 3)
    delicious = TrapezoidalMF{Int64}(7, 9, 10, 12)


Outputs:
--------
tip ∈ [0, 30] with membership functions:
    cheap = 0
    average = food
    generous = 2service + food - 2


Inference rules:
----------------
(service is poor ∧ food is rancid) --> tip is cheap
service is good --> tip is average
(service is excellent ∨ food is delicious) --> tip is generous


Settings:
---------
- ProdAnd()
- ProbSumOr()
source

Generate Julia code

FuzzyLogic.compilefisFunction
compilefis(
    fname::AbstractString,
    fis::FuzzyLogic.AbstractFuzzySystem
) -> Any
compilefis(
    fname::AbstractString,
    fis::FuzzyLogic.AbstractFuzzySystem,
    name::Symbol
) -> Any

Compile the fuzzy inference system into stand-alone Julia code. If the first argument is a string, it write the code in the given file, otherwise it returns the Julia expression of the code.

Inputs

  • fname::AbstractString – file where to write
  • fis::AbstractFuzzySystem – fuzzy system to compile
  • name::Symbol – name of the generated function, default fis.name

Notes

Only type-1 inference systems are supported

source

Read from file

FuzzyLogic.readfisFunction
readfis(file::String) -> FuzzyLogic.AbstractFuzzySystem
readfis(
    file::String,
    fmt::Union{Nothing, Symbol}
) -> FuzzyLogic.AbstractFuzzySystem

Read a fuzzy system from a file using a specified format.

Inputs

  • file::String – path to the file to read.
  • fmt::Union{Symbol,Nothing} – input format of the file. If nothing, it is inferred from the file extension.

Supported formats are

  • :fcl – Fuzzy Control Language (corresponding file extension .fcl)
  • :fml – Fuzzy Markup Language (corresponding file extension .xml)
  • :matlab – Matlab fis (corresponding file extension .fis)
source

Parse FCL

FuzzyLogic.FCLParser.parse_fclFunction
parse_fcl(s::String)::AbstractFuzzySystem

Parse a fuzzy inference system from a string representation in Fuzzy Control Language (FCL).

Inputs

  • s::String – string describing a fuzzy system in FCL conformant to the IEC 1131-7 standard.

Notes

The parsers can read FCL comformant to IEC 1131-7, with the following remarks:

  • Sugeno (system with singleton outputs) shall use COGS as defuzzifier.
  • the RANGE keyword is required for both fuzzification and defuzzification blocks.
  • Only the required MAX accumulator is supported.
  • Default value for defuzzification not supported.
  • Optional local variables are not supported.

With the exceptions above, the parser supports all required and optional features of the standard (tables 6.1-1 and 6.1-2). In addition, it also supports the following features:

  • Piecewise linear functions can have any number of points.
  • Membership degrees in piecewise linear functions points can be any number between $0$ and $1$.
source

Parse FML

FuzzyLogic.FMLParser.parse_fmlFunction
parse_fml(s::String)::AbstractFuzzySystem

Parse a fuzzy inference system from a string representation in Fuzzy Markup Language (FML).

Inputs

  • s::String – string describing a fuzzy system in FML conformant to the IEEE 1855-2016 standard.

Notes

The parsers can read FML comformant to IEEE 1855-2016, with the following remarks:

  • only Mamdani and Sugeno are supported.
  • Operators and and or definitions should be set in the rule base block. Definitions at individual rules are ignored.
  • Modifiers are not supported.
source

Parse Matlab