code: @Override
      public Beliefs forward() {
          // Initialization.
          initForward();
          
          // Message passing.
          loops:
          for (int iter=-1; iter < prm.maxIterations; iter++) {
              List<Object> order = sched.getOrder(iter, fg);
              for (Object item : order) {
                  List<Integer> edges = CachingBpSchedule.toEdgeList(fg, item);
                  List<?> elems = CachingBpSchedule.toFactorEdgeList(item);
                  TapeEntry te = prm.keepTape ? new TapeEntry(item, edges) : null;
                  for (Object elem : elems) {
                      if (elem instanceof Integer) {
                          forwardCreateMessage((Integer) elem);
                      } else if (elem instanceof AutodiffGlobalFactor) {
                          forwardGlobalFacToVar((AutodiffGlobalFactor) elem, te);
                      } else {
                          throw new RuntimeException("Unsupported type in schedule: " + elem.getClass());
                      }
                  }
                  for (Integer edge : edges) {
                      normalizeAndAddToTape(edge, te);
                  }
                  for (Integer edge : edges) {
                      forwardSendMessage(edge, iter);
                  }
                  if (prm.keepTape) { tape.add(te); }
                  if (isConverged()) {
                      // Stop on convergence: Break out of inner and outer loop.
                      log.trace("Stopping on convergence. Iterations = {}", (iter+1));
                      break loops;
                  }
              }
              maybeWriteAllBeliefs(iter);
          }
          
          log.trace("Oscillation rate: {}", ((double) oscillationCount.get() / sendCount.get()));
          
          forwardVarAndFacBeliefs();
          b = new Beliefs(varBeliefs, facBeliefs);
          return b;
      }
docs: /* ---------------------------- BEGIN: Forward Pass Methods ---------------------