To create a dynamic CTRL.Rule() using Scikit-Fuzzy, you can follow the following steps:
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
# Input variable
length = ctrl.Antecedent(np.arange(0, 11, 1), 'length')
# Output variable
width = ctrl.Consequent(np.arange(0, 11, 1), 'width')
# 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])
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".
# Create a control simulation object
width_simulation = ctrl.ControlSystemSimulation(width_control)
# Provide input to the control system
width_simulation.input['length'] = 6
# 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.
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
Asked: 2022-04-11 11:00:00 +0000
Seen: 17 times
Last updated: Jul 01 '22
Which are the best Control Systems for large Telescope Arrays?
How can a column be eliminated from a DataGridView?
What is an API for safeguarding data?
How can I use C# .NET4.8.1 Visual Studio 2022 to display multiple forms within a single panel?
How can I utilize custom properties for the Picturebox control?
How can local reporting using RDL be done on .NET 4.0 at the client-side?
How do you code using the Border control with rounded edges in dotnet Maui using C# language?
What is the method for presenting the content of an ObservableCollection in .net Maui?
Is it possible that the Label.Caption in VBA is not getting updated on UserForm?