Why does times(A,B) gives me negative values when A and B don't have any ???
3 次查看(过去 30 天)
显示 更早的评论
Hello, i'm working with this code, which is a non-negative factorization :
function [G] = NN_Update_G(G_0,S,H,V,nb_iter,beta)
mustBePositive(G_0);
G=G_0;
if beta<1
gamma_beta=1/(1-beta);
elseif 1<=beta && beta <=2
gamma_beta = 1;
else
gamma_beta = 1/(beta-1);
end
G_old=G;
for k=1:nb_iter
mustBePositive(G_old);
product = (((S'*(((S*G_old*H).^(beta-2)).*V)*H'))./(S'*((S*G_old*H).^(beta-1))*H')).^gamma_beta;
mustBePositive(product);mustBePositive(G_old);
G = times(G_old,product);
mustBePositive(G);
G_old = G;
end
end
I don't know how but only the last mustBepostive(G) is triggered. It's the only one, which would mean that both G and product are positive beforehand.
I really hope someone can make some sense out of this because it's really bothering me not understanding what's the problem...
采纳的回答
Steven Lord
2025-6-19
Try using mustBeNonnegative instead of mustBePositive. This will detect if your calculation underflowed to 0.
x = realmin
mustBePositive(x) % true so no error
y = x*x % underflow
mustBeNonnegative(y) % true so no error
mustBePositive(y) % false
0 个评论
更多回答(1 个)
dpb
2025-6-19
移动:dpb
2025-6-19
mustBePositive(0)
shows that zero is not considered positive by mustBePositive. You don't give any klews as to what the magnitudes of inputs are, but one must surmise that one or more of the elements must have underflowed owing to a large exponent in the product expression.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!