0% found this document useful (0 votes)
586 views32 pages

Fuzzy Modelling Using Python

The document describes how to build a fuzzy logic model for predicting thrust force and torque using Python. It outlines the steps to install Python and required modules, define input and output variables, generate membership functions, write fuzzy rules, simulate the control environment, input test values, and compute and evaluate the model's predictions against experimental data. The goal is to predict thrust force and torque given inputs of feed rate, spindle speed, and drill diameter.

Uploaded by

rvimalsamsingh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
586 views32 pages

Fuzzy Modelling Using Python

The document describes how to build a fuzzy logic model for predicting thrust force and torque using Python. It outlines the steps to install Python and required modules, define input and output variables, generate membership functions, write fuzzy rules, simulate the control environment, input test values, and compute and evaluate the model's predictions against experimental data. The goal is to predict thrust force and torque given inputs of feed rate, spindle speed, and drill diameter.

Uploaded by

rvimalsamsingh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

FUZZY MODELLING USING

PYTHON

Mayanck Bihani
(312216114064)
Step 1: Installing PYTHON
From https://www.anaconda.com/distribution/, download
Python, version 3.7
Step 2
From the start button, search and open the “Anaconda Prompt”, which
is a command prompt developed by Anaconda.
In that, type “conda update jupyter”
It will ask for a prompt, “Install all packages y/n.” Press y
This will automatically install the Jupyter notebook in the system
Video for Python and Jupyter installation
Familiarizing With Jupyter Integrated
Development Environment (IDE)

• Jupyter is an IDE that is great for running and learning python

• To get started, you can either type ‘jupyter notebook’ in the anaconda
command prompt, or directly search for the same from the start
menu.
The Notebook will open in a browser
From the top right corner, select New -> Python 3
• Code can be typed in the boxes line by line.
• To compile, press “Shift+Enter’
Video For Familiarizing With Jupyter IDE
Step 3: Installing Modules required to run
Fuzzy in Python
• After familiarizing yourself with the environment, download and
install “skfuzzy,” the module required to run fuzzy logic in python
• To do that, in the Anaconda command Prompt, type in “pip install
scikit-fuzzy” and press enter
Step 4: Fuzzy Code
• After installing the scikit-fuzzy module, open a new python 3 jupyter
notebook, and in the first block, type in the following commands:

• import skfuzzy as fuzz


• from skfuzzy import control
• import numpy as np
• skfuzzy is the module that has built in fuzzy tools and techniques
• “control” in the skfuzzy module has the capabilities to control and
simulate the fuzzy logic
• “numpy” module is useful in creating and manipulating a list of
numbers or arrays, and will be used to define the scope and range of
the numerical parameters (both input and output)
• After importing the required libraries, we now define the input
parameters.
• In our example, there are three input parameters, or “consequents”:
1. Feed [60,120,180 mm/min]
2. Spindle Speed [500,1000,1500 RPM]
3. Drill Diameter [4,6,8 mm]
and
• 2 output parameters, or “Antecedents”:
1. Thrust Force [70-350 N]
2. Torque [0-80 Nm]
Code for defining the input parameters
Code for defining the output parameters

The np.arange command takes in two arguments: the lower and the upper limits of the scope of the values,
and creates an array of integers starting from the lower value and ending at the number preceding the upper
value

For example, the command np.arange(5,11) would generate an array [5,6,7,8,9,10]


Generating the Membership Functions
• After defining the scope of the input and output parameters, we now
generate the respective Membership Functions using the “.automf”
command.
• The .automf command takes an argument indicating the number of
levels the entire range, as defined previously, will be divided into.
• The membership functions generated will be triangular, by default.
Defining the levels
• The input parameters will be divided into three levels: low, medium
and high.
• The output parameters will be divided into nine levels: ulow, vlow,
low, med low, medium, med high, high, vhigh and uhigh.
• To define these levels, we first create a list of these names:
Defining the Membership functions
• To view the generated membership functions, type the name of the
membership function that you’d like to view, followed by the .view()
command
Defining The Fuzzy Inference System Rules
• Basically, the conversion of numerical values of the parameters to linguistic terms give us the following result:
1. Feed :
1. 0-60 : Low
2. 60-120 : Medium
3. 120-180 : High
2. Spindle Speed :
1. 0-500 : Low
2. 500-1000 : Medium
3. 1000-1500 : High
3. Drill Diameter :
1. 0-4 : Low
2. 4-6 : Medium
3. 6-8 : High
Defining The Fuzzy Inference System Rules
5. Thrust Force :
1. 70-78 : ulow
2. 78-86 : vlow
3. 86-95 : low
..
9. 324 – 330: uhigh

6. Torque :
1. 0-10 : ulow
2. 10-20 : vlow
3. 20-30 : low
..
9. 90-100 : uhigh
Defining The Fuzzy Inference System Rules
• Now, convert the numerical values obtained from the experiment to
linguistic terms

• For Eg:
Defining The Fuzzy Inference System Rules
• Now, we write the rules in python
• FOR THRUST FORCE:
Generating the Control Environment
• After defining the rules, we generate the control environment using
control.ControlSystem([<rules list>])
Simulating the Control Environment
• The generated environment “tforce_env” is now simulated under
another variable name “tforce_sim” using
control.ControlSystemSimulation(tforce_env)
Inputting the Values
• Now that the environment has been simulated and stored under
tforce_sim, we can input the data for which fuzzy model prediction is
to be generated.
Computing the Data
Obtaining the Output:
• Similarly, the rule base for Torque can be defined, simulated and
computed.

• The readings predicted by the model are noted down in an excel


sheet, beside the experimental value.

• A scatter plot is generated in Excel, with a Linear Trendline.

• The R2 value is obtained, to measure the accuracy with which the


prediction has been made
• For more reference on Fuzzy Modelling using Python, refer to the
“Tipping Problem” link given below:
https://pythonhosted.org/scikit-
fuzzy/auto_examples/plot_tipping_problem_newapi.html

You might also like