Matlab: exp (X) gives inf, although exp (max (X)) does not

[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))?

+3
1

, : single, , , , . , . , :)

+3

Source: https://habr.com/ru/post/1755365/


All Articles