code: private void calculateVariance() {
          for (Tuple t : trainingData) {
              int index = model.labelIndexer.getIndex(t.label);
  
              double[] meanVector = Arrays.copyOf(model.meanVectors[index], model.meanVectors[index].length);
              VectorUtils.scale(meanVector, -1);
              double[] diff = VectorUtils.addition(t.vector.getVector(), meanVector);
  //                    VectorUtils.zip(t.vector.getVector(), model.meanVectors[index], (x, y) -> x - y);
              diff = Arrays.stream(diff).map(x -> x * x).toArray();
  
              double[] varianceVector = VectorUtils.addition(model.varianceVectors[index], diff);
              //  VectorUtils.zip(model.varianceVectors[index], diff, (x, y) -> x + y);
              model.varianceVectors[index] = varianceVector;
          }
  
          for (int i = 0; i < model.varianceVectors.length; i++) {
              double[] varianceVector = model.varianceVectors[i];
              // Denominator is Sample Var instead of Population Var
              VectorUtils.scale(varianceVector, 1.0 / (count[i] - 1));
              model.varianceVectors[i] = varianceVector;
          }
  
          for (int i = 0; i < model.varianceVectors.length; i++) {
              for (int j = 0; j < model.varianceVectors[i].length; j++) {
                  if (model.varianceVectors[i][j] == 0) {
                      LOG.warn("variance is 0 for label " + model.labelIndexer.labelIndexer.inverse().get(i) + " at dimension " + j);
                      model.varianceVectors[i][j] = Double.MIN_VALUE;
                  }
              }
          }
      }
docs: Step 2