PHP Classes

PHP Fuzzy Logic Library: Analyze variable based on fuzzy logic rules

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStar 32%Total: 393 All time: 6,632 This week: 52Up
Version License PHP version Categories
fuzzy-logic 1.0Free for non-comm...5PHP 5, Artificial intelligence
Description 

Author

This package can analyze variable based on fuzzy logic rules.

It can define ranges of values and labels to assign to different types of variables, like for instance temperature, temperature change, humidity, etc..

The package can build a knowledge base consisting of multiple inference rules that can be combined with logical operators like AND, OR and NOT.

Then the class can create an Mamdani inference engine that can take fuzzy values for the different variables defined before to compute diffused results for the maximum, minimum, average and centroid values.

The code and comments are in Spanish. In Spanish:

Libreria de logica difusa orientada a objetos que permite crear las variables linguisticas con sus terminos linguisticos correspondientes.

Crear una Base de Conocimientos y agregar las reglas de inferencia difusas (deben ser creadas previamente).

Se implementa un Sistema de Inferencia Difusa tipo Mamdani sin limite de cantidad de reglas.

La cantidad de terminos utilizados en los antecendentes de las reglas de inferencia pueden estar relacionados con los operadores AND, OR y Not. No hay un limite en la cantidad de elementos de los antecedentes.

Los consecuentes deben estar formados por un solo elemento. Al final del proceso se debe defuzificar el resultado.

Innovation Award
PHP Programming Innovation award nominee
September 2015
Number 11
Fuzzy logic is an approach to solve computing problems on which the results can have various levels of values, as opposed to Boolean logic on which the results can only be either true or false.

This package implements a complete fuzzy logic engine that can build a knowledge base of inference rules for applying to different input variables to achieve the desired outputs.

For instance it can make sense out of values of variables like for instance how temperature and humidity can be analyzed to determine if it is really cold, warm or hot.

Manuel Lemos
Picture of Gaston Silva
Name: Gaston Silva <contact>
Classes: 1 package by
Country: Argentina Argentina
Innovation award
Innovation award
Nominee: 1x

Example

<?php

/**
 * @author Gaston
 * @copyright 2014
 */

include_once 'reglaInferencia.php';
include_once
'variableLinguistica.php';
include_once
'etiquetaLinguistica.php';
include_once
'pertenencia.php';
include_once
'baseConocimiento.php';
include_once
'motordeinferencia.php';
include_once
'defuzificador.php';
include_once
'OperadorDifuso.php';
include_once
'implicacion.php';

//Definicion Temperatura

//Funciones de Pertenencia de las etiquetas linguisticas
$TempPert1 = new PertenenciaTriangular(0,15,10);
$TempPert2 = new PertenenciaTriangular(10,20,15);
$TempPert3 = new PertenenciaTriangular(18,22,20);
$TempPert4 = new PertenenciaTriangular(20,30,25);
$TempPert5 = new PertenenciaTriangular(25,35,30);

//5 etiquetas Linguisticas
$MBTemp = new EtiquetaLinguistica('muy baja',0,15,$TempPert1);
$BTemp = new EtiquetaLinguistica('baja',10,20,$TempPert2);
$NTemp = new EtiquetaLinguistica('normal',18,22,$TempPert3);
$ATemp = new EtiquetaLinguistica('alta',20,30,$TempPert4);
$MATemp = new EtiquetaLinguistica('muy alta',25,35,$TempPert5);

$Temperatura=new VariableLinguistica('temperatura',0,40,array($MBTemp,$BTemp,$NTemp,$ATemp,$MATemp),1);
// Fin definicion Variable Temperatura


//Definicion Humedad

//Funciones de Pertenencia de las etiquetas linguisticas
$HumPert1 = new PertenenciaTriangular(0,20,10);
$HumPert2 = new PertenenciaTriangular(10,40,25);
$HumPert3 = new PertenenciaTriangular(30,50,40);
$HumPert4 = new PertenenciaTriangular(40,70,55);
$HumPert5 = new PertenenciaTriangular(60,100,70);

//5 etiquetas Linguisticas
$MBHum = new EtiquetaLinguistica('muy baja',0,15,$HumPert1);
$BHum = new EtiquetaLinguistica('baja',10,20,$HumPert2);
$NHum = new EtiquetaLinguistica('normal',18,22,$HumPert3);
$AHum = new EtiquetaLinguistica('alta',20,30,$HumPert4);
$MAHum = new EtiquetaLinguistica('muy alta',25,35,$HumPert5);

$Humedad=new VariableLinguistica('humedad',0,100,array($MBHum,$BHum,$NHum,$AHum,$MAHum),1);
// Fin definicion Variable Humedad



//Definicion Variacion Temperatura

//Funciones de Pertenencia de las etiquetas linguisticas
$VarPert1 = new PertenenciaTriangular(-15,-7.5,-10);
$VarPert2 = new PertenenciaTriangular(-10,-2.5,-5);
$VarPert3 = new PertenenciaTriangular(-7.5,0,-2);
$VarPert4 = new PertenenciaTriangular(-1,1,0);
$VarPert5 = new PertenenciaTriangular(0,7.5,2.5);
$VarPert6 = new PertenenciaTriangular(2.5,10,5.5);
$VarPert7 = new PertenenciaTriangular(7.5,15,10);


//7 etiquetas Linguisticas
$BGVar = new EtiquetaLinguistica('bajada grande',-15,-7.5,$VarPert1);
$BNVar = new EtiquetaLinguistica('bajada normal',-10,-2.5,$VarPert2);
$BPVar = new EtiquetaLinguistica('bajada pequeña',-7.5,0,$VarPert3);
$MVar = new EtiquetaLinguistica('mantener',-1,1,$VarPert4);
$SPVar = new EtiquetaLinguistica('subida pequeña',0,7.5,$VarPert5);
$SNVar = new EtiquetaLinguistica('subida normal',2.5,10,$VarPert6);
$SGVar = new EtiquetaLinguistica('subida grande',7.5,15,$VarPert7);

$Variacion=new VariableLinguistica('variacion temperatura',-15,15,array($BGVar,$BNVar,$BPVar,$MVar,$SPVar,$SNVar,

$SGVar),0.2);
// Fin definicion Variable Variacion Temperatura


$BaseConocimiento = new BaseConocimiento();

try {
// ( ( ( not( (alto,normal) and (bajo,mucho) )

or (alto,poco) ) and (bajo,mucho) )
  
//si la temperatura es baja y la humedad es alta entonces la variacion es subida pequeña
  
$regla1 = new ReglaInferencia(1,array( array($Temperatura, 'baja') ,array($Humedad, 'alta') ), array($Variacion, 'subida

pequeña'
));
  
$BaseConocimiento->add_regla($regla1);
  
//si la temperatura es baja y la humedad es muy alta entonces la variacion es subida normal
  
$regla2 = new ReglaInferencia(2,array( array($Temperatura, 'baja') ,array($Humedad, 'muy alta') ), array($Variacion,

'subida normal'));
  
$BaseConocimiento->add_regla($regla2);
  
$regla3 = new ReglaInferencia(3,array( array($Temperatura, 'normal') ,array($Humedad, 'alta') ), array($Variacion,

'mantener'));
  
$BaseConocimiento->add_regla($regla3);
  
$regla4 = new ReglaInferencia(4,array( array($Temperatura, 'normal') ,array($Humedad, 'muy alta') ), array($Variacion,

'bajada pequeña'));
  
$BaseConocimiento->add_regla($regla4);
}
catch(
ReglaInferenciaException $e){
    echo
'error: '.$e->getMessage();
};

$conjuncion = new minimo('Min');
$disyuncion = new maximo('Max');
$implicacion = new Mamdani('Mamdani');
$agregacion = new maximo('agregacion Max');

$motor = new MotorInferenciaMamdani($BaseConocimiento, $conjuncion, $disyuncion, $implicacion, $agregacion);
$Temperatura->fuzificar(19.5);
$Humedad->fuzificar(65);

$resultados = $motor->inferir(array($Temperatura, $Humedad));


$min = new DefuzificadorMinOfMax();
$max = new DefuzificadorMaxOfMax();
$med = new DefuzificadorMedOfMax();
$cog = new DefuzificadorCOG();

echo
'defuzificador Min Of Max: ';
print_r($min->defuzificar($resultados));
echo
'</br>'.'</br>';

echo
'defuzificador Max Of Max: ';
print_r($max->defuzificar($resultados));
echo
'</br>'.'</br>';


echo
'defuzificador Med Of Max: ';
print_r($med->defuzificar($resultados));
echo
'</br>'.'</br>';

//$r = Array('variacion temperatura'=>array(array(-30, 0.1), array(-20, 0.1), array(-10, 0.1), array(0, 0.2), array(10,

0.2), array(20, 0.2), array(30, 0.2), array(40, 0.5), array(50, 0.5), array(60, 0.5), array(70, 0.5) ));


echo
'defuzificador Centroide: ';
print_r($cog->defuzificar($resultados));
echo
'</br>'.'</br>';

// echo 'defuzificador Min Of Max: '.$min->defuzificar($resultados).'</br>'.'</br>';
// echo 'defuzificador Max Of Max: '.$max->defuzificar($resultado).'</br>'.'</br>';
// echo 'defuzificador Med Of Max: '.$med->defuzificar($resultado).'</br>'.'</br>';
// echo 'defuzificador COS: '.$cos->defuzificar($resultado).'</br>'.'</br>';


?>


  Files folder image Files (10)  
File Role Description
Plain text file baseConocimiento.php Class Clase que representa las reglas de inferencia que modelan el problema.
Plain text file defuzificador.php Class Clase que transforma un conjunto difuso en un valor concreto
Plain text file etiquetaLinguistica Class clase encargada de representar las etiquetas lingusticas que caracterizan las variables de entrada y salida del sistema difuso. Cada etiqueta linguistica posee, ademas de su nombre y limites izquierdo y derecho, una funcion de pertenencia que es la encargada de determinar el grado de pertenencia de un valor crisp
Plain text file Implicacion.php Class Clase que se encarga de resolver la implicacion entre conjuntos difusos
Plain text file motordeinferencia.php Class Clase abastracta que evalua las reglas de inferencia. Recibe como entrada la base de conocimiento con las reglas de inferencia y devuelve un conjunto de reglas activadas para ser desfuzificadas. Por ejemplo el motor de inferencia mamadni evalua los antecedentes. Las reglas con antecedente mayor que cero son activadas y devueltas para resolver la defuzificacion con el metodo de desfuzificacion seleccionado
Plain text file operadorDifuso.php Class Clase que calcula la pertenencia de un valor en un termino lingusitico
Plain text file pertenencia.php Class Clase que calcula la pertenencia de un valor en un termino lingusitico
Accessible without login Plain text file prueba.php Example ejemplo de prueba de un problema con logica difusa
Plain text file reglaInferencia.php Class Clase que representa las reglas de inferencia. Permite calcular los participantes del antecedente devolviendo los valores de pertenencia de cada termino linguistico de las variables linguisticas del antecedente y del consecuente de la regla.
Plain text file variableLinguistica.php Class Clase que representa las variables difusas del sistema difuso. Tanto las variables de entrada como la de salida seran representadas por objetos de esta clase.

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:393
This week:0
All time:6,632
This week:52Up
User Ratings User Comments (1)
 All time
Utility:50%StarStarStar
Consistency:37%StarStar
Documentation:-
Examples:37%StarStar
Tests:-
Videos:-
Overall:32%StarStar
Rank:4282