A light-weight neural network framework built for academic use.
LightNeuNet borrowed syntaxes from Keras.
fromlnn.modelimportSequentialModelfromlnn.layersimportInput, Dense, Output# Initialize a fully connected neural networkmodel=SequentialModel()
# Add the input layermodel.add(Input(32))
# Add the first and second hidden layermodel.add(Dense(18, activation='tanh', kernel_initializer='uniform', use_bias=True))
model.add(Dense(18, activation='tanh', kernel_initializer='uniform', use_bias=True))
# Add the output layermodel.add(Output(num_output_units, activation='softmax', use_bias=True))
# Compile the modelmodel.compile()
# The summary of the model builtmodel.summary()
# Train the modelforiinrange(5000):
model.fit(X_train, y_train, learning_rate=0.01)
y_pred=model.predict(X_test)fromlnn.genetic_algorithm.layersimportGAInput, GADense, GAOutputfromlnn.genetic_algorithm.modelimportGAModel, GASequentialModel# Create the modelmodel=GAModel(population=500)
# Add input layer to the modelmodel.add(GAInput(32))
# Add the first hidden layer to the modelmodel.add(GADense(24, activation='tanh', use_bias=True, kernel_initializer='uniform'))
# Add the second hidden layer to the modelmodel.add(GADense(18, activation='tanh', use_bias=True, kernel_initializer='uniform'))
# Add the output layer to the modelmodel.add(GAOutput(4, activation='softmax', use_bias=False))
# Generate the populationmodel.new_population()
defplay_snake(model, params=(...)):
# Code to play the snake
...
iters=10000foriinrange(iters):
model.simulate(play_snake, keep_rate=0.6, mutate_rate=0.01, params=(False,))