inference/dimmwitted/src/factor_graph.cc
// Inline by defined here; accessible only from current file.
Inline by defined here; accessible only from current file.
Inline by defined here ; accessible only from current file .
inline void FactorGraph::sgd_on_factor(size_t factor_id, double stepsize,
                                       size_t vid, size_t evidence_value,
                                       InferenceResult &infrs) {
  const Factor &factor = factors[factor_id];
  if (infrs.weights_isfixed[factor.weight_id]) {
    return;
  }
  double pot_evid = factor.potential(vifs.get(), infrs.assignments_evid.get(),
                                     vid, evidence_value);
  double pot_free = factor.potential(vifs.get(), infrs.assignments_free.get());
  double gradient = pot_free - pot_evid;
  infrs.update_weight(factor.weight_id, stepsize, gradient);
}
inline void FactorGraph :: sgd_on_factor ( size_t factor_id , double stepsize , size_t vid , size_t evidence_value , InferenceResult & infrs ) { const Factor & factor = factors [ factor_id ] ; if ( infrs . weights_isfixed [ factor . weight_id ] ) { return ; } double pot_evid = factor . potential ( vifs . get ( ) , infrs . assignments_evid . get ( ) , vid , evidence_value ) ; double pot_free = factor . potential ( vifs . get ( ) , infrs . assignments_free . get ( ) ) ; double gradient = pot_free - pot_evid ; infrs . update_weight ( factor . weight_id , stepsize , gradient ) ; }
Inline by defined here; accessible only from current file.
Inline by defined here ; accessible only from current file .
// stochastic gradient ascent // decrement weight with stepsize * gradient of weight // gradient of weight = E[f] - E[f|D], where D is evidence variables, // f is the factor function, E[] is expectation. Expectation is // calculated using a sample of the variable.