code: static void addExpectedPartials(FactorGraph fg, FgInferencer inferencer, double multiplier, IFgModel gradient) {
          // For each factor...
          for (int factorId=0; factorId<fg.getNumFactors(); factorId++) {     
              Factor f = fg.getFactor(factorId);
              if (f instanceof GlobalFactor) {
                  ((GlobalFactor) f).addExpectedPartials(gradient, multiplier, inferencer, factorId);
              } else {
                  VarTensor marg = inferencer.getMarginalsForFactorId(factorId);
                  f.addExpectedPartials(gradient, marg, multiplier);
              }
          }
      }
docs: Computes the expected partials (i.e. feature counts for exponential family factors) for a
  factor graph, and adds them to the gradient after scaling them.
  
  @param fg The factor graph.
  @param inferencer The inferencer for a clamped factor graph, which has already been run.
  @param multiplier The value which the expected partials will be multiplied by.
  @param gradient The OUTPUT gradient vector to which the scaled expected partials will be
  added.