I'm new to fuzzy logic, I'm trying to get the power of a heater with the mom defuzzy method when the temperature is 27 degree
I'm having an error because the first and second element of the defuzz method should be an array of the same size, but I'm not sure how to write the problem/code
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
# Definir el universo de discurso para temperatura y potencia
temperatura = ctrl.Antecedent(np.arange(0, 41, 1), 'temperatura')
potencia = ctrl.Consequent(np.arange(0, 101, 1), 'potencia')
# Definir las funciones de membresía para temperatura
temperatura['baja'] = fuzz.trimf(temperatura.universe, [0, 10, 15])
temperatura['media'] = fuzz.trapmf(temperatura.universe, [10, 15, 25, 30])
temperatura['alta'] = fuzz.trimf(temperatura.universe, [25, 30, 40])
# Definir las funciones de membresía para potencia
potencia['baja'] = fuzz.trimf(potencia.universe, [0, 20, 30])
potencia['media'] = fuzz.trapmf(potencia.universe, [20, 30, 60, 70])
potencia['alta'] = fuzz.trimf(potencia.universe, [60, 70, 100])
# Visualización de las funciones de membresía
temperatura.view()
potencia.view()
# Definir las reglas difusas
regla1 = ctrl.Rule(temperatura['baja'], potencia['alta'])
regla2 = ctrl.Rule(temperatura['media'], potencia['media'])
regla3 = ctrl.Rule(temperatura['alta'], potencia['baja'])
# Crear el sistema de control difuso
sistema_control = ctrl.ControlSystem([regla1, regla2, regla3])
# Crear el simulador del sistema de control difuso
simulador = ctrl.ControlSystemSimulation(sistema_control)
# Establecer la temperatura de entrada
simulador.input['temperatura'] = 27 # Temperatura de ejemplo
# Realizar la inferencia
simulador.compute()
# Obtener el valor de potencia de salida
potencia_mom = fuzz.defuzz(potencia.universe, simulador.output['potencia'], 'mom')