feature extraction by using sparse filtering -凯发k8网页登录
feature extraction by using sparse filtering
description
returns
a sparse filtering model object that contains the results from applying
sparse filtering to the table or matrix of predictor data mdl
= sparsefilt(x
,q
)x
containing p variables. q
is
the number of features to extract from x
, therefore sparsefilt
learns
a p-by-q
matrix of transformation
weights. for undercomplete or overcomplete feature representations, q
can
be less than or greater than the number of predictor variables, respectively.
to access the learned transformation weights, use
mdl.transformweights
.to transform
x
to the new set of features by using the learned transformation, passmdl
andx
to .
uses
additional options specified by one or more mdl
= sparsefilt(x
,q
,name,value
)name,value
pair
arguments. for example, you can standardize the predictor data or
apply l2 regularization.
examples
create sparse filter
create a sparsefiltering
object by using the sparsefilt
function.
load the sampleimagepatches
image patches.
data = load('sampleimagepatches');
size(data.x)
ans = 1×2
5000 363
there are 5,000 image patches, each containing 363 features.
extract 100 features from the data.
rng default % for reproducibility q = 100; obj = sparsefilt(data.x,q,'iterationlimit',100)
warning: solver lbfgs was not able to converge to a solution.
obj = sparsefiltering modelparameters: [1x1 struct] numpredictors: 363 numlearnedfeatures: 100 mu: [] sigma: [] fitinfo: [1x1 struct] transformweights: [363x100 double] initialtransformweights: [] properties, methods
sparsefilt
issues a warning because it stopped due to reaching the iteration limit, instead of reaching a step-size limit or a gradient-size limit. you can still use the learned features in the returned object by calling the transform
function.
restart sparsefilt
continue optimizing a sparse filter.
load the sampleimagepatches
image patches.
data = load('sampleimagepatches');
size(data.x)
ans = 1×2
5000 363
there are 5,000 image patches, each containing 363 features.
extract 100 features from the data and use an iteration limit of 20.
rng default % for reproducibility q = 100; mdl = sparsefilt(data.x,q,'iterationlimit',20);
warning: solver lbfgs was not able to converge to a solution.
view the resulting transformation matrix as image patches.
wts = mdl.transformweights; w = reshape(wts,[11,11,3,q]); [dx,dy,~,~] = size(w); for f = 1:q wvec = w(:,:,:,f); wvec = wvec(:); wvec =(wvec - min(wvec))/(max(wvec) - min(wvec)); w(:,:,:,f) = reshape(wvec,dx,dy,3); end m = ceil(sqrt(q)); n = m; img = zeros(m*dx,n*dy,3); f = 1; for i = 1:m for j = 1:n if (f <= q) img((i-1)*dx 1:i*dx,(j-1)*dy 1:j*dy,:) = w(:,:,:,f); f = f 1; end end end imshow(img,'initialmagnification',300);
the image patches appear noisy. to clean up the noise, try more iterations. restart the optimization from where it stopped for another 40 iterations.
mdl = sparsefilt(data.x,q,'iterationlimit',40,'initialtransformweights',wts);
warning: solver lbfgs was not able to converge to a solution.
view the updated transformation matrix as image patches.
wts = mdl.transformweights; w = reshape(wts,[11,11,3,q]); [dx,dy,~,~] = size(w); for f = 1:q wvec = w(:,:,:,f); wvec = wvec(:); wvec =(wvec - min(wvec))/(max(wvec) - min(wvec)); w(:,:,:,f) = reshape(wvec,dx,dy,3); end m = ceil(sqrt(q)); n = m; img = zeros(m*dx,n*dy,3); f = 1; for i = 1:m for j = 1:n if (f <= q) img((i-1)*dx 1:i*dx,(j-1)*dy 1:j*dy,:) = w(:,:,:,f); f = f 1; end end end imshow(img,'initialmagnification',300);
these images are less noisy.
input arguments
x
— predictor data
numeric matrix | table
predictor data, specified as an n-by-p numeric
matrix or table. rows correspond to individual observations and columns
correspond to individual predictor variables. if x
is
a table, then all of its variables must be numeric vectors.
data types: single
| double
| table
q
— number of features to extract
positive integer
number of features to extract from the predictor data, specified as a positive integer.
sparsefilt
stores a p-by-q
transform
weight matrix in mdl.transformweights
. therefore,
setting very large values for q
can result in greater
memory consumption and increased computation time.
data types: single
| double
name-value arguments
specify optional pairs of arguments as
name1=value1,...,namen=valuen
, where name
is
the argument name and value
is the corresponding value.
name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
before r2021a, use commas to separate each name and value, and enclose
name
in quotes.
example: 'standardize',true,'lambda',1
standardizes
the predictor data and applies a penalty of 1
to
the transform weight matrix.
iterationlimit
— maximum number of iterations
1000
(default) | positive integer
maximum number of iterations, specified as the comma-separated
pair consisting of 'iterationlimit'
and a positive
integer.
example: 'iterationlimit',1e6
data types: single
| double
verbositylevel
— verbosity level
0
(default) | nonnegative integer
verbosity level for monitoring algorithm convergence, specified
as the comma-separated pair consisting of 'verbositylevel'
and
a value in this table.
value | description |
---|---|
0 | sparsefilt does not display convergence
information at the command line. |
positive integer | sparsefilt displays convergence information
at the command line. |
convergence information
heading | meaning |
---|---|
fun value | objective function value. |
norm grad | norm of the gradient of the objective function. |
norm step | norm of the iterative step, meaning the distance between the previous point and the current point. |
curv | ok means the weak wolfe condition is satisfied.
this condition is a combination of sufficient decrease of the objective
function and a curvature condition. |
gamma | inner product of the step times the gradient difference, divided by the inner product of the gradient difference with itself. the gradient difference is the gradient at the current point minus the gradient at the previous point. gives diagnostic information on the objective function curvature. |
alpha | step direction multiplier, which differs from 1 when
the algorithm performed a line search. |
accept | yes means the algorithm found an acceptable
step to take. |
example: 'verbositylevel',1
data types: single
| double
lambda
— l2 regularization coefficient value
0
(default) | positive numeric scalar
l2 regularization
coefficient value for the transform weight matrix, specified as the
comma-separated pair consisting of 'lambda'
and
a positive numeric scalar. if you specify 0
, the
default, then there is no regularization term in the objective function.
example: 'lambda',0.1
data types: single
| double
standardize
— flag to standardize predictor data
false
(default) | true
flag to standardize the predictor data, specified as the comma-separated
pair consisting of 'standardize'
and true
(1
)
or false
(0
).
if standardize
is true
,
then:
example: 'standardize',true
data types: logical
initialtransformweights
— transformation weights that initialize optimization
randn(p,q)
(default) | numeric matrix
transformation weights that initialize optimization, specified
as the comma-separated pair consisting of 'initialtransformweights'
and
a p-by-q
numeric matrix. p must
be the number of columns or variables in x
and q
is
the value of q
.
tip
you can continue optimizing a previously returned transform
weight matrix by passing it as an initial value in another call to sparsefilt
.
the output model object mdl
stores
a learned transform weight matrix in the transformweights
property.
example: 'initialtransformweights',mdl.transformweights
data types: single
| double
gradienttolerance
— relative convergence tolerance on gradient norm
1e-6
(default) | positive numeric scalar
relative convergence tolerance on gradient norm, specified as
the comma-separated pair consisting of 'gradienttolerance'
and
a positive numeric scalar. this gradient is the gradient of the objective
function.
example: 'gradienttolerance',1e-4
data types: single
| double
steptolerance
— absolute convergence tolerance on step size
1e-6
(default) | positive numeric scalar
absolute convergence tolerance on the step size, specified as
the comma-separated pair consisting of 'steptolerance'
and
a positive numeric scalar.
example: 'steptolerance',1e-4
data types: single
| double
output arguments
mdl
— learned sparse filtering model
sparsefiltering
model object
learned sparse filtering model, returned as a model object.
to access properties of mdl
, use dot notation.
for example:
to access the learned transform weights, use
mdl.transformweights
.to access the fitting information structure, use
mdl.fitinfo
.
to find sparse filtering coefficients for new data, use the function.
algorithms
the sparsefilt
function creates a nonlinear
transformation of input features to output features. the transformation
is based on optimizing an objective function that encourages the representation
of each example by as few output features as possible while at the
same time keeping the output features equally active across examples.
for details, see .
version history
introduced in r2017a
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
select a web site
choose a web site to get translated content where available and see local events and offers. based on your location, we recommend that you select: .
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.
americas
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)