Machine Learning Laboratory set of experiments, including ANN, Backpropagation, K-Means, Hierarchical Clustering, Linear Regression, Multivariate Regression, Fuzzy Logic.
A brief review about Python for computer vision showing the different modules necessary to dive into computer vision.
The modules presented are NumPy, SciPy, and Matplotlib.
Dr. Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf SEA - 5/20/16MLconf
Multi-algorithm Ensemble Learning at Scale: Software, Hardware and Algorithmic Approaches: Multi-algorithm ensemble machine learning methods are often used when the true prediction function is not easily approximated by a single algorithm. The Super Learner algorithm, also known as stacking, combines multiple, typically diverse, base learning algorithms into a single, powerful prediction function through a secondary learning process called metalearning. Although ensemble methods offer superior performance over their singleton counterparts, there is an implicit computational cost to ensembles, as it requires training and cross-validating multiple base learning algorithms.
We will demonstrate a variety of software- and hardware-based approaches that lead to more scalable ensemble learning software, including a highly scalable implementation of stacking called “H2O Ensemble”, built on top of the open source, distributed machine learning platform, H2O. H2O Ensemble scales across multi-node clusters and allows the user to create ensembles of deep neural networks, Gradient Boosting Machines, Random Forest, and others. As for algorithm-based approaches, we will present two algorithmic modifications to the original stacking algorithm that further reduce computation time — Subsemble algorithm and the Online Super Learner algorithm. This talk will also include benchmarks of the implementations of these new stacking variants.
Taken from this site for use by those without ppt application.
http://www2.le.ac.uk/departments/engineering/research/bioengineering/neuroengineering-lab/spike-sorting
Web spam classification using supervised artificial neural network algorithmsaciijournal
Due to the rapid growth in technology employed by the spammers, there is a need of classifiers that are more efficient, generic and highly adaptive. Neural Network based technologies have high ability of adaption as well as generalization. As per our knowledge, very little work has been done in this field using neural network. We present this paper to fill this gap. This paper evaluates performance of three supervised learning algorithms of artificial neural network by creating classifiers for the complex problem of latest web spam pattern classification. These algorithms are Conjugate Gradient algorithm, Resilient Backpropagation learning, and Levenberg-Marquardt algorithm.
A brief review about Python for computer vision showing the different modules necessary to dive into computer vision.
The modules presented are NumPy, SciPy, and Matplotlib.
Dr. Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf SEA - 5/20/16MLconf
Multi-algorithm Ensemble Learning at Scale: Software, Hardware and Algorithmic Approaches: Multi-algorithm ensemble machine learning methods are often used when the true prediction function is not easily approximated by a single algorithm. The Super Learner algorithm, also known as stacking, combines multiple, typically diverse, base learning algorithms into a single, powerful prediction function through a secondary learning process called metalearning. Although ensemble methods offer superior performance over their singleton counterparts, there is an implicit computational cost to ensembles, as it requires training and cross-validating multiple base learning algorithms.
We will demonstrate a variety of software- and hardware-based approaches that lead to more scalable ensemble learning software, including a highly scalable implementation of stacking called “H2O Ensemble”, built on top of the open source, distributed machine learning platform, H2O. H2O Ensemble scales across multi-node clusters and allows the user to create ensembles of deep neural networks, Gradient Boosting Machines, Random Forest, and others. As for algorithm-based approaches, we will present two algorithmic modifications to the original stacking algorithm that further reduce computation time — Subsemble algorithm and the Online Super Learner algorithm. This talk will also include benchmarks of the implementations of these new stacking variants.
Taken from this site for use by those without ppt application.
http://www2.le.ac.uk/departments/engineering/research/bioengineering/neuroengineering-lab/spike-sorting
Web spam classification using supervised artificial neural network algorithmsaciijournal
Due to the rapid growth in technology employed by the spammers, there is a need of classifiers that are more efficient, generic and highly adaptive. Neural Network based technologies have high ability of adaption as well as generalization. As per our knowledge, very little work has been done in this field using neural network. We present this paper to fill this gap. This paper evaluates performance of three supervised learning algorithms of artificial neural network by creating classifiers for the complex problem of latest web spam pattern classification. These algorithms are Conjugate Gradient algorithm, Resilient Backpropagation learning, and Levenberg-Marquardt algorithm.
From the perspective of Design and Analysis of Algorithm. I made these slide by collecting data from many sites.
I am Danish Javed. Student of BSCS Hons. at ITU Information Technology University Lahore, Punjab, Pakistan.
Distributed implementation of a lstm on spark and tensorflowEmanuel Di Nardo
Academic project based on developing a LSTM distributing it on Spark and using Tensorflow for numerical operations.
Source code: https://github.com/EmanuelOverflow/LSTM-TensorSpark
Intro to TensorFlow and PyTorch Workshop at Tubular LabsKendall
These are some introductory slides for the Intro to TensorFlow and PyTorch workshop at Tubular Labs. The Github code is available at:
https://github.com/PythonWorkshop/Intro-to-TensorFlow-and-PyTorch
MLConf 2013: Metronome and Parallel Iterative Algorithms on YARNJosh Patterson
Online learning techniques, such as Stochastic Gradient Descent (SGD), are powerful when applied to risk minimization and convex games on large problems. However, their sequential design prevents them from taking advantage of newer distributed frameworks such as Hadoop/MapReduce. In this session, we will take a look at how we parallelize parameter estimation for linear models on the next-gen YARN framework Iterative Reduce and the parallel machine learning library Metronome. We also take a look at non-linear modeling with the introduction of parallel neural network training in Metronome as well.
Melanie Warrick, Deep Learning Engineer, Skymind.io at MLconf SF - 11/13/15MLconf
Attention Neural Net Model Fundamentals: Neural networks have regained popularity over the last decade because they are demonstrating real world value in different applications (e.g. targeted advertising, recommender engines, Siri, self driving cars, facial recognition). Several model types are currently explored in the field with recurrent neural networks (RNN) and convolution neural networks (CNN) taking the top focus. The attention model, a recently developed RNN variant, has started to play a larger role in both natural language processing and image analysis research.
This talk will cover the fundamentals of the attention model structure and how its applied to visual and speech analysis. I will provide an overview of the model functionality and math including a high-level differentiation between soft and hard types. The goal is to give you enough of an understanding of what the model is, how it works and where to apply it.
Slides for the Part One of "Deep learning implementations and frameworks" presented as a Tutorial at PAKDD (Pacific Asia Knowledge Discovery and Data Mining Conference) 2016.
The presentation took place on April 19, 2016 at Auckland, New Zealand.
http://pakdd16.wordpress.fos.auckland.ac.nz/technical-program/tutorials/
Parallel External Memory Algorithms Applied to Generalized Linear ModelsRevolution Analytics
Presentation by Lee Edlefsen, Revolution Analytics to JSM 2012, San Diego CA, July 30 2012
For the past several decades the rising tide of technology has allowed the same data analysis code to handle the increase in sizes of typical data sets. That era is ending. The size of data sets is increasing much more rapidly than the speed of single cores, of RAM, and of hard drives. To deal with this, statistical software must be able to use multiple cores and computers. Parallel external memory algorithms (PEMA's) provide the foundation for such software. External memory algorithms (EMA's) are those that do not require all data to be in RAM, and are widely available. Parallel implementations of EMA's allow them to run on multiple cores and computers, and to process unlimited rows of data. This paper describes a general approach to efficiently parallelizing EMA's, using an R and C++ implementation of GLM as a detailed example. It examines the requirements for efficient PEMA's; the arrangement of code for automatic parallelization; efficient threading; and efficient inter-process communication. It includes billion row benchmarks showing linear scaling with rows and nodes, and demonstrating that extremely high performance is achievable.
Josh Patterson, Principal at Patterson Consulting: Introduction to Parallel Iterative Machine Learning Algorithms on Hadoop’s NextGeneration YARN Framework
Intelligent Systems Project: Bike sharing service modelingAlessio Villardita
A university project on data analysis and modeling based on a bike sharing system data set. Models developed: MLP and RBF fitting, Fuzzy Inference System, ANFIS and time series forecasting.
From the perspective of Design and Analysis of Algorithm. I made these slide by collecting data from many sites.
I am Danish Javed. Student of BSCS Hons. at ITU Information Technology University Lahore, Punjab, Pakistan.
Distributed implementation of a lstm on spark and tensorflowEmanuel Di Nardo
Academic project based on developing a LSTM distributing it on Spark and using Tensorflow for numerical operations.
Source code: https://github.com/EmanuelOverflow/LSTM-TensorSpark
Intro to TensorFlow and PyTorch Workshop at Tubular LabsKendall
These are some introductory slides for the Intro to TensorFlow and PyTorch workshop at Tubular Labs. The Github code is available at:
https://github.com/PythonWorkshop/Intro-to-TensorFlow-and-PyTorch
MLConf 2013: Metronome and Parallel Iterative Algorithms on YARNJosh Patterson
Online learning techniques, such as Stochastic Gradient Descent (SGD), are powerful when applied to risk minimization and convex games on large problems. However, their sequential design prevents them from taking advantage of newer distributed frameworks such as Hadoop/MapReduce. In this session, we will take a look at how we parallelize parameter estimation for linear models on the next-gen YARN framework Iterative Reduce and the parallel machine learning library Metronome. We also take a look at non-linear modeling with the introduction of parallel neural network training in Metronome as well.
Melanie Warrick, Deep Learning Engineer, Skymind.io at MLconf SF - 11/13/15MLconf
Attention Neural Net Model Fundamentals: Neural networks have regained popularity over the last decade because they are demonstrating real world value in different applications (e.g. targeted advertising, recommender engines, Siri, self driving cars, facial recognition). Several model types are currently explored in the field with recurrent neural networks (RNN) and convolution neural networks (CNN) taking the top focus. The attention model, a recently developed RNN variant, has started to play a larger role in both natural language processing and image analysis research.
This talk will cover the fundamentals of the attention model structure and how its applied to visual and speech analysis. I will provide an overview of the model functionality and math including a high-level differentiation between soft and hard types. The goal is to give you enough of an understanding of what the model is, how it works and where to apply it.
Slides for the Part One of "Deep learning implementations and frameworks" presented as a Tutorial at PAKDD (Pacific Asia Knowledge Discovery and Data Mining Conference) 2016.
The presentation took place on April 19, 2016 at Auckland, New Zealand.
http://pakdd16.wordpress.fos.auckland.ac.nz/technical-program/tutorials/
Parallel External Memory Algorithms Applied to Generalized Linear ModelsRevolution Analytics
Presentation by Lee Edlefsen, Revolution Analytics to JSM 2012, San Diego CA, July 30 2012
For the past several decades the rising tide of technology has allowed the same data analysis code to handle the increase in sizes of typical data sets. That era is ending. The size of data sets is increasing much more rapidly than the speed of single cores, of RAM, and of hard drives. To deal with this, statistical software must be able to use multiple cores and computers. Parallel external memory algorithms (PEMA's) provide the foundation for such software. External memory algorithms (EMA's) are those that do not require all data to be in RAM, and are widely available. Parallel implementations of EMA's allow them to run on multiple cores and computers, and to process unlimited rows of data. This paper describes a general approach to efficiently parallelizing EMA's, using an R and C++ implementation of GLM as a detailed example. It examines the requirements for efficient PEMA's; the arrangement of code for automatic parallelization; efficient threading; and efficient inter-process communication. It includes billion row benchmarks showing linear scaling with rows and nodes, and demonstrating that extremely high performance is achievable.
Josh Patterson, Principal at Patterson Consulting: Introduction to Parallel Iterative Machine Learning Algorithms on Hadoop’s NextGeneration YARN Framework
Intelligent Systems Project: Bike sharing service modelingAlessio Villardita
A university project on data analysis and modeling based on a bike sharing system data set. Models developed: MLP and RBF fitting, Fuzzy Inference System, ANFIS and time series forecasting.
Python is the choice llanguage for data analysis,
The aim of this slide is to provide a comprehensive learning path to people new to python for data analysis. This path provides a comprehensive overview of the steps you need to learn to use Python for data analysis.
Start machine learning in 5 simple stepsRenjith M P
Simple steps to get started with machine learning.
The use case uses python programming. Target audience is expected to have a very basic python knowledge.
Machine Learning (ML) models are often composed as pipelines of operators, from “classical” ML operators to pre-processing and featurization operators. Current systems deploy pipelines as "black boxes”, where the same implementation of training is run for inference. This solution is convenient but leaves large room to improve performance and resource usage. This talk presents Pretzel, a framework for deployment of ML pipelines that is inspired to Database Systems: Pretzel inspects and optimizes pipelines end-to-end much like queries, and manages resources common to multiple pipelines such as operators' state. Pretzel is joint work with University of Seoul and Microsoft Research and has recently been presented at OSDI ’18. After the overview, this talk also shows experimental results of Pretzel against state-of-art ML solutions and discusses limitations and extensions.
Comprehensive Performance Evaluation on Multiplication of Matrices using MPIijtsrd
In Matrix multiplication we refer to a concept that is used in technology applications such as digital image processing, digital signal processing and graph problem solving. Multiplication of huge matrices requires a lot of computing time as its complexity is O n3 . Because most engineering science applications require higher computational throughput with minimum time, many sequential and analogue algorithms are developed. In this paper, methods of matrix multiplication are elect, implemented, and analyzed. A performance analysis is evaluated, and some recommendations are given when using open MP and MPI methods of parallel of latitude computing. Adamu Abubakar I | Oyku A | Mehmet K | Amina M. Tako ""Comprehensive Performance Evaluation on Multiplication of Matrices using MPI""
Published in International Journal of Trend in Scientific Research and Development (ijtsrd), ISSN: 2456-6470, Volume-4 | Issue-2 , February 2020,
URL: https://www.ijtsrd.com/papers/ijtsrd30015.pdf
Paper Url : https://www.ijtsrd.com/engineering/electrical-engineering/30015/comprehensive-performance-evaluation-on-multiplication-of-matrices-using-mpi/adamu-abubakar-i
In this talk I'll discuss how we can combine the power of PostgreSQL with TensorFlow to perform data analysis. By using the pl/python3 procedural language we can integrate machine learning libraries such as TensorFlow with PostgreSQL, opening the door for powerful data analytics combining SQL with AI. Typical use-cases might involve regression analysis to find relationships in an existing dataset and to predict results based on new inputs, or to analyse time series data and extrapolate future data taking into account general trends and seasonal variability whilst ignoring noise. Python is an ideal language for building custom systems to do this kind of work as it gives us access to a rich ecosystem of libraries such as Pandas and Numpy, in addition to TensorFlow itself.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
1. Machine Learning Lab Report
Submitted by:
Almkdad Ali, MCS18001
Course:
M. Tech, CSE
Date:
16-April-2019
C. V. Raman College of Engineering, Department of Computer Science and Engineering
3. 2
1.Tools and Libraries:
1.1 Python:
1.1.1 What is Python?
● Python is an interpreted programming language used in various
fields.
● It has two major versions 2.X, and 3.X.
● It used in :
○ web development (server-side),
○ software development,
○ mathematics,
○ system scripting.
○ Scientific applications.
1.1.2 What can Python do?
● Python can be used on a server to create web applications.
● Python can be used alongside software to create workflows.
● Python can connect to database systems. It can also read and
modify files.
● Python can be used to handle big data and perform complex
mathematics.
● Python can be used for rapid prototyping, or for production-ready
software development.
1.1.3 Why using Python?
● Python works on different platforms (Windows, Mac, Linux, Raspberry Pi,
etc).
● Python has a simple syntax similar to the English language.
● Python has syntax that allows developers to write programs with fewer
lines than some other programming languages.
● Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping can be very
quick.
● Python can be treated in a procedural way, an object-oriented way or a
functional way.
4. 3
1.2 NumPy Library:
1.2.1 What is NumPy?
● NumPy is the fundamental package for scientific computing with
Python.
● It contains among other things:
○ a powerful N-dimensional array object
○ sophisticated (broadcasting) functions
○ tools for integrating C/C++ and Fortran code
○ useful linear algebra, Fourier transform, and random
number capabilities
1.2.2 Why NumPy is useful for machine learning?
● NumPy is very useful for performing mathematical and logical
operations on Arrays.
● It provides an abundance of useful features for operations on n-
arrays and matrices in Python.
1.2.3 Installing and using NumPy
● To install NumPy we use pip python package manager:
>> pip install numpy
● To use NumPy inside Python code:
import numpy as np
1.2.4 NumPy arrays:
● A NumPy array is simply a grid that contains values of the same
type.
● NumPy Arrays come in two forms; Vectors and Matrices.
● Vectors are strictly one-dimensional(1-d) arrays.
● Matrices are multidimensional.
● In some cases, Matrices can still have only one row or one
column.
● Using NumPy array in code:
python_list = [[1,2,3], [5,4,1], [3,6,7]]
new_2d_arr = np.array(second_list)
● Creating array from range:
my_list = np.arange(0,10)
● Generate a one-dimensional array of zeros:
zeros_array = np.zeros(5)
5. 4
● Generating an 1-d array of random numbers in NumPy:
random_array = np.random.randn(25)
● Converting one-dimensional array to two-dimensional:
random_array.reshape(5,5)
1.3 Pandas Library:
1.3.1 What is Pandas?
● Python library providing high-performance, easy-to-use data
structures and data analysis tools for the Python programming
language.
1.3.2 Why Pandas is used for machine learning ?
● Pandas offers powerful, expressive and flexible data structures
that make data manipulation and analysis easy.
● A fast and efficient DataFrame object for data manipulation with
integrated indexing.
● Pandas provides tools for reading and writing data between in-
memory data structures and different formats: CSV and text files,
Microsoft Excel, SQL databases, and the fast HDF5 format.
● Time series-functionality: date range generation and frequency
conversion, moving window statistics, moving window linear
regressions, date shifting and lagging. Even create domain-
specific time offsets and join time series without losing data.
● Highly optimized for performance.
1.3.3 Installing and using Pandas:
● To install Pandas we use pip python package manager:
>> pip install pandas
● To use Pandas inside Python code:
import pandas as pd
1.3.4 Pandas data structures:
● Pandas deals with the following three data structures:
○ Series
○ DataFrame
○ Panel
6. 5
● These data structures are built on top of Numpy array, which
means they are fast.
● That the higher dimensional data structure is a container of its
lower dimensional data structure.
● For example, DataFrame is a container of Series, Panel is a
container of DataFrame.
Data Structure Dimensions Description
Series 1 - 1D labeled array
of the same type.
- size can not be
changed.
DataFrame 2 General 2D labeled,
size-mutable
tabular structure
with potentially
heterogeneously
typed columns.
Panel 3 General 3D labeled,
size-mutable array.
● Creating Pandas Series:
pandas.Series( data, index, dtype, copy)
Example
s = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])
● Retrieve element from Series using Index
s['a']
● Creating Pandas DataFrame:
pandas.DataFrame( data, index, columns, dtype, copy)
Example:
data = [['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'])
● Select column from DataFrame
df['Name']
● Select row from DataFrame by integer index:
Df.iloc[2]
7. 6
1.3.5 Reading CSV files with Pandas:
● To read csv ( Comma Separated Values) files with pandas:
dataset = pd.read_csv("../dataset/student_result.csv")
1.4 Matplotlib Library:
1.4.1 What is Matplotlib?
● Matplotlib is a Python 2D plotting library which produces
publication quality figures in a variety of hard copy formats and
interactive environments across platforms.
1.4.2 Why Matplotlib is used for machine learning ?
● Matplotlib is used for data visualization.
● Data visualization is a very important part of data analysis.
● It can be used to explore the data to find some insights.
1.4.3 Installing and using Matplotlib:
● To install Matplotlib we use pip python package manager:
>> pip install matplotlib
● To use Pandas inside Python code:
import matplotlib as mpl
1.4.4 Using Matplotlib:
dataset = pd.read_csv('files/bd-dec18-births-deaths-natural-increase.csv')
n_groups = 19
fig, ax = plt.subplots()
bar_width = 0.35
index = np.arange(n_groups)
opacity = 0.4
error_config = {'ecolor': '0.3'}
rects1 = ax.bar(
Index,
dataset.loc[
dataset['Births_Deaths_or_Natural_Increase'] == 'Births']['Count'].values,
bar_width,
alpha=opacity, color='b',
error_kw=error_config,
label='Births')
rects2 = ax.bar(index + bar_width,
dataset.loc[
dataset['Births_Deaths_or_Natural_Increase'] == 'Deaths']['Count'].values,
8. 7
bar_width,
alpha=opacity, color='r',
error_kw=error_config,
label='Death')
ax.set_xlabel('Year')
ax.set_ylabel('Number of ')
ax.set_title('Number of Deaths and Births by Year')
ax.set_xticks(index + bar_width / 2)
ax.set_xticklabels(dataset['Period'].unique()-2000)
ax.legend()
fig.tight_layout()
plt.show()
Figure 1 ( Number of Deaths and Births by Year )
2. Experiment 1, ANN, Backpropagation
2.1 Basic Structure of Artificial Neural Network?
● Any basic ANN consists of one input layer, one or more hidden layer,
output layer.
9. 8
Figure 2 ( Model of Artificial Neural Network )
● For the above general model of artificial neural network, the net input can
be calculated as follows:
● The output can be calculated by applying the activation function over the
net input:
2.2 Experiment Objective:
● Build and train Artificial Neural Network to predict the output of logical
XOR Gate.
● The problem with logical XOR operation is that, it’s not linearly separable.
2.3 Network structure:
● Multilayer Perceptrons with one hidden layer.
● Two inputs.
● One output.
● One bias.
10. 9
2.4 How it works?
● Forward propagation begins with the input values and bias unit from the
input layer being multiplied by their respective weights.
● There is a weight for each combination of input and hidden unit.
● The products of the input layer values and their respective weights are
parsed as input to the non-bias units in the hidden layer.
● Each non-bias hidden unit invokes an activation function to squash the
sum of their input values down to a value that falls between 0 and 1 ( or
values near 0 and 1, i.e 0.01 and 0.9).
● Sigmoid function is used as the activation function
● The outputs of each hidden layer unit, including the bias unit, are then
multiplied by another set of respective weights and parsed to an output
unit.
● The output unit parses the sum of its input values through an activation
function to return an output value falling between 0 and 1, this is the
predicted output.
● After calculating predicted output, the backpropagation algorithm is
applied.
● The backpropagation algorithm begins by comparing the actual value
output by the forward propagation process to the expected value.
● Then backpropagation algorithm moves backward through the network.
● Backpropagation slightly adjusting each of the weights in a direction that
reduces the size of the error by a small degree.
● This process re-run thousands of times on each input combination until
the network can accurately predict the expected output of the possible
inputs using forward propagation.
2.5 Used Libraries:
● Numpy
13. 12
● Output plot:
● As we can observe from the diagram above the sum of errors ( Predicted
output - desired output ) is decreasing with the iterations.
● Number of iteration is defined by 15000 epoches.
● The final result is approx :
○ The predicated output:
[[0.98991756]
[0.99547241]
[0.00784624]
[0.00775994]]
○ The actual output should be
[[1]
[1]
[0]
[0]]
14. 13
3. Experiment 2, Clustering data points, K-Means
3.1 Experiment Objective:
● Clustering sets of data points into separate clusters using K-Means
algorithm.
3.2 Used libraries:
● OpenCv
● NumPy
● Matplotlib
3.3 Used methods:
● K-Means algorithm for clustering.
3.4 K-Means working flow:
Figure 2 ( K-Means algorithm workflow )
3.5 How to choose number of clusters (K) ?
● There are many methods to choose the optimum k value.
15. 14
● K could be defined previously or by using mathematical methods or
experimental algorithms like ‘elbow method’ .
Figure 3 ( Elbow Method )
16. 15
3.6 K-means Code:
import numpy as np
import cv2
from matplotlib import pyplot as plt
# Generate Random data points
group_1 = np.random.randint(0, 70, 30)
group_2 = np.random.randint(80, 130, 30)
group_3 = np.random.randint(160, 255, 30)
# Grouping all generated data points into one vector
data_points = np.hstack((group_1, group_2, group_3))
data_points = data_points.reshape((90, 1))
data_points = np.float32(data_points)
# Draw histogram of data points before clustering
plt.hist(data_points, 256, [0, 256]), plt.draw(), plt.show()
# Define criteria = ( type, max_iter = 15 , epsilon = 0.5 )
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 15, 0.5)
# Set flags, choose the initial clusters' centers with probabili ty 'P'
flags = cv2.KMEANS_PP_CENTERS
# Initialize centroids
centroid=np.array([2.5,15, 30],dtype=float)
centroid=np.reshape(centroid,(1,3))
best_labels=np.array(data_points)
# Apply K-Means
compactness,labels,centers = cv2.kmeans(data_points, 3, best_labels, criteria, 3, flags, centroid)
A = data_points[labels == 0]
B = data_points[labels == 1]
C = data_points[labels == 2]
# Plot cluster ‘A’ in red, cluster ‘B’ in blue, cluster ‘C’ in lime,
# and clusters’ centers in black
plt.hist(A,256,[0,256],color = 'r')
plt.hist(B,256,[0,256],color = 'b')
plt.hist(B,256,[0,256],color = 'lime')
plt.hist(centers,32,[0,256],color = 'k')
plt.draw()
plt.show()
17. 16
3.7 Experiment results and explanation :
● Sets of data points before clustering:
Figure 4 ( Set of data points, not clustered)
● Sets of data points after clustering:
Figure 5 ( Three Clusters, cluster 1 ‘Blue’, cluster 2 ‘Red’, cluster 3 ‘Lime’, clusters’ centers ‘Black’)
● Three sets of data point group_1, group_2, and group_3 had been
generated using np.random.randint.
18. 17
group_1 = np.random.randint(0, 70, 30)
group_2 = np.random.randint(80, 130, 30)
group_3 = np.random.randint(160, 255, 30)
● Grouping all groups data points into one-dimension vector with
dimensions 1x90
data_points = np.hstack((group_1, group_2, group_3))
data_points = data_points.reshape((90, 1))
● Define clustering criteria, in OpenCv we have two options:
○ Clustering with maximum number of iterations
cv2.TERM_CRITERIA_MAX_ITER
○ Clustering with error ‘epsilon’
cv2.TERM_CRITERIA_EPS
○ It is possible to combine both criterias
cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER
○ We apply both criterias with EPS = 0.5, and max_iter = 15
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 15, 0.5)
● Initialize clusters’ centroids:
centroid=np.array([2.5,15, 30],dtype=float)
centroid=np.reshape(centroid,(1,3))
● Apply K-Means methods from OpenCv library
compactness,labels,centers = cv2.kmeans(data_points, 3,
best_labels, criteria, 3, flags, centroid)
● cv2.kmeans returns threes objects:
○ Compactness: sum of squared distance between each point and
its corresponding cluster’s center.
○ Labels : List of clusters labels that will be used to separate data
points in matplotlib.
○ Centers: list of clusters centers coordinates.
19. 18
4. Experiment 3 (Clustering data points, Hierarchical Clustering)
4.1 Experiment Objective:
● Segment customers into different groups based on their shopping trends
using hierarchical clustering algorithm.
4.2 Used libraries:
● SciKit-Learn
● NumPy
● Matplotlib
● pandas
4.3 Used methods:
● Hierarchical clustering algorithm.
● Dendrogram Data Visualization to know number of clusters.
● Agglomerative Clustering approach.
4.4 Hierarchical Clustering Algorithm workflow:
● There are two approaches for hierarchical clustering:
○ Agglomerative clustering ( Bottom-Up )
○ Divisive Clustering (Top-Down )
Figure 6 (Agglomerative vs Divisive Clustering)
20. 19
4.5 Dendrogram:
● A dendrogram is a tree diagram frequently used to illustrate the
arrangement of the clusters produced by hierarchical clustering.
Figure 7 (Dendrogram Visualization)
● The vertical axis of the dendrogram represents the distance or
dissimilarity between clusters.
● The horizontal axis represents the objects and clusters.
● The dendrogram is simple to interpret, and is used where the main
interest is in similarity and clustering.
● Each joining (fusion) of two clusters is represented on the graph by the
splitting of a vertical line into two vertical lines.
● The vertical position of the split, shown by the short horizontal bar,
gives the distance (dissimilarity) between the two clusters.
21. 20
4.6 Experiment Code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import scipy.cluster.hierarchy as shc
from sklearn.cluster import AgglomerativeClustering
# read data from csv file
shopping_data = pd.read_csv('files/shopping_data.csv')
# clean data
data = shopping_data.iloc[:, 3:5].values
# Plot Scatter of data points
colors = np.random.rand(200)
plt.scatter(data[:, 0], data[:, 1] , c=colors, alpha=0.5)
plt.xlabel('Annual Income (k$)')
plt.ylabel('Spending Score (1-100)')
plt.show()
# draw dendrogram for the data points
plt.figure(figsize=(15, 10))
plt.title("Shopping data Dendrograms")
# Dendrogram with linkage
dend = shc.dendrogram(shc.linkage(data, method='ward'))
plt.xticks(rotation='vertical')
plt.xlabel('Data Points')
plt.ylabel('Dissimilarity (Distance)')
plt.show()
# Clustering data points using Agglomerative Clustering Algorithm
cluster = AgglomerativeClustering(n_clusters=5,
affinity='euclidean', linkage='ward')
cluster.fit_predict(data)
plt.figure(figsize=(10, 7))
plt.scatter(data[:, 0], data[:, 1], c=cluster.labels_,
cmap='rainbow')
plt.xlabel('Annual Income (k$)')
plt.ylabel('Spending Score (1-100)')
plt.show()
22. 21
4.7 Experiment results and explanation :
● First read csv file using pandas library and clean data (take Annual
Income and Spending Score Columns from data)
shopping_data = pd.read_csv('files/shopping_data.csv')
data = shopping_data.iloc[:, 3:5].values
● Data Points Scattering ( Annual Income vs Spending Score)
○ Draw scattering of data points
plt.scatter(data[:, 0], data[:, 1] , c=colors, alpha=0.5)
Figure 7 (Scattering of data points)
23. 22
● Dendrogram of all data points
○ Draw the dendrogram for data points
dend = shc.dendrogram(shc.linkage(data, method='ward'))
● Where linkage performs hierarchical/agglomerative clustering, i.e
it calculate the distance d(s, t) between two clusters t and s
● linkage has the possible methods (single, complete, average,
weighted, centroid, median ,ward)
● ‘Ward’ method (The incremental algorithm) is calculated by the
next formula:
Where: ‘u’ is the newly joined cluster consisting of clusters ‘s’ and
‘t’
‘v’ is the unused cluster in the forest
‘T’ is calculated as T = |u| + |v| + |t|
● We use 'ward' as the method since it minimizes then variants of
distances between the clusters.
Figure 9 (Dendrogram of Shopping Customers
● Number of clusters from Shopping Dendrogram
○ If we draw a horizontal line that passes through longest distance
without a horizontal line, we get 5 clusters as shown in the
following figure:
24. 23
Figure 10 (Number of Cluster from Shopping Dendrogram)
● Clustering of data points using agglomerative clustering algorithm
○ After defining number of clusters we can cluster the given data
points using AgglomerativeClustering method
cluster = AgglomerativeClustering(n_clusters=5,
affinity='euclidean', linkage='ward')
cluster.fit_predict(data)
Figure 11 (Clusters of data points)
25. 24
5. Experiment 4
Linear Regression, Multivariable Regression
5.1 Experiment Objective:
● Implement Linear Regression and Multivariate Regression in python.
● Predicate the Salary of an employee in linear regression (given years of
experiences).
● Predicate the Profit of a Startup company using multivariate regression
(given R&D Spend,Administration,Marketing Spend,State).
5.2 Used libraries:
● SciKit-Learn
● NumPy
● Matplotlib
● pandas
5.3 Salary Problem:
5.3.1 Problem statement:
● We have set of data points describe the relation between the
years of experience for an employee and his salary.
● We want a predictor (Regressor) to predict the salary of an
employee depending on his years of experience.
5.3.2 The solution:
● We’ll use linear regression as we have one feature ( years of
experience).
● Create Linear Regressor.
● Fit the Regressor with the given data (Hypothesis).
● Calculate the coefficients and intercept.
● Solution equation is of the form:
Y’ = m * years_of_experience + c
● Predict a value.
5.3.3 Experimentsteps and result:
● Reading the dataset:
26. 25
dataset = pd.read_csv('files/Salary_Data.csv')
print(dataset.head())
● Create and fit the model:
lr = LinearRegression()
Model = lr.fit(dataset[['YearsExperience']],
dataset.Salary)
● Test on one point ( years of experience = 5.3):
testPoint = 5.3
res = model.predict(np.array([[testPoint]]))
# Hypothesis: y' = a * x + b
hypothesis = model.coef_ * testPoint + model.intercept_
● Draw a scatter of data points, hypothesis, and the predicted value
of the previous test data point.
lt.xlabel('Years Of Experience (Year)')
plt.ylabel('Salary (INR)')
plt.title('Salary vs Years of Experience')
plt.scatter(testPoint,
res,
c='r',
marker='*',
s=100,
label = 'Predicated Salary')
plt.scatter(testPoint,
dataset.at[17, 'Salary'],
c='k',
marker='s',
s=100,
28. 27
5.4 Startup Profits Problem:
5.4.1 Problem statement:
● We have set of data points describe the relation between the
different startups departments expenses and the startup profits.
● We want to build a model that predict the profits of the startup
depending on its departments expenses ( Administration, R&D,
Marketing) .
● The dataset is consists from 50 companies.
5.4.2 The solution:
● We’ll use Multivariate regression as we have many features (R&D
spend, Administration Spend, and Marketing Spend).
● Create Linear Regressor.
● Fit the model with the given data (Hypothesis).
● Calculate the coefficients and intercept.
● Solution equation is of the form:
Profit = b0 + b1 * Administration + b2 * R&D + b3 * Marketing
● Predict a profit.
5.4.3 Used libraries:
● Pandas
● Sklearn
● Matplotlib
● Seaborn
5.4.3 Experimentsteps and results:
● Read the dataset and separating input / output dataset
29. 28
# Read Dataset
dataset = pd.read_csv('files/startupsCompanies.csv')
# Seperate input data from output data
input_set = dataset.iloc[:, :-1].values
output_set = dataset.iloc[:, -1].values
● Split dataset into train (80%) and test (20%) data set
# split data into train and test datasets
# train = 80%, test = 20%
input_train, input_test, output_train, output_test =
train_test_split(input_set, output_set, test_size=0.2, random_state=0)
● Create and fit the model
# Create model
lr = LinearRegression()
# Fit the model
model = lr.fit(input_train, output_train)
● Predict the output using test data and calculate model score
(accuracy):
# predict output set using input test set
output_predict = model.predict(input_test)
comparisionArray = np.column_stack(
(output_predict, output_test))
df = pd.DataFrame(comparisionArray,
columns=['Predicted Profit', 'Actual Profit'])
print(df)
# Get the model accuracy score ( 94%)
print(model.score(input_test, output_test))
30. 29
● Visualize the result
# Correlation Matrix Heatmap
f, ax = plt.subplots(figsize=(10, 8))
corr = dataset.corr()
hm = sns.heatmap(
round(corr,2),
annot=True,
ax=ax,
cmap="coolwarm",
fmt='.2f',
linewidths=.05)
f.subplots_adjust(top=0.93)
t= f.suptitle('Different department spending and profit Correlation
Heatmap', fontsize=14)
plt.show()
31. 30
● We can notice from the heatmap that R&D Spend has the most
influence effect on the profits, while the Administration Spend
has the least one.
32. 31
6. Experiment 5, Fuzzy Logic
6.1 Experiment Objective:
● Build Fuzzy Logic Control System.
● Apply the system on a real world problem.
6.2 What is Fuzzy Logic:
● The term fuzzy mean things which are not very clear or vague.
● Fuzzy logic offers very valuable flexibility for reasoning, ,i.e considering
the uncertainties of any situation.
● Fuzzy logic algorithm helps to solve a problem after considering all
available data.
● Then it takes the best possible decision for the given the input.
● The Fuzzy Logic method imitates the way of decision making in a human
which consider all the possibilities between digital values T and F.
6.5 Fuzzy Logic System Architecture:
● Each Fuzzy logic system basically consists of:
a. Fuzzifier
b. Inference engine (Controller)
c. Set of rules
d. Defuzzifier
● Fuzzy logic System workflow:
a. Define fuzzy sets.
b. Define membership functions.
c. Fuzzification of inputs.
d. Define the fuzzy rules.
e. Create the control system from the defined rules.
f. Apply the input on the control system.
g. Defuzzy the output to get a crisp value.
33. 32
6.6 Problem Statement:
● We have an “Automotive Speed Controller” system consists of:
○ 3 inputs:
■ Speed (5 levels: Too slow, Slow, Optimum, Fast, Too fast)
■ Acceleration (3 levels: Decelerating, Constant,
Accelerating)
■ Distance to destination (3 levels: Very close, Close,
Distant)
○ 1 output:
■ Power (fuel flow to engine)
● The output consists of 5 levels:
○ Decrease power greatly.
○ Decrease power slightly.
○ Leave power constant.
○ Increase power slightly.
○ Increase power greatly.
● We need to build a fuzzy system that takes a fuzzy input ( speed,
acceleration and distance) and give us a crisp output (degree of power)
● Steps of the System:
○ Fuzzification: determines an input's % membership in
overlapping sets.
○ Rules: determine outputs based on inputs and rules.
○ Combination/Defuzzification: combine all fuzzy actions
into a single fuzzy action and transform the single fuzzy
action into a crisp, executable system output.
● We’ll formulate this problem as:
○ Antecedents (Inputs)
■ Speed
● Universe (ie, crisp value range): What is the speed
of the car, on a scale of 0 to 100?
34. 33
● Fuzzy set (ie, fuzzy value range): Too slow, Slow,
Optimum, Fast, Too fast.
■ Acceleration
● Universe: Acceleration state of the car, on a scale
of 0 to 10?
● Fuzzy set: Decelerating, Constant, Accelerating
■ Distance
● Universe: The distance between the car and other
cars, on a scale of 0 to 100?
● Fuzzy set: Very close, Close,Distant
○ Consequents (Outputs)
■ Power
● Universe : How much should the power (quantity of
fuel to the engine) should be injected?, on a scale
of 0 to 60?
● Fuzzy set: Too slow, Decrease power greatly,
Decrease power slightly, Leave power constant,
Increase power slightly, Increase power greatly.
● Rules
○ IF speed is TOO SLOW and acceleration is DECELERATING,
THEN INCREASE POWER GREATLY
○ IF speed is SLOW and acceleration is DECREASING, THEN
INCREASE POWER SLIGHTLY
○ IF distance is CLOSE, THEN DECREASE POWER SLIGHTLY
○ IF distance is CLOSE and speed is TOO FAST, THEN
DECREASE POWER GREATLY
○ IF speed is OPTIMUM and acceleration is CONSTANT and
distance is CLOSE, THEN power is LEAVE POWER CONSTANT
● Usage
○ If the input to the controller is like:
The is speed 50,
And the acceleration is 3.6
And the distance is 50
○ The system will recommend to keep decrease the power slightly
and inject 23.85 mL of fuel to the engine
39. 38
7. Assignment, Defuzzification Methods
7.1 Assignment statement:
● Fuzzy logic calculations are excellent tools, but to use them the fuzzy
result must be converted back into a single number. This is known as
defuzzification. There are several possible methods for defuzzification,
using skfuzzy.defuzz.
● The task is to :
1. Develop a Python program to expose that methods (3 methods at
least) for the same membership function.
2. Display the output of those three methods.
3. Report the work clearly, include the theory and math part of the
chosen three methods.
7.2 Features of Membership functions:
● The core of a membership function for some fuzzy set A is defined as
that region of the universe that is characterized by complete and full
membership in the set A. That is, the core comprises those elements x of
the universe such that μA (x) = 1.
● The support of a membership function for some fuzzy set A is defined as
that region of the universe that is characterized by nonzero membership
in the set A . That is, the support comprises those elements x of the
universe such that μA(x) > 0.
● The boundaries of a membership function for some fuzzy set A are
defined as that region of the universe containing elements that have a
nonzero membership but not complete membership.
That is, the boundaries comprise those elements x of the universe such
that 0 < μA (x) < 1.
40. 39
7.3 What is defuzzification ?
● Defuzzification means convert fuzzy values to a crisp value.
7.4 Defuzzification methods:
● Following defuzzification methods are known to calculate crisp output:
○ Maxima Methods
■ Height method
■ First of maxima (FoM)
■ Last of maxima (LoM)
■ Mean of maxima(MoM)
○ Centroid methods
■ Center of gravity method (CoG)
■ Center of sum method (CoS)
■ Center of area method (CoA)
○ Weighted average method
7.4 Method 1, First of Maxima:
7.4.1 First of Maxima Mathematics:
● This method considers values with maximum membership.
● This method determines the smallest value of the domain with
maximum membership value.
● FoM is calculated as :
41. 40
x*
= min{x|C(x) = maxwC{w}}
Where: x*
is the crisp value
C(x) is the membership function value for x
● Example:
○ The defuzzified value x*
of the given fuzzy set will be x*
=4.
7.4.2 First of Maxima FoM Algorithm:
1. If the membership function is singleton fuzzy set then
x*
= maxwC{w}
2. Else
a. Initialize FoM = C{0}
b. Initialize lst = [ ]
c. For Each Point of x:
i. Compare x with maxwC{w}
ii. If C{x} is the equal to maxwC{w} THEN add x to lst
d. Take the minimum x value.
i. FoM = min x in lst
42. 41
7.4.3 Python Implementationfor FoM:
index = 0
sm_index = 0
sm = membership_function[0]
# Calculate FoM
for point in membership_function:
if point > sm:
sm = point
sm_index = index
index = index + 1
return input_universe[sm_index]
7.5 Method 2, Last of Maxima:
7.5.1 Last of Maxima Mathematics:
● This method considers values with maximum membership.
● This method determines the largest value of the domain with
maximum membership value
● LoM is calculated as :
x*
= max{x|C(x) = maxwC{w}}
Where: x*
is the crisp value
C(x) is the membership function value for x
43. 42
● Example:
○ The defuzzified value x*
of the given fuzzy set will be x*
=8.
7.4.2 Last of Maxima FoM Algorithm:
3. If the membership function is singleton fuzzy set then
x*
= maxwC{w}
4. Else
a. Initialize LoM = C{0}
b. Initialize lst = [ ]
c. For Each Point of x:
i. Compare x with maxwC{w}
ii. If C{x} is the equal to maxwC{w} THEN add x to lst
d. Take the maximum x value.
i. LoM = max x in lst
44. 43
7.4.3 Python Implementationfor LoM:
index = 0
mx_index = 0
mx = membership_function[0]
# Calculate LoM
for point in membership_function:
if point >= mx:
mx = point
mx_index = index
index = index + 1
return input_universe[mx_index]
7.6 Method 3, Mean of Maxima (Mean-Max):
7.6.1 Mean of Maxima Mathematics:
● This method considers values with maximum membership.
● This method determines the average (mean) values of the domain
with maximum membership value
● MoM is calculated as :
Where: x*
is the crisp value
M = {xi |μA(xi ) = h(C)}
where h(C) is the height of the fuzzy set C
|M| is the cardinality of the set M.
45. 44
● Example:
○ The defuzzified value x*
of the given fuzzy set will be x*
=(4+6+8) / 3 => x*
= 6
7.6.2 Mean of Maxima MoM Algorithm:
5. If the membership function is singleton fuzzy set then
x*
= maxwC{w}
6. Else
a. Initialize mx = C{0}
b. Initialize total_of_maximas = 0
c. Initialize sum_of_maximas = 0
d. For Each Point of x:
i. Compare x with maxwC{w}
ii. If C{x} is the equal to maxwC{w} THEN
1. sum_of_maximas = sum_of_maximas + x
2. Total_of_maximas = total_of_maximas + 1
e. Calculate MoM.
i. MoM = sum_of_maximas / Total_of_maximas
7.6.3 Python Implementationfor LoM:
total_no = 0
sum_of_maximas = 0.0
# Calculate Mean of Maximas
index = 0
for item in memberFunction:
if item == mx:
total_no = total_no + 1
sum_of_maximas = sum_of_maximas +
input_universe[index]
index = index + 1
return sum_of_maximas / total_no
46. 45
7.7 Method 4, Centroid (Center of gravity method CoG):
7.7.1 Centroid Mathematics:
● This method provides a crisp value based on the center of gravity
of the fuzzy set.
● The total area of the membership function distribution used to
represent the combined control action is divided into a number of
sub-areas.
● The area and the center of gravity or centroid of each sub-area is
calculated and then the summation of all these sub-areas is taken
to find the defuzzified value for a discrete fuzzy set.
● If the output fuzzy set C = C 1 ∪ C 2 ∪ ....C n , then the crisp
value according to CoS is defined as
● Aci denotes the area of the region bounded by the fuzzy set Ci
and xi is the geometric center of the area Aci .
● CoS is represented graphically as :
47. 46
● To Calculate the Centroid of any shape it could be one of three
possible shapes:
○ Rectangle:
- The Centroid of a rectangle is calculated as:
CoG = 0.5 * ( height + width )
- The area of the rectangle is calculated as:
area = width * height
○ Triangle:
- Either with a positive degree and its centroid is cal as:
CoG = (2.0 / 3.0) * (x2-x1) + x1
- Or with negative degree and its centroid is cal as:
CoG = (1.0 / 3.0) * (x2 - x1) + x1
● Example:
48. 47
○ Considering the three output fuzzy sets as shown in the
following plots:
● In this case, we have
○ Ac1 = 0.5 × 0.3 × (3 + 5), x1 = 2.5
○ Ac2 = 0.5 × 0.5 × (4 + 2), x2 = 5
○ Ac3 = 0.5 × 1 × (3 + 1), x3 = 6.5
● Thus :
7.7.3 Python Implementationfor CoG:
sum_moment_area = 0.0
sum_area = 0.0
for i in range(1,len(x)):
x1 = x[i - 1]
x2 = x[i]
y1 = mfx[i - 1]
y2 = mfx[i]
# if y1 == y2 == 0.0 or x1==x2: --> rectangle of zero heightor width
if not(y1 == y2 == 0.0 or x1 == x2):
if y1 == y2: # rectangle
moment= 0.5 * (x1 + x2)
area = (x2 - x1) * y1
elif y1 == 0.0 and y2 != 0.0: # triangle,heighty2
moment= 2.0 / 3.0 * (x2-x1) + x1
area = 0.5 * (x2 - x1) * y2
elif y2 == 0.0 and y1 != 0.0: # triangle,heighty1
moment= 1.0 / 3.0 * (x2 - x1) + x1
area = 0.5 * (x2 - x1) * y1
else:
moment= (2.0 / 3.0 * (x2-x1) * (y2 + 0.5*y1)) / (y1+y2) + x1
area = 0.5 * (x2 - x1) * (y1 + y2)
sum_moment_area += moment* area
sum_area += area
return sum_moment_area /np.fmax(sum_area,
np.finfo(float).eps).astype(float)
49. 48
7.8 Built-In defuzzification methods vs User-defined
defuzzification methods:
● We have the input universe and membership function as:
# create fuzzy set universe
setUniverse = np.arange(0, 25.0, 0.5)
# membership function for the fuzzy set
memberFunction = fuzz.trapmf(setUniverse, [5.0, 7.5, 15, 23.5])
● After Implementing the previous methods in python we get the below
results:
● And graphically: