Avoiding $0$ in the $\log()$ function

58 Views Asked by At

I have an issue with my costfunction:

$$\sum A_{ij}\cdot\log(p_{ij})+(1-A_{ij})\cdot \log(1-p_{ij})$$

Where $p_{ij} = sigmoid(-\|z_i-z_j\|+\beta)$ and $A_{ij}$ is $1$ if connected $0$ if not.

Im solving this numerically using stochastic gradient decent, however after sufficently many iterations the $p_{ij}$ term becomes $0$ and the $\log$ returns $-\infty$ which ruins the rest of the sum.

If it is possible, can I rewrite the cost function so that the 0 value in $p_{ij}$ does not make the $-\infty$ situation occur?