如何在tensorflow中实现优化功能? [英] How do I implement the optimization function in tensorflow?
本文介绍了如何在tensorflow中实现优化功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
minΣ(|| xi-X ci || ^ 2 +λ || ci ||),
minΣ(||xi-Xci||^2+ λ||ci||),
st cii = 0 ,
s.t cii = 0,
其中X是d * n形状的矩阵,C是n * n形状的矩阵,xi和ci分别表示X和C的列。
where X is a matrix of shape d * n and C is of the shape n * n, xi and ci means a column of X and C separately.
X在这里是已知的,并且基于X我们想找到C。
X is known here and based on X we want to find C.
推荐答案
通常,像这样的损失需要向量化,而不是使用列:
Usually with a loss like that you need to vectorize it, instead of working with columns:
loss = X - tf.matmul(X, C)
loss = tf.reduce_sum(tf.square(loss))
reg_loss = tf.reduce_sum(tf.square(C), 0) # L2 loss for each column
reg_loss = tf.reduce_sum(tf.sqrt(reg_loss))
total_loss = loss + lambd * reg_loss
要对C的对角线实施零约束,最好的方法是用另一个常数<$将它添加到损失中c $ c> lambd2 :
reg_loss2 = tf.trace(tf.square(C))
total_loss = total_loss + lambd2 * reg_loss2
这篇关于如何在tensorflow中实现优化功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文