code: private IntIntDenseVector[][] countFeatures(FgExampleList data, FactorTemplateList templates) {
          IntIntDenseVector[][] counts = new IntIntDenseVector[numTemplates][];
          for (int t=0; t<numTemplates; t++) {
              FactorTemplate template = templates.get(t);
              int numConfigs = template.getNumConfigs();
              int numFeats = template.getAlphabet().size();
              counts[t] = new IntIntDenseVector[numConfigs];
              for (int c=0; c<numConfigs; c++) {
                  counts[t][c] = new IntIntDenseVector(numFeats);
              }
          }
          for (int i=0; i<data.size(); i++) {
              LFgExample ex = data.get(i);
              FactorGraph fg = ex.getFactorGraph();
              for (int a=0; a<ex.getFactorGraph().getNumFactors(); a++) {
                  Factor f = fg.getFactor(a);
                  if (f instanceof ObsFeatureCarrier && f instanceof TemplateFactor) {
                      int t = templates.getTemplateId((TemplateFactor) f);
                      if (t != -1) {
                          FeatureVector fv = ((ObsFeatureCarrier) f).getObsFeatures();
                          // We must clamp the predicted variables and loop over the latent ones.
                          VarConfig predVc = ex.getGoldConfigPred(a);
                          IntIter iter = IndexForVc.getConfigIter(ex.getFactorGraph().getFactor(a).getVars(), predVc);
                          while (iter.hasNext()) {
                              // The configuration of all the latent/predicted variables,
                              // where the predicted variables have been clamped.
                              int config = iter.next();
                              for (IntDoubleEntry entry : fv) {
                                  counts[t][config].add(entry.index(), 1);
                              }
                          }
                      }
                  }
              }
          }
          return counts;
      }
docs: Counts the number of times each feature appears in the gold training data.