p300_detector.py
def dnn(X, y, optimizer=optimizers.Adam(learning_rate=0.001), loss='mse'):
    '''
    This function trains a neural network on given data.

    Parameters
    ----------
    X : 2d array: sample x feature
        DESCRIPTION. Training data
    y : 1d array
        DESCRIPTION. Labels
    optimizer : optimizer object, optional
        DESCRIPTION. The optimizer for neural network
        The default is optimizers.Adam().
    loss : string, optional
        DESCRIPTION. The loss functoin for neural network
        The default is 'mse'.

    Returns
    -------
    history : network object
        DESCRIPTION. The trained network information

    '''
    # split the data into training, validating, and testing datasets
    X_train, X_test, y_train, y_test = train_test_split(X, y)
    
    # design neural network architecture
    layers = [
        Flatten(),
        Dense(70, activation='relu', 
              kernel_regularizer=keras.regularizers.l1(l=0.01)),
        Dense(10, activation='relu'),
        Dense(1, activation='sigmoid')
    ]
    dnn = Sequential(layers)
    # compile neural network
    dnn.compile(optimizer=optimizer, loss=loss, 
                  metrics=['accuracy'])
    # train the network and save each epoch output in the history list
    history = dnn.fit(X_train, y_train, batch_size=16, epochs=200, 
                      validation_split=0.2, verbose=0, callbacks=[])
    # plot the performance
    label = 'neural_network'
    plt.figure()
    plt.plot(history.history['accuracy'], label="acc")
    plt.plot(history.history['val_accuracy'], label="val_acc")
    plt.legend()
    plt.title(label)
    plt.savefig(label+'.png')
    
    label='nn_confusion_matrix'
    plot_matrix(X_test, y_test, dnn, label)
    
    # return trained network info
    return history

    This function trains a neural network on given data.

    Parameters
    ----------
    X : 2d array: sample x feature
        DESCRIPTION. Training data
    y : 1d array
        DESCRIPTION. Labels
    optimizer : optimizer object, optional
        DESCRIPTION. The optimizer for neural network
        The default is optimizers.Adam().
    loss : string, optional
        DESCRIPTION. The loss functoin for neural network
        The default is 'mse'.

    Returns
    -------
    history : network object
        DESCRIPTION. The trained network information

    
This function trains a neural network on given data.
Parameters

X : 2d array: sample x feature
DESCRIPTION. Training data
y : 1d array
DESCRIPTION. Labels
optimizer : optimizer object, optional
DESCRIPTION. The optimizer for neural network
The default is optimizers.Adam().
loss : string, optional
DESCRIPTION. The loss functoin for neural network
The default is 'mse'.

Returns

history : network object
DESCRIPTION. The trained network information
This function trains a neural network on given data . Parameters X : 2d array : sample x feature DESCRIPTION . Training data y : 1d array DESCRIPTION . Labels optimizer : optimizer object optional DESCRIPTION . The optimizer for neural network The default is optimizers . Adam () . loss : string optional DESCRIPTION . The loss functoin for neural network The default is ' mse ' . Returns history : network object DESCRIPTION . The trained network information
def dnn(X, y, optimizer=optimizers.Adam(learning_rate=0.001), loss='mse'):
    X_train, X_test, y_train, y_test = train_test_split(X, y)
    layers = [
        Flatten(),
        Dense(70, activation='relu', 
              kernel_regularizer=keras.regularizers.l1(l=0.01)),
        Dense(10, activation='relu'),
        Dense(1, activation='sigmoid')
    ]
    dnn = Sequential(layers)
    dnn.compile(optimizer=optimizer, loss=loss, 
                  metrics=['accuracy'])
    history = dnn.fit(X_train, y_train, batch_size=16, epochs=200, 
                      validation_split=0.2, verbose=0, callbacks=[])
    label = 'neural_network'
    plt.figure()
    plt.plot(history.history['accuracy'], label="acc")
    plt.plot(history.history['val_accuracy'], label="val_acc")
    plt.legend()
    plt.title(label)
    plt.savefig(label+'.png')
    label='nn_confusion_matrix'
    plot_matrix(X_test, y_test, dnn, label)
    return history
def dnn ( X , y , optimizer = optimizers . Adam ( learning_rate = 0.001 ) , loss = 'mse' ) : X_train , X_test , y_train , y_test = train_test_split ( X , y ) layers = [ Flatten ( ) , Dense ( 70 , activation = 'relu' , kernel_regularizer = keras . regularizers . l1 ( l = 0.01 ) ) , Dense ( 10 , activation = 'relu' ) , Dense ( 1 , activation = 'sigmoid' ) ] dnn = Sequential ( layers ) dnn . compile ( optimizer = optimizer , loss = loss , metrics = [ 'accuracy' ] ) history = dnn . fit ( X_train , y_train , batch_size = 16 , epochs = 200 , validation_split = 0.2 , verbose = 0 , callbacks = [ ] ) label = 'neural_network' plt . figure ( ) plt . plot ( history . history [ 'accuracy' ] , label = "acc" ) plt . plot ( history . history [ 'val_accuracy' ] , label = "val_acc" ) plt . legend ( ) plt . title ( label ) plt . savefig ( label + '.png' ) label = 'nn_confusion_matrix' plot_matrix ( X_test , y_test , dnn , label ) return history
This function trains a neural network on given data.
This function trains a neural network on given data .
'''
    This function trains a neural network on given data.

    Parameters
    ----------
    X : 2d array: sample x feature
        DESCRIPTION. Training data
    y : 1d array
        DESCRIPTION. Labels
    optimizer : optimizer object, optional
        DESCRIPTION. The optimizer for neural network
        The default is optimizers.Adam().
    loss : string, optional
        DESCRIPTION. The loss functoin for neural network
        The default is 'mse'.

    Returns
    -------
    history : network object
        DESCRIPTION. The trained network information

    ''' # split the data into training, validating, and testing datasets # design neural network architecture # compile neural network # train the network and save each epoch output in the history list # plot the performance # return trained network info
X
y
optimizer
loss