function [W, elapse] = constructW(fea,options)
% Usage:
% W = constructW(fea,options)
%
% fea: Rows of vectors of data points. Each row is x_i
% options: Struct value in Matlab. The fields in options that can be set:
% Metric - Choices are:
% 'Euclidean' - Will use the Euclidean distance of two data
% points to evaluate the "closeness" between
% them. [Default One]
% 'Cosine' - Will use the cosine value of two vectors
% to evaluate the "closeness" between them.
% A popular similarity measure used in
% Information Retrieval.
%
% NeighborMode - Indicates how to construct the graph. Choices
% are: [Default 'KNN']
% 'KNN' - k = 0
% Complete graph
% k > 0
% Put an edge between two nodes if and
% only if they are among the k nearst
% neighbors of each other. You are
% required to provide the parameter k in
% the options. Default k=5.
% 'Supervised' - k = 0
% Put an edge between two nodes if and
% only if they belong to same class.
% k > 0
% Put an edge between two nodes if
% they belong to same class and they
% are among the k nearst neighbors of
% each other.
% Default: k=0
% You are required to provide the label
% information gnd in the options.
%
% WeightMode - Indicates how to assign weights for each edge
% in the graph. Choices are:
% 'Binary' - 0-1 weighting. Every edge receiveds weight
% of 1. [Default One]
% 'HeatKernel' - If nodes i and j are connected, put weight
% W_ij = exp(-norm(x_i - x_j)/2t^2). This
% weight mode can only be used under
% 'Euclidean' metric and you are required to
% provide the parameter t.
% 'Cosine' - If nodes i and j are connected, put weight
% cosine(x_i,x_j). Can only be used under
% 'Cosine' metric.
%
% k - The parameter needed under 'KNN' NeighborMode.
% Default will be 5.
% gnd - The parameter needed under 'Supervised'
% NeighborMode. Colunm vector of the label
% information for each data point.
% bLDA - 0 or 1. Only effective under 'Supervised'
% NeighborMode. If 1, the graph will be constructed
% to make LPP exactly same as LDA. Default will be
% 0.
% t - The parameter needed under 'HeatKernel'
% WeightMode. Default will be 1
% bNormalized - 0 or 1. Only effective under 'Cosine' metric.
% Indicates whether the fea are already be
% normalized to 1. Default will be 0
% bSelfConnected - 0 or 1. Indicates whether W(i,i) == 1. Default 1
% if 'Supervised' NeighborMode & bLDA == 1,
% bSelfConnected will always be 1. Default 1.
%
%
% Examples:
%
% fea = rand(50,15);
% options = [];
% options.Metric = 'Euclidean';
% options.NeighborMode = 'KNN';
% options.k = 5;
% options.WeightMode = 'HeatKernel';
% options.t = 1;
% W = constructW(fea,options);
%
%
% fea = rand(50,15);
% gnd = [ones(10,1);ones(15,1)*2;ones(10,1)*3;ones(15,1)*4];
% options = [];
% options.Metric = 'Euclidean';
% options.NeighborMode = 'Supervised';
% options.gnd = gnd;
% options.WeightMode = 'HeatKernel';
% options.t = 1;
% W = constructW(fea,options);
%
%
% fea = rand(50,15);
% gnd = [ones(10,1);ones(15,1)*2;ones(10,1)*3;ones(15,1)*4];
% options = [];
% options.Metric = 'Euclidean';
% options.NeighborMode = 'Supervised';
% options.gnd = gnd;
% options.bLDA = 1;
% W = constructW(fea,options);
%
%
% For more details about the different ways to construct the W, please
% refer:
% Deng Cai, Xiaofei He and Jiawei Han, "Document Clustering Using
% Locality Preserving Indexing" IEEE TKDE, Dec. 2005.
%
%
% Written by Deng Cai (dengcai2 AT cs.uiuc.edu), April/2004, Feb/2006,
% May/2007
%
if (~exist('options','var'))
options = [];
else
if ~isstruct(options)
error('parameter error!');
end
end
%=================================================
if ~isfield(options,'Metric')
options.Metric = 'Cosine';
end
switch lower(options.Metric)
case {lower('Euclidean')}
case {lower('Cosine')}
if ~isfield(options,'bNormalized')
options.bNormalized = 0;
end
otherwise
error('Metric does not exist!');
end
%=================================================
if ~isfield(options,'NeighborMode')
options.NeighborMode = 'KNN';
end
switch lower(options.NeighborMode)
case {lower('KNN')} %For simplicity, we include the data point itself in the kNN
if ~isfield(options,'k')
options.k = 5;
end
case {lower('Supervised')}
if ~isfield(options,'bLDA')
options.bLDA = 0;
end
if options.bLDA
options.bSelfConnected = 1;
end
if ~isfield(options,'k')
options.k = 0;
end
if ~isfield(options,'gnd')
error('Label(gnd) should be provided under ''Supervised'' NeighborMode!');
end
if ~isempty(fea) && length(options.gnd) ~= size(fea,1)
error('gnd doesn''t match with fea!');
end
otherwise
error('NeighborMode does not exist!');
end
%=================================================
if ~isfield(options,'WeightMode')
options.WeightMode = 'Binary';
end
bBinary = 0;
switch lower(options.WeightMode)
case {lower('Binary')}
bBinary = 1;
case {lower('HeatKernel')}
if ~strcmpi(options.Metric,'Euclidean')
warning('''HeatKernel'' WeightMode should be used under ''Euclidean'' Metric!');
options.Metric = 'Euclidean';
end
if ~isfield(options,'t')
options.t = 1;
end
case {lower('Cosine')}
if ~strcmpi(options.Metric,'Cosine')
warning('''Cosine'' WeightMode should be used under ''Cosine'' Metric!');
options.Metric = 'Cosine';
end
if ~isfield(options,'bNormalized')
options.bNormalized = 0;
end
otherwise
error('WeightMode does not exist!'
Gabor小波+LBP特征提取+PCA+LPP降维_人脸识别_matlab
版权申诉
5星 · 超过95%的资源 89 浏览量
2022-04-14
21:47:54
上传
评论 5
收藏 20KB ZIP 举报
阿里matlab建模师
- 粉丝: 3205
- 资源: 2782
最新资源
- week6.1.7z
- 移动机器人自主路径规划之RRTStar算法MATLAB实现代码
- 基于Python+OpenCV+FFmpeg实现自动识别电影剪辑+分析剪辑主题颜色+源码+文档(毕业设计&课程设计&项目开发)
- 基于python的二手商品交易平台 python+django开发的供需平台
- 微信小程序源码 侧滑布局小程序 (源码下载 +内附使用说明)
- heima-JUC-资料
- coreg_FSL.sh
- ROS+YOLOV8+SLAM智能小车导航实战(四、激光雷达+SLAM建图)
- 什么是决策树,有哪些适用场景?
- 基于python开发的口红色号识别程序+源码+开发文档+源码解析(毕业设计&课程设计&项目开发)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页