srendle / libfm

Library for factorization machines
GNU General Public License v3.0
1.49k stars 414 forks source link

How to implement MCMC #39

Open EagleYing opened 5 years ago

EagleYing commented 5 years ago

I code as the MCMC algorithm in Paper Factorization Machine with libFM in python ,but it not work ,is there any detail I can do ?

chihming commented 5 years ago

Did you trace the code in libfm?

EagleYing commented 5 years ago

您是否在libfm中跟踪了代码?

I read the code in libfm and coded refer to the file fm_learnmcmc.h, I found the draw function is a little different to the pseudo code. For example:

double w0_sigma_sqr;
  double w0_mean = 0;
  for (uint i = 0; i < train.num_cases; i++) {
    w0_mean += cache[i].e - w0;
  }
  w0_sigma_sqr = (double) 1.0 / (reg + alpha * train.num_cases);
  w0_mean = - w0_sigma_sqr * (alpha * w0_mean - w0_mean_0 * reg);
  // update w0
  double w0_old = w0;

In the pseudo code it was described as: image I coded it as :

w0_mean =  w0_sigma_sqr * (alpha * w0_mean + w0_mean_0 * reg + mu_w0 * lambda_w0)

And can I use numpy.random.gamma instead of ran_gaussian?