PHP code example of ifaqih / iffuzzy

1. Go to this page and download the library: Download ifaqih/iffuzzy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ifaqih / iffuzzy example snippets

ruby
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);
ruby
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)
}