[Edit: all this has a very simple solution: the matrix uses a single data type instead of a double by default]
I just noticed a somewhat peculiar (I think) behavior in Matlab and wonder what causes it. I have a 10000x500 M matrix with values ββfrom
min(min(M)) = -226.9723 to
max(max(M)) = 92.8173
and
exp(-227) = 2.6011e-99
exp(93) = 2.4512e+40
but if I run out of the whole matrix, this matrix has the values ββinf:
ii = isinf(exp(M));
sum(sum(ii))
ans =
2
How does Matlab store values ββin a matrix so that operations with individual elements can give a different result than when performing the same operation on the matrix itself?
those.
expM = exp(M);
exp(M(1)) == expM(1) ; %can be false, which I find surprising
I know that I need to change the algorithm, since high values ββwill give inaccurate results, even if I can avoid the inf values. This happens in the formula for calculating an artificial neural network, for example:
sum(log(1+exp(ones(numcases,1)*b_h + data*w_vh)),2);
, : , , , ,
log(1+exp(ones(numcases,1)*b_h + data*w_vh)
ones(numcases,1)*b_h + data*w_vh
? , ,
log(1+exp(x)) β log(exp(x)) β x, for large x
btw: , max, max (max (M))?