code: public int numVariables() {
      int maxVar = 0;
      for (Factor f : factors) {
        for (int n : f.neigborIndices) {
          if (n > maxVar) maxVar = n;
        }
      }
      return maxVar + 1;
    }
docs: The number of variables in this graphical model.