public Layer(int numberOfNeurons, int numberOfInputsPerNeuron, string activationFunctionName, DebugNeuronSpawner debugNeuronSpawner) { if (debugNeuronSpawner != null) { debugNeuronSpawner.addLayer(); } for (int i = 0; i < numberOfNeurons; i++) { GameObject debugNeuron = null; if (debugNeuronSpawner != null) { debugNeuron = debugNeuronSpawner.addNeuron(i, numberOfNeurons, numberOfInputsPerNeuron); } neurons.Add(new Neuron(numberOfInputsPerNeuron, numberOfNeurons, activationFunctionName, debugNeuron)); } }
/// <summary> /// This constructor prepared the neural network by setting the hyperparameters, as well as the inputs /// and prepares the visualization of the neural net, if an inworld spawner for the neurons is given. /// Alpha indicates the learning rate, while it will be multiplied with alphaDecay after every learning /// cycle to gradually decay the learning rate. alphaDecay = 1.0 disables the decay. /// Lambda indicates a rate by which the neurons weights decay every learning cycle. This is a technique /// to combat overfitting and exploding gradients. /// </summary> /// <param name="numberOfInputs">An integer indicating the number of inputs to expect</param> /// <param name="alpha">A double representing the learning rate</param> /// <param name="alphaDecay">A double to reduce alpha (and lambda) over time by multiplication</param> /// <param name="lambda">A double to reduce weights by the amount of lambda multiplied with the actual weight</param> /// <param name="debugNeuronSpawnerGameObject">A gameobject variable containing a special spawner for neuron visualization if needed</param> public ANN(int numberOfInputs, double alpha, double alphaDecay = 1.0d, double lambda = 0.0d, GameObject debugNeuronSpawnerGameObject = null) { this.numInputs = numberOfInputs; this.alpha = alpha; this.alphaDecay = alphaDecay; this.lambda = lambda; // debug output visualization debugInputNeurons = new List<GameObject>(); if (debugNeuronSpawnerGameObject != null) { debugNeuronSpawner = debugNeuronSpawnerGameObject.GetComponent<DebugNeuronSpawner>(); for (int i = 0; i < numberOfInputs; i++) { debugInputNeurons.Add(debugNeuronSpawner.addNeuron(i, numberOfInputs, 0)); } } }