Untitled
unknown
plain_text
a year ago
1.5 kB
3
Indexable
Never
# Define temperature membership function def temperature_membership(value): if value <= 30: return 1.0 elif value <= 60: return (60 - value) / 30 else: return 0.0 # Define humidity membership function def humidity_membership(value): if value <= 40: return 0.0 elif value <= 70: return (value - 40) / 30 else: return 1.0 # Define fan speed membership function def fan_speed_membership(value): if value <= 30: return 0.0 elif value <= 60: return (value - 30) / 30 else: return 1.0 # Perform fuzzy inference def fuzzy_inference(temperature, humidity): temperature_membership_value = temperature_membership(temperature) humidity_membership_value = humidity_membership(humidity) # Apply fuzzy rules if temperature_membership_value == 1.0 and humidity_membership_value == 1.0: return "high" elif temperature_membership_value == 0.0 or humidity_membership_value == 0.0: return "low" else: return "medium" # Defuzzify the output def defuzzify(output_fuzzy_set): if output_fuzzy_set == "low": return 30 elif output_fuzzy_set == "medium": return 60 elif output_fuzzy_set == "high": return 90 else: return None # Example usage temperature_input = 45 humidity_input = 55 output_fuzzy_set = fuzzy_inference(temperature_input, humidity_input) crisp_output = defuzzify(output_fuzzy_set) print(crisp_output)