code: public Tensor forward() {
          VarTensor[] varBeliefs = inf.getOutput().varBeliefs;
          double l2dist = s.zero();
  
          for (Var v : vc.getVars()) {
              if (v.getType() == VarType.PREDICTED) {
                  VarTensor marg = varBeliefs[v.getId()];
                  int goldState = vc.getState(v);
                  for (int c=0; c<marg.size(); c++) {
                      double goldMarg = (c == goldState) ? s.one() : s.zero();
                      double predMarg = marg.getValue(c);
                      double diff = s.minus(Math.max(goldMarg, predMarg), Math.min(goldMarg, predMarg));
                      l2dist = s.plus(l2dist, s.times(diff, diff));
                  }
              }
          }
          if (s.lt(l2dist, s.zero())) {
              log.warn("L2 distance shouldn't be less than 0: " + l2dist);
          }
          y = Tensor.getScalarTensor(s, l2dist);
          return y;        
      }
docs: Forward pass: y = \sum_i \sum_{x_i} (b(x_i) - b*(x_i))^2 , where b*(x_i) are the marginals given by
  taking the gold variable assignment as a point mass distribution. Note the sum is over all
  variable assignments to the predicted variables.