Skip to main content
. 2025 Nov 15;25(22):6981. doi: 10.3390/s25226981
Algorithm 1 CNN-LSTM-GA: Feature selection and hyperparameter optimization
  • Input: D—Dataset, Npop—population size, Ngen—number of generations, pc—crossover probability, pm—mutation probability  

  • Output:  Best individual I* and corresponding CNN-LSTM model M*  

  •   1:

    Split D into train (40%), validation (40%) and test (20%) subsets;

    // Initialize population P with Npop individuals

  •   2:

    for each individual iP do

  •   3:

          Randomly initialize feature subset Fi and model hyperparameters Hi;

  •   4:

    end for

  •   5:

    for generation = 1 to Ngen do

  •   6:

          for each individual iP do

  •   7:

                Decode chromosome → feature subset Fi and model hyperparameters Hi;

  •   8:

                Build CNN-LSTM(Hi);

  •   9:

                Construct Ttrain and Ttest datasets from EEG data using feature subset Fi;

  • 10:

                Train CNN-LSTM(Hi) model with Ttrain;

  • 11:

                Compute fitness f(i) as the F1-score of CNN_LSTM(Hi) evaluated on Tvalidation;

  • 12:

          end for

  • 13:

          Apply tournament selection to choose parents based on f(i);

  • 14:

          For each parent pair, generate two offspring using crossover with probability pc.

  • 15:

          for each offspring gene g with probability pm do

  • 16:

                if g is Boolean then

  • 17:

                      Flip gene g;

  • 18:

                else if g is Integer or Real then

  • 19:

                      Apply window mutation;

  • 20:

                else if g is Nominal then

  • 21:

                      Replace with random category;

  • 22:

                end if

  • 23:

          end for

  • 24:

          Form new population P combining best individuals and offspring;

  • 25:

    end for

  • 26:

    Select best individual I*=argmaxif(i);

  • 27:

    Decode individual I*→ feature subset Fi and model hyperparameters Hi;

  • 28:

    Build CNN-LSTM(Hi);

  • 29:

    Construct Ttrain and Ttest datasets from EEG data using feature subset Fi;

  • 30:

    Train CNN-LSTM(Hi) model with Ttrain;

  • 31:

    Evaluate final model M* on Ttest;

  • 32:

    return I*,M*