微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R NMF 中的自定义目标函数 - 为其添加另一个术语

如何解决R NMF 中的自定义目标函数 - 为其添加另一个术语

我在使用 R 的 NMF 函数实现我想要的确切模型时遇到问题。 我想要的是通过添加一个术语来改变 NMF 模型的“正常”目标函数,这说明了我拥有的一些数据。

也就是说,我希望使用最小化欧几里得距离并使用乘法更新(“lee”算法)的“标准”NMF模型,然后将另一个形式的项添加到该距离上:

α ⋅ ‖W(1) − γ M‖

其中 M 是“我的数据”,W(1) 是第一个隐藏因子,α 和 γ 是要调整的参数。

文档不是很有帮助。以下示例来自 R 的 NMF documentation

n <- 50; r <- 3; p <- 20
V <-syntheticNMF(n,r,p)

my.algorithm <- function(x,seed,scale.factor=1){
  # do something with starting point
  # ...
  # for example:
  # 1. compute principal components
  pca <- prcomp(t(x),retx=TRUE)
  # 2. use the absolute values of the first PCs for the Metagenes
  # Note: the factorization rank is stored in object 'start'
  factorization.rank <- nbasis(seed)
  Metagenes(fit(seed)) <- abs(pca$rotation[,1:factorization.rank])
  # use the rotated matrix to get the mixture coefficient
  # use a scaling factor (just to illustrate the use of extra parameters)
  Metaprofiles(fit(seed)) <- t(abs(pca$x[,1:factorization.rank])) / scale.factor
  # return updated data
  return(seed)
}


my.objective <- function(model,target,p_alpha,p_gamma){
  (sum((target-fitted(model))^4 ) )^{1/4}
}

res = nmf(V,3,my.algorithm,seed='nndsvd',objective=my.objective)

但是,如果我理解正确的话,为了改变目标函数,我需要从头开始编写自己的算法,我不知道该怎么做。

关于如何实现我想要的任何帮助,将不胜感激。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?