/godot_plugin-neural-network

Oops! It seems like the repository was missing a description, but no worries, a new commit has been made to add it. Let's keep it a secret from everyone else!

Primary LanguageGDScriptBSD 2-Clause "Simplified" LicenseBSD-2-Clause

The add-on provides 2 classes: NNET and RLNNET. NNET stands for NeuralNet Toolkit, while RLNNET stands for Reinforcement Learning NeuralNet Toolkit.

The distinction between NNET and RLNNET is as follows: NNET employs back propagation for training, whereas RLNNET utilizes reinforcement learning.

Usage of NNET

Neural network initialization The initial step requires you to provide the architecture of your neural network. Firstly, specify the number of input neurons, followed by the sequence of hidden layers, and conclude with the number of output layers in the format [1,6,5,1].

The second step entails providing the learning rate for the neural network.

In the third step, you are required to indicate "true" or "false" depending on whether you intend to use bias neurons or not.

By the fourth step, it is optional to provide a range for the neural network. If no range is specified, the default range will be from 0 to 1.

Here is an example of how it may appear in your code:

  func _ready() -> void:
	  var neural_network_1 = NNET.new([1,6,5,1], 0.1, true)
	  var neural_network_2 = NNET.new([5,20,30,40,15], 0.005, true)
	  var neural_nrtwork_3 = NNET.new([2,1], 0.5, true)

Training

To initiate the training of your neural network, it is imperative to supply input data. Accomplish this by employing the command "set_input()".

Subsequently, you will need to establish the desired output you aim to obtain. This can be accomplished by utilizing the command "set_desired_output()".

In the present context, to facilitate the learning process of the neural network, employ the "train()" function. "train()" function accepts an optional parameter that determines the number of training iterations. If this parameter is not specified, it defaults to 1.

Using

To acquire the output of the neural network, firstly execute the "run()" command, followed by the utilization of the "get_output()" function. If you solely desire to display the output in the console, utilize the "show_result()" command.

func _ready() -> void:
	  var neural_network = NNET.new([1,3,1], 0.1, true)
	  
	  neural_network.set_input([0.5])
	  neural_network.set_desired_output([0.333])
	  
	  neural_network.run()
	  neural_network.show_result()
	  
	  neural_network.train()
	  print(neural_network.get_output())
	  
	  neural_network.train(500)
	  neural_network.show_result()

Usage of RLNNET

Neural network initialization

To begin, you need to define the structure of your neural network. Start by indicating the amount of input neurons, then outline the arrangement of hidden layers, and conclude by specifying the number of output layers.

In the second step, provide the curiosity (mutation) rate. This parameter indicates the degree of deviation of the new approach from the previous one.

The remaining steps are identical.

Training

The training procedure is presented within an unceasing, continuous loop.

In the primary stage, it is crucial to provide the input data via the utilization of the function "set_input()". Subsequently, retrieve the output data by employing the function "get_output()".

Once the neural network has been tested, evaluate the effectiveness of the output and assign the computed value to the "set_reward()" function. Subsequently, invoke the "update()" function.

Continue iterating until the desired results are attained.

Using

Upon completion of the training procedure, the neural network can be obtained by employing the "get_main()" function.

Rough code example:

var neural_network : RLNNET = RLNNET.new([2,5,1], 0.00006, true)

func _physics_process(_delta : float) -> void:
	  neural_network.set_input(InputData)
	  var output = neural_network.get_output()
	  
	  execute(output)
	  
	  if game_has_finished:
	  	  neural_network.set_reward(reward)
	  	  neural_network.update()
	  	  restart_game()