// File: hkbu-victor[P]SFastLDA/super_fast_final1_w.cpp
// Function: eval_likelihood()
void eval_likelihood(){

	//assume symmetric alpha and beta
  double log_likelihood = 0.0;
  double ALPHA_BAR = ALPHA[0] * T;
  double BETA_BAR = WBETA;
  int wi, di, j;

  double lgamma_beta = lgamma(BETA);
  double lgamma_alpha = lgamma(ALPHA[0]);

  for (wi=0; wi<W; wi++){
     wi_pair_val = wpVal[wi];
     for (j=0; j<W_pair_count[wi]; j++){
    	log_likelihood += lgamma( BETA + wi_pair_val[ j ] ) - lgamma_beta;
     }
  }

  for (di=0; di<D; di++){
	  di_pair = dpPair[di];
	  for (j=0; j<D_pair_count[di]; j++){
		  log_likelihood += lgamma(ALPHA[0] + di_pair[j].value) - lgamma_alpha;
	  }
  }

  for (j=0; j<T; j++)
	  log_likelihood += lgamma(BETA_BAR) - lgamma(BETA_BAR + ztot[j] );

  for (di=0; di<D; di++){
	  log_likelihood += lgamma(ALPHA_BAR) - lgamma(ALPHA_BAR + doc_lens[di] );
  }

  log_likelihood = log_likelihood / nTokens;

  printf("LOG LIKELIHOOD (per token) : %lf\n", log_likelihood);

}

// Assembly:
subq $0x48, %rsp
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x875c(%rip), %rax      # 0xa1a0
movsd (%rax), %xmm0
cvtsi2sdl 0x86a8(%rip), %xmm1 # 0xa0f8
mulsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x8726(%rip), %xmm0     # 0xa188
movsd %xmm0, 0x30(%rsp)
movsd 0x8710(%rip), %xmm0     # 0xa180
callq 0x1080
movsd %xmm0, 0x18(%rsp)
movq 0x871e(%rip), %rax      # 0xa1a0
movsd (%rax), %xmm0
callq 0x1080
movsd %xmm0, 0x10(%rsp)
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x8665(%rip), %eax      # 0xa108
jge 0x1b30
movq 0x8720(%rip), %rax      # 0xa1d0
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8708(%rip)      # 0xa1c8
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
movq 0x869d(%rip), %rcx      # 0xa170
movslq 0x2c(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x1b1e
movsd 0x869b(%rip), %xmm0     # 0xa180
movq 0x86dc(%rip), %rax      # 0xa1c8
movslq 0x24(%rsp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
addsd %xmm1, %xmm0
callq 0x1080
subsd 0x18(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1ac8
jmp 0x1b20
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x1a99
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x85c2(%rip), %eax      # 0xa104
jge 0x1bd3
movq 0x86d1(%rip), %rax      # 0xa220
movslq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x86b9(%rip)      # 0xa218
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
movq 0x85f6(%rip), %rcx      # 0xa168
movslq 0x28(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x1bc1
movq 0x861d(%rip), %rax      # 0xa1a0
movsd (%rax), %xmm0
movq 0x868a(%rip), %rax      # 0xa218
movslq 0x24(%rsp), %rcx
cvtsi2sdl 0x4(%rax,%rcx,8), %xmm1
addsd %xmm1, %xmm0
callq 0x1080
subsd 0x10(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1b67
jmp 0x1bc3
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x1b38
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x8513(%rip), %eax      # 0xa0f8
jge 0x1c3e
movsd 0x30(%rsp), %xmm0
callq 0x1080
movsd %xmm0, 0x8(%rsp)
movsd 0x30(%rsp), %xmm0
movq 0x851b(%rip), %rax      # 0xa120
movslq 0x24(%rsp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
addsd %xmm1, %xmm0
callq 0x1080
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1bdb
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x84b4(%rip), %eax      # 0xa104
jge 0x1ca7
movsd 0x38(%rsp), %xmm0
callq 0x1080
movsd %xmm0, (%rsp)
movsd 0x38(%rsp), %xmm0
movq 0x84e9(%rip), %rax      # 0xa158
movslq 0x28(%rsp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
addsd %xmm1, %xmm0
callq 0x1080
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x1c46
movsd 0x40(%rsp), %xmm0
cvtsi2sdl 0x8463(%rip), %xmm1 # 0xa118
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x40(%rsp), %xmm0
leaq 0x5634(%rip), %rdi      # 0x7300
movb $0x1, %al
callq 0x1040
addq $0x48, %rsp
retq
nopl (%rax,%rax)