PHPackages                             ifaqih/iffuzzy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ifaqih/iffuzzy

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ifaqih/iffuzzy
==============

Fuzzy Logic library for PHP based on the Mamdani, Sugeno or Tsukamoto methods.

1.0.0(3y ago)11.1k1MITPHPPHP &gt;= 8.0

Since Feb 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ifaqih/IFFuzzy)[ Packagist](https://packagist.org/packages/ifaqih/iffuzzy)[ RSS](/packages/ifaqih-iffuzzy/feed)WikiDiscussions main Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (1)

Fuzzy
=====

[](#fuzzy)

Fuzzy logic is a form of many-valued logic in which the truth value of variables may be any real number between 0 and 1. It is employed to handle the concept of partial truth, where the truth value may range between completely true and completely false. By contrast, in Boolean logic.

PHP Version: 8.0 or aboveInstallation
------------

[](#installation)

### With Composer:

[](#with-composer)

```
composer require ifaqih/iffuzzy
```

Use The Library
---------------

[](#use-the-library)

```
use IFaqih\AIMethods\Fuzzy;
```

Constants:
----------

[](#constants)

Constant NameValueDescription`FUZZY_METHOD_MAMDANI``"MAMDANI"`Using the Mamdani method`FUZZY_METHOD_SUGENO``"SUGENO"`Using the Sugeno method`FUZZY_METHOD_TSUKAMOTO``"TSUKAMOTO"`Using the Tsukamoto method`FUZZY_MEMBERSHIP_LINEAR_UP``10`Using ascending linear membership`FUZZY_MEMBERSHIP_LINEAR_DOWN``11`Using descending linear membership`FUZZY_MEMBERSHIP_TRIANGLE``12`Using triangular membership`FUZZY_MEMBERSHIP_TRAPEZOID``13`Using trapezoidal membership`FUZZY_MEMBERSHIP_SIGMOID_UP``14`Using ascending sigmoid membership`FUZZY_MEMBERSHIP_SIGMOID_DOWN``15`Using descending sigmoid membership`FUZZY_MEMBERSHIP_PI``16`Using pi membershipSet Method
----------

[](#set-method)

Setting the fuzzy method to be used.

```
class::method()
```

- Type: static
- Parameter data type: `string $method_name`
- Return data type: `object`

### Prototype:

[](#prototype)

```
IFFuzzy::method(FUZZY_METHOD_MAMDANI)
```

Set Attribute
-------------

[](#set-attribute)

Set one attribute context.

```
class::attribute()
```

- Type: static
- Parameter data type: `string $context_name, array $attributes, ?array $domain = null`
- Return data type: `object`

### Prototype 1:

[](#prototype-1)

```
IFFuzzy::attribute("many", [
        "little"    =>  FUZZY_MEMBERSHIP_LINEAR_DOWN,
        "much"      =>  FUZZY_MEMBERSHIP_LINEAR_UP
    ],
    [40, 80]
)
```

### Prototype 2:

[](#prototype-2)

```
IFFuzzy::attribute("level", [
        "low"       =>  [
            "membership"    =>  FUZZY_MEMBERSHIP_LINEAR_DOWN,
            "domain"        =>  [40, 50]
        ],
        "medium"    =>  [
            "membership"    =>  FUZZY_MEMBERSHIP_TRIANGLE,
            "domain"        =>  [40, 60]
        ],
        "high"      =>  [
            "membership"    =>  FUZZY_MEMBERSHIP_LINEAR_UP,
            "domain"        =>  [50, 60]
        ]
    ]
)
```

Set Attributes
--------------

[](#set-attributes)

Set multiple context attributes.

```
class::attributes()
```

- Type: static
- Parameter data type: `array ...$attribute_each_context`
- Return data type: `object`

### Prototype:

[](#prototype-3)

```
IFFuzzy::attributes(
    [
        "many" =>  [
            "little"    =>  FUZZY_MEMBERSHIP_LINEAR_DOWN,
            "much"      =>  FUZZY_MEMBERSHIP_LINEAR_UP
        ],
        [40, 80]
    ],
    [
        "level" => [
            "low"       =>  [
                "membership"    =>  FUZZY_MEMBERSHIP_LINEAR_DOWN,
                "domain"        =>  [40, 50]
            ],
            "medium"    =>  [
                "membership"    =>  FUZZY_MEMBERSHIP_TRIANGLE,
                "domain"        =>  [40, 60]
            ],
            "high"      =>  [
                "membership"    =>  FUZZY_MEMBERSHIP_LINEAR_UP,
                "domain"        =>  [50, 60]
            ]
        ]
    ],
    [
        "speed" =>  [
            "slow"      =>  FUZZY_MEMBERSHIP_LINEAR_DOWN,
            "fast"      =>  FUZZY_MEMBERSHIP_LINEAR_UP
        ],
        [500, 1200]
    ]
)
```

Set Rule
--------

[](#set-rule)

Set one rule.

```
class::rule()
```

- Type: static
- Parameter data type: `string $result, array $attribute`
- Return data type: `object`

### Prototype:

[](#prototype-4)

```
IFFuzzy::rule("fast", ["many" => "much", "level" => "medium"])
```

Set Rules
---------

[](#set-rules)

Set multiple rule.

```
class::rules()
```

- Type: static
- Parameter data type: `array ...$rules`
- Return data type: `object`

### Prototype:

[](#prototype-5)

```
IFFuzzy::rules(
    ["rules"    =>  ["many" => "little", "level" => "low"], "result" => "slow"],
    ["rules"    =>  ["many" => "little", "level" => "medium"], "result" => "slow"],
    ["rules"    =>  ["many" => "little", "level" => "high"], "result" => "fast"],
    ["rules"    =>  ["many" => "much", "level" => "low"], "result" => "slow"],
    ["rules"    =>  ["many" => "much", "level" => "medium"], "result" => "fast"],
    ["rules"    =>  ["many" => "much", "level" => "high"], "result" => "fast"]
)
```

Builder of Rules
----------------

[](#builder-of-rules)

In the `set_rules()` method you can use builder

```
class::build()
```

- Type: static
- Parameter data type: no needed
- Return data type: `object`

### Object of build method

[](#object-of-build-method)

#### Set Rule Name

[](#set-rule-name)

```
class::build()->rule()
```

- Type: static
- Parameter data `string|array $data`
- Return data type: `object`

#### Set Rule Name

[](#set-rule-name-1)

```
class::build()->rule()->result()
```

- Type: static
- Parameter data `string $data, bool $is_formula = false`
- Return data type: `array`

#### Prototype:

[](#prototype-6)

```
IFFuzzy::build()->rule(["many" => "much", "level" => "medium"])->result('fast')
```

Set Value
---------

[](#set-value)

Set value of one context attribute.

```
class::set_value()
```

- Type: static
- Parameter data type: `string $context_name, int|float $value`
- Return data type: `object`

### Prototype:

[](#prototype-7)

```
IFFuzzy::set_value("much", 50)
```

Set Values
----------

[](#set-values)

Set value of multiple context attribute.

```
class::set_values()
```

- Type: static
- Parameter data type: `string $context_name, int|float $value`
- Return data type: `object`

### Prototype:

[](#prototype-8)

```
IFFuzzy::set_values(
    [
        "much"  =>  50,
        "level" =>  58
    ]
)
```

Constant Flags
--------------

[](#constant-flags)

Constant NameValueDescription`FUZZY_EXEC_HOLD``1`Not reset all data after executed`FUZZY_EXEC_GET_ALL``2`Getting all data has been processed of library (in object values)`FUZZY_EXEC_AS_ARRAY``3`Getting all data has been processed of library in array valuesExecuting Fuzzy Logic
---------------------

[](#executing-fuzzy-logic)

Execute datas has been added from all of method.

```
class::execute()
```

- Type: static
- Parameter data type: `array|int $flags = 0`
- Return data type: `int|float|object|array|null`

### Prototype:

[](#prototype-9)

```
IFFuzzy::execute(FUZZY_EXEC_HOLD)
```

Getting Value
-------------

[](#getting-value)

Getting all data has been processed of library.

```
class::get_all_values()
```

- Type: static
- Parameter data type: `int $flags = 0`
- Return data type: `array|object`

### Prototype:

[](#prototype-10)

```
IFFuzzy::get_all_values(FUZZY_EXEC_AS_ARRAY)
```

Clear Data
----------

[](#clear-data)

Clearing datas has been added or result of processed.

```
class::clear()
```

- Type: static
- Parameter data type: no needed
- Return data type: `void`

### Prototype:

[](#prototype-11)

```
IFFuzzy::clear()
```

Example
-------

[](#example)

### Example 1:

[](#example-1)

```
IFFuzzy::method(FUZZY_METHOD_MAMDANI)
    ->attributes(
        [
            "many" =>  [
                'little'   =>  FUZZY_MEMBERSHIP_LINEAR_DOWN,
                'much'    =>  FUZZY_MEMBERSHIP_LINEAR_UP
            ],
            [40, 80]
        ],
        [
            "level" => [
                'low'    =>  [
                    'membership'    =>  FUZZY_MEMBERSHIP_LINEAR_DOWN,
                    'domain'        =>  [40, 50]
                ],
                'medium'    =>  [
                    'membership'    =>  FUZZY_MEMBERSHIP_TRIANGLE,
                    'domain'        =>  [40, 60]
                ],
                'high'    =>  [
                    'membership'    =>  FUZZY_MEMBERSHIP_LINEAR_UP,
                    'domain'        =>  [50, 60]
                ]
            ]
        ],
        [
            "speed" =>  [
                'slow'    =>  FUZZY_MEMBERSHIP_LINEAR_DOWN,
                'fast'     =>  FUZZY_MEMBERSHIP_LINEAR_UP
            ],
            [500, 1200]
        ]
    )
    ->rules(
        ['rules'  =>  ["many" => "little", "level" => "low"], 'result' => 'slow'],
        ['rules'  =>  ["many" => "little", "level" => "medium"], 'result' => 'slow'],
        ['rules'  =>  ["many" => "little", "level" => "high"], 'result' => 'fast'],
        ['rules'  =>  ["many" => "much", "level" => "low"], 'result' => 'slow'],
        ['rules'  =>  ["many" => "much", "level" => "medium"], 'result' => 'fast'],
        ['rules'  =>  ["many" => "much", "level" => "high"], 'result' => 'fast']
    )
    ->set_values([
        'many' =>  50,
        'level' =>  58
    ])
    ->execute();
```

#### Result:

[](#result)

```
float(782.6128545848649)
```

### Example 2:

[](#example-2)

```
IFFuzzy::method(FUZZY_METHOD_MAMDANI);
IFFuzzy::attribute("many", [
    'little'   =>  FUZZY_MEMBERSHIP_LINEAR_DOWN,
    'much'    =>  FUZZY_MEMBERSHIP_LINEAR_UP
], [40, 80]);
IFFuzzy::attribute("level", [
    'low'    =>  [
        'membership'    =>  FUZZY_MEMBERSHIP_LINEAR_DOWN,
        'domain'        =>  [40, 50]
    ],
    'medium'    =>  [
        'membership'    =>  FUZZY_MEMBERSHIP_TRIANGLE,
        'domain'        =>  [40, 60]
    ],
    'high'    =>  [
        'membership'    =>  FUZZY_MEMBERSHIP_LINEAR_UP,
        'domain'        =>  [50, 60]
    ]
]);
IFFuzzy::attribute("speed", [
    'slow'    =>  FUZZY_MEMBERSHIP_LINEAR_DOWN,
    'fast'     =>  FUZZY_MEMBERSHIP_LINEAR_UP
], [500, 1200]);
IFFuzzy::rules([
    IFFuzzy::build()->rule(["many" => "little", "level" => "low"])->result('slow'),
    IFFuzzy::build()->rule(["many" => "little", "level" => "medium"])->result('slow'),
    IFFuzzy::build()->rule(["many" => "little", "level" => "high"])->result('fast'),
    IFFuzzy::build()->rule(["many" => "much", "level" => "low"])->result('slow'),
    IFFuzzy::build()->rule(["many" => "much", "level" => "medium"])->result('fast'),
    IFFuzzy::build()->rule(["many" => "much", "level" => "high"])->result('fast')
]);
IFFuzzy::set_values([
    'many' =>  50,
    'level' =>  58
]);
IFFuzzy::execute(FUZZY_EXEC_AS_ARRAY);
```

#### Result:

[](#result-1)

```
array(6) {
  ["method"]=>
  string(7) "MAMDANI"
  ["attributes"]=>
  array(3) {
    ["many"]=>
    array(2) {
      ["little"]=>
      array(3) {
        ["membership"]=>
        string(11) "Linear Down"
        ["domain"]=>
        array(2) {
          [0]=>
          int(40)
          [1]=>
          int(80)
        }
        ["fuzzification"]=>
        float(0.75)
      }
      ["much"]=>
      array(3) {
        ["membership"]=>
        string(9) "Linear Up"
        ["domain"]=>
        array(2) {
          [0]=>
          int(40)
          [1]=>
          int(80)
        }
        ["fuzzification"]=>
        float(0.25)
      }
    }
    ["level"]=>
    array(3) {
      ["low"]=>
      array(3) {
        ["membership"]=>
        string(11) "Linear Down"
        ["domain"]=>
        array(2) {
          [0]=>
          int(40)
          [1]=>
          int(50)
        }
        ["fuzzification"]=>
        int(0)
      }
      ["medium"]=>
      array(3) {
        ["membership"]=>
        string(8) "Triangle"
        ["domain"]=>
        array(2) {
          [0]=>
          int(40)
          [1]=>
          int(60)
        }
        ["fuzzification"]=>
        float(0.2)
      }
      ["high"]=>
      array(3) {
        ["membership"]=>
        string(9) "Linear Up"
        ["domain"]=>
        array(2) {
          [0]=>
          int(50)
          [1]=>
          int(60)
        }
        ["fuzzification"]=>
        float(0.8)
      }
    }
    ["speed"]=>
    array(2) {
      ["slow"]=>
      array(2) {
        ["membership"]=>
        int(11)
        ["domain"]=>
        array(2) {
          [0]=>
          int(500)
          [1]=>
          int(1200)
        }
      }
      ["fast"]=>
      array(2) {
        ["membership"]=>
        int(10)
        ["domain"]=>
        array(2) {
          [0]=>
          int(500)
          [1]=>
          int(1200)
        }
      }
    }
  }
  ["rules"]=>
  array(6) {
    [0]=>
    array(2) {
      ["rules"]=>
      array(2) {
        ["many"]=>
        string(6) "little"
        ["level"]=>
        string(3) "low"
      }
      ["result"]=>
      string(6) "slow"
    }
    [1]=>
    array(2) {
      ["rules"]=>
      array(2) {
        ["many"]=>
        string(6) "little"
        ["level"]=>
        string(6) "medium"
      }
      ["result"]=>
      string(6) "slow"
    }
    [2]=>
    array(2) {
      ["rules"]=>
      array(2) {
        ["many"]=>
        string(6) "little"
        ["level"]=>
        string(4) "high"
      }
      ["result"]=>
      string(5) "fast"
    }
    [3]=>
    array(2) {
      ["rules"]=>
      array(2) {
        ["many"]=>
        string(4) "much"
        ["level"]=>
        string(3) "low"
      }
      ["result"]=>
      string(6) "slow"
    }
    [4]=>
    array(2) {
      ["rules"]=>
      array(2) {
        ["many"]=>
        string(4) "much"
        ["level"]=>
        string(6) "medium"
      }
      ["result"]=>
      string(5) "fast"
    }
    [5]=>
    array(2) {
      ["rules"]=>
      array(2) {
        ["many"]=>
        string(4) "much"
        ["level"]=>
        string(4) "high"
      }
      ["result"]=>
      string(5) "fast"
    }
  }
  ["values"]=>
  array(2) {
    ["many"]=>
    int(50)
    ["level"]=>
    int(58)
  }
  ["inference"]=>
  array(2) {
    ["alpha_predicate"]=>
    array(2) {
      ["slow"]=>
      array(3) {
        [0]=>
        int(0)
        [1]=>
        float(0.2)
        [3]=>
        int(0)
      }
      ["fast"]=>
      array(3) {
        [2]=>
        float(0.75)
        [4]=>
        float(0.2)
        [5]=>
        float(0.25)
      }
    }
    ["z"]=>
    array(2) {
      ["momentum"]=>
      array(3) {
        [0]=>
        float(40960)
        [1]=>
        float(159037.08333333337)
        [2]=>
        float(146015.625)
      }
      ["area"]=>
      array(3) {
        [0]=>
        float(128)
        [1]=>
        float(182.875)
        [2]=>
        float(131.25)
      }
    }
  }
  ["result"]=>
  float(782.6128545848649)
}
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1244d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/43080806?v=4)[Ikhwanul Faqih](/maintainers/ifaqih)[@ifaqih](https://github.com/ifaqih)

---

Top Contributors

[![ifaqih](https://avatars.githubusercontent.com/u/43080806?v=4)](https://github.com/ifaqih "ifaqih (22 commits)")

---

Tags

artificial-intelligence-algorithmsfuzzy

### Embed Badge

![Health badge](/badges/ifaqih-iffuzzy/health.svg)

```
[![Health](https://phpackages.com/badges/ifaqih-iffuzzy/health.svg)](https://phpackages.com/packages/ifaqih-iffuzzy)
```

###  Alternatives

[symfony/polyfill-php56

Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions

1.6k208.5M28](/packages/symfony-polyfill-php56)[pear/pear-core-minimal

Minimal set of PEAR core files to be used as composer dependency

8078.0M78](/packages/pear-pear-core-minimal)[webgriffe/sylius-table-rate-shipping-plugin

Provides table rate shipping calculator.

1493.8k](/packages/webgriffe-sylius-table-rate-shipping-plugin)[cebe/luya-module-sitemap

sitemap.xml module for luya CMS

116.0k](/packages/cebe-luya-module-sitemap)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
