public static void trainCachedNeuralNetworks(int cycles, int numTraining) {
    { double mse = 0.0;
      double absError = 0.0;
      double error = 0.0;
      double target = 0.0;
      double output = 0.0;
      int numEx = Logic.$TRAINING_EXAMPLES$.length();
      Vector index = Vector.newVector(numTraining);
      OutputStream lookPtr = null;
      Vector examples = Vector.newVector(numTraining);
      Vector netRecords = Vector.newVector(numTraining);

      if (numTraining > numEx) {
        System.out.print("Error: There are only " + numEx + " training examples");
        return;
      }
      { int i = Stella.NULL_INTEGER;
        int iter000 = 0;
        int upperBound000 = numTraining - 1;
        TrainingExample example = null;
        Cons iter001 = Logic.$TRAINING_EXAMPLES$.theConsList;

        for (;(iter000 <= upperBound000) &&
                  (!(iter001 == Stella.NIL)); iter000 = iter000 + 1, iter001 = iter001.rest) {
          i = iter000;
          example = ((TrainingExample)(iter001.value));
          (examples.theArray)[i] = example;
          (index.theArray)[i] = (IntegerWrapper.wrapInteger(i));
        }
      }
      { int i = Stella.NULL_INTEGER;
        int iter002 = 0;
        int upperBound001 = numTraining - 1;

        for (;iter002 <= upperBound001; iter002 = iter002 + 1) {
          i = iter002;
          { TrainingExample example = ((TrainingExample)((examples.theArray)[i]));
            int timestamp = Logic.getNowTimestamp();

            if ((!(example.cachedSolution == null)) &&
                (timestamp == example.timestamp)) {
              (netRecords.theArray)[i] = (((Cons)(example.cachedSolution)));
            }
            else {
              { Module currentModule = ((Module)(Stella.$MODULE$.get()));

                if (!(example.module == null)) {
                  example.module.changeModule();
                }
                (netRecords.theArray)[i] = (Logic.createCachedNetwork(example.query));
                example.cachedSolution = ((Cons)((netRecords.theArray)[i]));
                example.timestamp = timestamp;
                currentModule.changeModule();
              }
            }
          }
        }
      }
      System.out.println("Training Networks");
      { int cycle = Stella.NULL_INTEGER;
        int iter003 = 0;
        int upperBound002 = cycles - 1;

        loop002 : for (;iter003 <= upperBound002; iter003 = iter003 + 1) {
          cycle = iter003;
          mse = 0.0;
          absError = 0.0;
          if ((Logic.$NEURAL_NETWORK_TRAINING_METHOD$ == Logic.KWD_BACKPROP) ||
              (Logic.$NEURAL_NETWORK_TRAINING_METHOD$ == Logic.KWD_BACKPROPAGATION)) {
            Logic.shuffleVector(index);
          }
          else if (Logic.$NEURAL_NETWORK_TRAINING_METHOD$ == Logic.KWD_QUICKPROP) {
            Logic.clearAllSlopes();
          }
          else {
            { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

              stream000.nativeStream.print("`" + Logic.$NEURAL_NETWORK_TRAINING_METHOD$ + "' is not a valid case option");
              throw ((StellaException)(StellaException.newStellaException(stream000.theStringReader()).fillInStackTrace()));
            }
          }
          { int k = Stella.NULL_INTEGER;
            int iter004 = 0;
            int upperBound003 = numTraining - 1;

            for (;iter004 <= upperBound003; iter004 = iter004 + 1) {
              k = iter004;
              if (Logic.$TRACE_NEURAL_NETWORK_TRAINING$) {
                System.out.println("Example " + k + ": " + ((TrainingExample)((examples.theArray)[(((IntegerWrapper)((index.theArray)[k])).wrapperValue)])).query + "  " + ((TrainingExample)((examples.theArray)[(((IntegerWrapper)((index.theArray)[k])).wrapperValue)])).score);
              }
              target = ((TrainingExample)((examples.theArray)[(((IntegerWrapper)((index.theArray)[k])).wrapperValue)])).score;
              output = Logic.activateCachedNetwork(((Cons)((netRecords.theArray)[(((IntegerWrapper)((index.theArray)[k])).wrapperValue)])));
              error = Logic.computeError(target, output);
              if (Logic.$TRACE_NEURAL_NETWORK_TRAINING$) {
                System.out.println("   Output: " + output);
              }
              absError = absError + (((error < 0.0) ? (0.0 - error) : error));
              mse = mse + (error * error);
              if ((Logic.$NEURAL_NETWORK_TRAINING_METHOD$ == Logic.KWD_BACKPROPAGATION) ||
                  (Logic.$NEURAL_NETWORK_TRAINING_METHOD$ == Logic.KWD_BACKPROP)) {
                Logic.cachedBackpropagateError(((Cons)((netRecords.theArray)[(((IntegerWrapper)((index.theArray)[k])).wrapperValue)])), error);
              }
              else if (Logic.$NEURAL_NETWORK_TRAINING_METHOD$ == Logic.KWD_QUICKPROP) {
                Logic.cachedQuickpropagateError(((Cons)((netRecords.theArray)[(((IntegerWrapper)((index.theArray)[k])).wrapperValue)])), error);
              }
              else {
                { OutputStringStream stream001 = OutputStringStream.newOutputStringStream();

                  stream001.nativeStream.print("`" + Logic.$NEURAL_NETWORK_TRAINING_METHOD$ + "' is not a valid case option");
                  throw ((StellaException)(StellaException.newStellaException(stream001.theStringReader()).fillInStackTrace()));
                }
              }
            }
          }
          if (Logic.$NEURAL_NETWORK_TRAINING_METHOD$ == Logic.KWD_QUICKPROP) {
            Logic.modifyWeights();
          }
          if ((Logic.$SAVE_NETWORK_CYCLE$ > 0) &&
              ((cycle % Logic.$SAVE_NETWORK_CYCLE$) == 0)) {
            System.out.println("Saving networks");
            Logic.saveAllNeuralNetworks(Logic.$SAVE_NETWORK_FILE$);
          }
          if ((Logic.$ERROR_PRINT_CYCLE$ > 0) &&
              ((cycle % Logic.$ERROR_PRINT_CYCLE$) == 0)) {
            if (Logic.$SAVE_NETWORK_FILE$ != null) {
              if (lookPtr == null) {
                lookPtr = OutputFileStream.newOutputFileStream(Logic.$SAVE_NETWORK_FILE$ + ".err");
              }
              lookPtr.nativeStream.println("Cycle " + cycle + " Error: " + (absError / numTraining));
            }
            System.out.println("Cycle " + cycle + " Error: " + (absError / numTraining));
          }
          if ((mse / numTraining) < Logic.$ERROR_CUTOFF$) {
            break loop002;
          }
        }
      }
      if (lookPtr != null) {
        lookPtr.free();
      }
    }
  }