主要内容

nnmf.

Nonnegative matrix factorization

描述

example

[W,H] = nnmf(A,k)因素n-通过-mmatrixAinto nonnegative factorsW(n-通过-k)和H(k-通过-m)。分解并不准确;W * H.is a lower-rank approximation toA。因素WH最小化根均方差异D之间AW * H.

d = norm(a  -  w * h,'fro'/ sqrt(n * m)

分组使用从随机初始值开始的迭代算法WH。因为根均值均衡D可能具有局部最小值,重复的因素可能会产生不同WH。Sometimes the algorithm converges to a solution of lower rank thank, which can indicate that the result is not optimal.

example

[W,H] = nnmf(A,k,名称,Value)使用一个或多个名称值对参数修改分解。例如,您可以通过设置请求重复的因素'复制'整数值大于1。

[W,H,D] = nnmf(___)also returns the root mean square residualD使用any of the input argument combinations in the previous syntaxes.

例子

collapse all

Load the sample data.

loadfisheriris

Compute a nonnegative rank-two approximation of the measurements of the four variables in Fisher's iris data.

RNG(1)重复性的%[w,h] = nnmf(meas,2);H
h =2×4.0.6945 0.2856 0.6220 0.2218 0.8020 0.5683 0.1834 0.0149

The first and third variables in测定(萼片长度和花瓣长度,分别为0.6945和0.6220)为第一栏提供相对强大的重量W。第一和第二变量测定(萼片长度和萼片宽度,分别为0.8020和0.5683)为第二栏提供相对强的重量W

创建一个biplot数据和变量测定in the column space ofW

biplot(H','Scores',w,'VarLabels',{'sl','sw','pl','pw'}); axis([0 1.1 0 1.1]) xlabel('Column 1')ylabel('Column 2')

从随机数组开始Xwith rank 20, try a few iterations at several replicates using the multiplicative algorithm.

rng默认重复性的%x = rand(100,20)*兰特(20,50);opt = statset('maxiter',5,'显示','最后');[W0,H0] = nnmf(x,5,'复制'10,......'选项',opt,......'算法',“MULT”);
rep iteration rms resid |delta x| 1 5 0.560887 0.0245182 2 5 0.66418 0.0364471 3 5 0.609125 0.0358355 4 5 0.608894 0.0415491 5 5 0.619291 0.0455135 6 5 0.621549 0.0299965 7 5 0.640549 0.0438758 8 5 0.673015 0.0366856 9 5 0.606835 0.0318931 10 5 0.633526 0.0319591 Final root mean square residual = 0.560887

Continue with more iterations from the best of these results using alternating least squares.

opt = statset('Maxiter',1000,'显示','最后');[w,h] = nnmf(x,5,'w0',W0,'H0',H0,......'选项',opt,......'算法','als');
rep iteration rms resid |delta x| 1 24 0.257336 0.00271859 Final root mean square residual = 0.257336

Input Arguments

collapse all

矩阵到分解,指定为真实矩阵。

例:rand(20,30)

数据类型:|

因素排名,被指定为正整数。由此产生的因素WHhavekcolumns and rows, respectively.

例:3

数据类型:|

名称-Value Pair Arguments

Specify optional comma-separated pairs of名称,Value论点。名称is the argument name andValue是相应的价值。名称must appear inside quotes. You can specify several name and value pair arguments in any order asname1,value1,...,namen,valuen

例:[W,H] = nnmf(A,k,'Algorithm','mult','Replicates',10)选择乘法更新算法和十个重复以提高结果

分解算法,指定为逗号分隔对组成'算法''als'(alternating least squares) or“MULT”(a multiplicative update algorithm).

The'als'算法通常更稳定并在较少的迭代中收敛。每次迭代都需要更长时间。因此,默认最大值为50,通常会在内部测试中提供令人满意的结果。

The“MULT”algorithm typically has faster iterations and requires more of them. The default maximum is 100. This algorithm tends to be more sensitive to starting values and, therefore, seems to benefit more from running multiple replications.

例:'算法','mult'

数据类型:char|

Initial value ofW, specified as the comma-separated pair consisting of'w0'A.nn-通过-k矩阵,其中n是行的行数A, andk是第二个输入论点nnmf.

数据类型:|

Initial value ofH, specified as the comma-separated pair consisting of'H0'A.k-通过-m矩阵,其中k是第二个输入论点nnmf., andmis the number of columns ofA

数据类型:|

算法选项,指定为逗号分隔对组成'选项'A.structure returned by the实例化function.nnmf.使用以下选项结构的以下字段。

Field 描述 Values
显示 迭代显示水平
  • 'off'(默认) - 无显示

  • '最后'- 显示最终结果

  • 'iter'- 中间结果的迭代显示

maxiter. 最大迭代次数 正整数。默认为50.为了'als'算法和算法100.为了“MULT”算法。与优化设置不同,达到maxiter.迭代被视为融合。
塔尔芬 Termination tolerance on the change in size of the residual Nonnegative value. The default is1E-4
TolX 关于元素相关变化的终止耐受WH Nonnegative value. The default is1E-4
UseParallel 指示并行计算 逻辑价值。默认值falseindicates not to compute in parallel, andtrue表示并行计算。并行计算需要并行计算工具箱™许可证。
UseSubstreams Type of reproducibility when computing in parallel
  • false(默认) - 不要重复计算

  • 'mlfg6331_64'

  • 'MRG32K3A'

For details, see并行统计计算中的再现性

溪流 Arandstream.这些对象的对象或单元格阵列
  • If you do not specify溪流,nnmf.使用默认流或流。

  • IfUseParallelistrueUseSubstreamsisfalse, specify a cell array ofrandstream.对象与并行池相同的大小。否则,请指定单个randstream.目的。

例:'选项',statset('Display','iter','MaxIter',50)

数据类型:struct

Number of times to repeat the factorization, specified as the comma-separated pair consisting of'复制'A.正整数。The algorithm chooses new random starting values forWH在每个复制中,除了指定时在第一个复制'w0''H0'。如果指定大于的值1,您可以通过设置获得更好的结果Algorithm“MULT”。看到改变算法

例:10.

数据类型:|

输出参数

collapse all

Nonnegative left factor ofA,返回一个n-通过-k矩阵。n是行的行数A, andk是第二个输入论点nnmf.

WH是标准化的,使行的行为H有单位长度。列的列W通过减少长度来命令。

非负面正确因素A, returned as ak-通过-m矩阵。k是第二个输入论点nnmf., andmis the number of columns ofA

WH是标准化的,使行的行为H有单位长度。列的列W通过减少长度来命令。

根均方剩余,作为非负标量返回。

d = norm(a  -  w * h,'fro'/ sqrt(n * m)

参考资料

[1] Berry,Michael W.,Murray Browne,Amy N. Langville,V.Paul Pauca和Robert J. Plemons。“近似非环境矩阵分解的算法和应用。”Computational Statistics & Data Analysis52, no. 1 (September 2007): 155–73.https://doi.org/10.1016/j.csda.2006.11.006

扩展能力

Introduced in R2008a