⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trips.m

📁 模糊控制工具箱,很好用的,有相应的说明文件,希望对大家有用!
💻 M
📖 第 1 页 / 共 2 页
字号:
%% Modeling Traffic Patterns using Subtractive Clustering
% This demo demonstrates the use of subtractive clustering to model traffic
% patterns in an area based on the area's demographics.
%
% Copyright 1994-2005 The MathWorks, Inc.
% $Revision: 1.12.2.2.2.1 $Date: 2005/07/17 06:06:22 $
%
%% The problem: Understanding Traffic Patterns
% In this demo we attempt to understand the relationship between the number
% of automobile trips generated from an area and the area's demographics.
% Demographic and trip data were collected from traffic analysis zones
% in New Castle County, Delaware. Five demographic factors are considered:
% population, number of dwelling units, vehicle ownership, median household
% income and total employment. 
%
% Hereon, the demographic factors will be addressed as inputs and the
% trips generated will be addressed as output. Hence our problem has five
% input variables (five demographic factors) and one output variable
% (num of trips generated).
%
%% The Data
% We will now load the input and output variables used for this demo into
% the workspace. 
% 

tripdata

%%
% Two variables are loaded in the workspace, |datin| and |datout|. |datin|
% has 5 columns representing the 5 input variables and |datout| has 1
% column representing the 1 output variable.
%

subplot(2,1,1)
plot(datin)
legend('population', 'num. of dwelling units', 'vehicle ownership',...
    'median household income', 'total employment');
title('Input Variables')

subplot(2,1,2)
plot(datout)
legend('num of trips');
title('Output Variable')

%%
% *Figure 1:* Input and Output variables 
%%
% The number of rows in |datin| and |datout|, 75, represent the number of
% observations or samples or datapoints available. A row in |datin|, say
% row 11, constitutes a set of observed values of the 5 input variables
% (population, number of dwelling units, vehicle ownership, median
% household income and total employment) and the corresponding row, row 11,
% in |datout| represents the observed value for the number of trips
% generated given the observations made for the input variables.
%
% We will model the relationship between the input variables (demographics)
% and the output variable (trips) by first clustering the data. The cluster
% centers will then be used as a basis to define a Fuzzy Inference System
% (FIS) which can then be used to explore and understand traffic patterns.
%
%% Why clustering and fuzzy logic?
% Clustering can be a very effective technique to identify natural
% groupings in data from a large data set, thereby allowing concise
% representation of relationships embedded in the data. In this example,
% clustering allows us to group traffic patterns into broad categories
% hence allowing for easier understandability.
%
% Fuzzy logic is an effective paradigm to handle uncertainty. It can be
% used to take fuzzy or imprecise observations for inputs and yet arrive at
% crisp and precise values for outputs. Also, the
% <matlab:helpview([docroot,'/toolbox/fuzzy/fuzzy.map'],'fuzzy_inference_systems') Fuzzy Inference System (FIS)> 
% is a simple and commonsensical way to build systems without using complex
% analytical equations.
%
% In our example, fuzzy logic will be employed to capture the broad
% categories identified during clustering into a Fuzzy Inference System
% (FIS). The FIS will then act as a model that will reflect the
% relationship between demographics and auto trips. 
%
% Clustering and fuzzy logic together provide a simple yet powerful means
% to model the traffic relationship that we want to study.
%
%% Clustering the data
% |subclust| is the function that implements a clustering technique called
% subtractive clustering. Subtractive clustering, [Chi94], is a fast,
% one-pass algorithm for estimating the number of clusters and the cluster
% centers in a dataset.
%
% In this section, we will see how subtractive clustering is performed on a
% dataset and in the next section we will explore independently how
% clustering is used to build a Fuzzy Inference System(FIS).

[C,S] = subclust([datin datout],0.5);

%%
% The first argument to the |subclust| function is the data to be
% clustered. The second argument to the function is the |radii| which
% marks a cluster's radius of influence in the <#28 input space>.
%
% The variable |C| now holds all the centers of the clusters that have been
% identified by |subclust|. Each row of |C| contains the position of a
% cluster.

C

%% 
% In this case, |C| has 3 rows representing 3 clusters with 6 columns
% representing the positions of the clusters in each dimension.
%
% |subclust| has hence identified 3 natural groupings in the
% demographic-trip dataset being considered. The following plot shows how
% the clusters have been identified in the 'total employment' and 'trips'
% dimensions of the input space.

clf;
plot(datin(:,5), datout(:,1), '.', C(:,5),C(:,6),'r*')
legend('Data points', 'Cluster centers', 'Location', 'SouthEast')
xlabel('total employment')
ylabel('num of trips')
title('Data and Clusters in selected two dimensions of the input space')

%%
% *Figure 2:* Cluster centers in the 'total employment' and 'trips'
% dimensions of the input space
%%
% The variable |S| contains the sigma values that specify the range of
% influence of a cluster center in each of the data dimensions. All cluster
% centers share the same set of sigma values.

S

%%
% |S| in this case has 6 columns representing the influence of the cluster
% centers on each of the 6 dimensions.
%

%% Generating the Fuzzy Inference System (FIS)
%
% |genfis2| is the function that creates a FIS using subtractive
% clustering. |genfis2| employs |subclust| behind the scenes to cluster the
% data and uses the cluster centers and their range of influences to build
% a FIS which will then be used to explore and understand traffic patterns.

myfis=genfis2(datin,datout,0.5);

%%
% The first argument is the input variables matrix |datin|, the second
% argument is the output variables matrix |datout| and the third argument
% is the |radii| that should be used while using |subclust|.
%
% |genfis2| assigns default names for inputs, outputs and membership
% functions. For our understanding it is beneficial to rename the inputs
% and outputs meaningfully.

% Assign names to inputs and outputs
myfis = setfis(myfis, 'input',1,'name','population');
myfis = setfis(myfis, 'input',2,'name','dwelling units');
myfis = setfis(myfis, 'input',3,'name','num vehicles');
myfis = setfis(myfis, 'input',4,'name','income');
myfis = setfis(myfis, 'input',5,'name','employment');
myfis = setfis(myfis, 'output',1,'name','num of trips');

%% Understanding the clusters-FIS relationship
% A FIS is composed of inputs, outputs and rules. Each input and
% output can have any number of membership functions. The rules dictate the
% behavior of the fuzzy system based on inputs, outputs and membership
% functions. |genfis2| constructs the FIS in an attempt to capture the the
% position and influence of each cluster in the input space. 
% 
% |myfis| is the FIS that |genfis2| has generated. Since the dataset has 5
% input variables and 1 output variable, |genfis2| constructs a FIS with
% 5 inputs and 1 output. Each input and output has as many membership
% functions as the number of clusters that |subclust| has identified. As
% seen previously, for the current dataset |subclust| identified 3
% clusters. Therefore each input and output will be characterized by 3
% membership functions. Also, the number of rules equals the number of
% clusters and hence 3 rules are created. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -