Ask Your Question
3

How can dynamic CTRL.Rule() be created using Sckikit-Fuzzy?

asked 2022-04-11 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-07-01 17:00:00 +0000

ladyg gravatar image

To create a dynamic CTRL.Rule() using Scikit-Fuzzy, you can follow the following steps:

  1. Import the necessary libraries:
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
  1. Define the input and output variables using ctrl.Antecedent() and ctrl.Consequent() methods:
# Input variable
length = ctrl.Antecedent(np.arange(0, 11, 1), 'length')

# Output variable
width = ctrl.Consequent(np.arange(0, 11, 1), 'width')
  1. Define the membership functions for the input and output variables using the methods available in Scikit-Fuzzy:
# Membership functions for length
length['short'] = fuzz.trimf(length.universe, [0, 0, 5])
length['medium'] = fuzz.trimf(length.universe, [0, 5, 10])
length['long'] = fuzz.trimf(length.universe, [5, 10, 10])

# Membership functions for width
width['narrow'] = fuzz.trimf(width.universe, [0, 0, 5])
width['medium'] = fuzz.trimf(width.universe, [2, 5, 8])
width['wide'] = fuzz.trimf(width.universe, [5, 10, 10])
  1. Create a CTRL.Rule() object by defining the antecedent and consequent variables using the methods available in Scikit-Fuzzy:
rule1 = ctrl.Rule(length['short'] & ~length['medium'], width['narrow'])
rule2 = ctrl.Rule(length['medium'], width['medium'])
rule3 = ctrl.Rule(length['long'] | length['medium'], width['wide'])

# Create a control system using the defined rules
width_control = ctrl.ControlSystem([rule1, rule2, rule3])

In the above code, rule1 corresponds to "If length is short and not medium, then width is narrow", rule2 corresponds to "If length is medium, then width is medium", and rule3 corresponds to "If length is long or medium, then width is wide".

  1. Create a control simulation by setting the control system and inputs using Simulation() and input['variable_name'] methods:
# Create a control simulation object
width_simulation = ctrl.ControlSystemSimulation(width_control)

# Provide input to the control system
width_simulation.input['length'] = 6
  1. Obtain the output of the simulation using the compute() method:
# Compute the result of the simulation
width_simulation.compute()

# Get the output value
width_val = width_simulation.output['width']

print("Width: ", width_val)

The above code will print the width value obtained as per the given input length value.

In this way, dynamic CTRL.Rule() can be created using Scikit-Fuzzy to implement fuzzy control systems for various real-world applications.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-04-11 11:00:00 +0000

Seen: 17 times

Last updated: Jul 01 '22