How can i use logsumexp trick to this?

159 Views Asked by At

I m trying to compute $\frac{\sum_{k=1}^K q_k \sum_{i=1}^N \exp(- \sum_{j=1}^J P \exp(\alpha_{i,j})+ \alpha_{i,j} \hspace{1mm} cj)}{\sum_{k=1}^K q_k \sum_{i=1}^N \exp(- \sum_{j=1}^J (P-1)\exp(\alpha_{i,j})+ \alpha_{i,j} \hspace{1mm} cj )} \quad $ but the both are too small so the computer round it to $0$ and give me $\frac{0}{0}$ wich is so problematic, so i want to pass into log using logsumexp trick.

So how can i can i calculate $log( \sum_{k=1}^K q_k \sum_{i=1}^N \exp(- \sum_{j=1}^J P \exp(\alpha_{i,j})+ \alpha_{i,j} \hspace{1mm} cj) )$ ?

knowing that :

  • $\sum_{k=1}^K q_k=1$
  • $\alpha_{i} $ is relied to the sum of k ( because $\alpha_{i} \sim N(0, \Sigma^{(k)}$ )
  • P is a big integer
  • cj is an integer for all j

logsumpexp trick is a method to calculate the log of sums $\log \sum_{i} \exp{(\theta_i)} = \theta_* + \log \sum_{i} \exp{(\theta_i - \theta_*)}$ where $\theta_* = \max_{i} \theta_i$

thank you