Are folds changed between epochs in K-Fold Cross Validation? 2 Related question about Cross-Validation (In the scope of Neural Networks):
1) Let's say we train our neural network for 100 epochs and apply 5-fold cross validation. In that case, should I use the same folds over 100 epochs or at each epoch should epochs need to be re-created ? In other words which one of the following 2 pseudo code is correct ? 
for i=1:EPOCH
     folds = create_folds(training_data)     
     for j=1:length(folds)
         for k in range(length(folds))
             if j != k
                 model <- train(folds[j])
             end

         end
         evaluate(model,folds[j])
         reset-model-weights(model)
     end
end

Or 
folds = create_folds(training_data) # Look at the change in this line place
for i=1:EPOCH     
     for j=1:length(folds)
         for k in range(length(folds))
             if j != k
                 model <- train(folds[j])
             end

         end
         evaluate(model,folds[j])
         reset-model-weights(model)
     end
end

2) My second question is if I have a single file for all train validation and test splits, should I keep test set constant ( I mean take the 10% of the file first and use that part always as a test set and then apply k-Fold cross validation for the remaning part for creating train/val sets) or should test set also be changed ?
 A: I cannot say I fully understand your pseudocode, however, the usual procedure is following:


*

*Test set: Take a part of your data (if needed, use stratified sampling or similar technique to ensure this test set is a good representative of your data) and put it aside. Do not use this data for learning nor model selection.

*Parameter tuning: Use k-fold cross validation to find the best parameters.

*Training: Train the model with parameters selected in step 2 on the whole dataset.

*Testing: See how your model performs on the testing data put aside in step 1.

I hope this should answer both of your questions. But, more specifically and using some fancy-like math notation:


*

*Split your training data $D$ into $K$ splits, $\{D_k; k\in[1;K]\}$.

*Repeat $K$-times: (kinda for k in range(K))
a. Train the network using splits $\bigcup D_{j; j\neq k}$ as training data.
b. Evaluate the trained network on the remaining part, $D_k$. Do not use this part for evaluation after each epoch. If you want to do early stopping, define yet another validation set for each $\bigcup D_{j; j\neq k}$.
I think your second code sample reflects this.
Regarding your second question, always keep a separate test set.
Also, this is a very common topic on this site. See some related answers:


*

*Neural network training without early stopping

*Choosing best training-validation split?

*Is epoch optimization in CV with constant mini-batch size even possible?

*Should I use the same weight initialization for each fold in cross validation?
