/* Update embeddings */ void Update(real *vec_u, real *vec_v, real *vec_error, int label) { real x = 0, g; for (int c = 0; c != dim; c++) x += vec_u[c] * vec_v[c]; g = (label - FastSigmoid(x)) * rho; for (int c = 0; c != dim; c++) vec_error[c] += g * vec_v[c]; for (int c = 0; c != dim; c++) vec_v[c] += g * vec_u[c]; }
/* Update embeddings & return likelihood */ real Update(real *vec_u, real *vec_v, real *vec_error, int label) { real x = 0, f, g; for (int c = 0; c != dim; c++) x += vec_u[c] * vec_v[c]; f = FastSigmoid(x); g = (label - f) * rho; for (int c = 0; c != dim; c++) vec_error[c] += g * vec_v[c]; for (int c = 0; c != dim; c++) vec_v[c] += g * vec_u[c]; return label > 0? fast_log(f+LOG_MIN): fast_log(1-f+LOG_MIN); }