code: public void pretrainLayer(int layerIdx, DataSetIterator iter, int numEpochs) {
          Preconditions.checkState(numEpochs > 0, "Number of epochs (%s) must be a positive number", numEpochs);
  
          if (flattenedGradients == null) {
              initGradientsView();
          }
          if (layerIdx >= layers.length) {
              throw new IllegalArgumentException(
                      "Cannot pretrain layer: layerIdx (" + layerIdx + ") >= numLayers (" + layers.length + ")");
          }
  
          Layer layer = layers[layerIdx];
          if (!layer.isPretrainLayer())
              return;
  
          if(numEpochs > 1 && !iter.resetSupported())
              throw new IllegalStateException("Cannot fit multiple epochs (" + numEpochs + ") on an iterator that doesn't support resetting");
  
          if (!iter.hasNext() && iter.resetSupported()) {
              iter.reset();
          }
  
          log.info("Starting unsupervised training on layer " + layerIdx + " for " + numEpochs + " epochs");
          for(int i=0; i<numEpochs; i++ ) {
              if(i > 0)
                  iter.reset();
  
              while (iter.hasNext()) {
                  DataSet next = iter.next();
                  input = next.getFeatures();
                  pretrainLayer(layerIdx, input);
              }
          }
  
          int ec = getLayer(layerIdx).conf().getEpochCount() + 1;
          getLayer(layerIdx).conf().setEpochCount(ec);
      }
docs: Perform layerwise unsupervised training on a single pre-trainable layer in the network (VAEs, Autoencoders, etc)
  for the specified number of epochs<br>
  If the specified layer index (0 to numLayers - 1) is not a pretrainable layer, this is a no-op.
  
  @param layerIdx  Index of the layer to train (0 to numLayers-1)
  @param iter      Training data
  @param numEpochs Number of epochs to fit the specified layer for