public DataContainer?ComputeLayer(decimal[] Input) { if (NeuronObjects != null) { for (int i = 0; i < NeuronObjects.Length; i++) { GameObject ActivationObj = NeuronObjects[i].transform.Find("UI/Activation").gameObject; ActivationObj.GetComponent <Text>().text = Input[i].ToString(); } } if (IsExecuting) { Debug.Log("Trying to Feed Forward but the neural network is executing."); return(null); } m_Input = Input; IsExecuting = true; var Result = NextLayer.ComputeLayer(Input); IsExecuting = false; return(Result); }
public DataContainer?ComputeLayer(decimal[] Input) { if (NextLayer == null) { Debug.LogError(string.Format("Unvalid next layer for Hidden Layer {0}.", LayerName)); return(null); } if (Perceptrons == null || Perceptrons.Length == 0) { Debug.LogError(string.Format("Hidden Layer {0} has no valid perceptrons, can't get perceptrons values...", LayerName)); return(null); } // Check for: // Activation Function. // Previous Layers' Input? int perceptronsLength = Perceptrons.Length; decimal[] PerceptronValues = new decimal[perceptronsLength]; // For every perceptron, we compute the weighted-sum + bias and with the applied activation function. for (int i = 0; i < perceptronsLength; i++) { PerceptronValues[i] = Perceptrons[i].Compute(Input, ActivationFunction); } // Cosmetics at the end. if (NeuronObjects != null) { for (int i = 0; i < Perceptrons.Length; i++) { GameObject NeuronObj = Perceptrons[i].NeuronObj; for (int j = 0; j < PreviousLayer.GetNeuronObjects().Length; j++) { GameObject OtherNeuronObj = PreviousLayer.GetNeuronObjects()[j]; LineRenderer lr = Perceptrons[i].GetConnectionLiner(j); Perceptrons[i].UpdateActivationText(); lr.SetPositions(new Vector3[] { NeuronObj.transform.position, OtherNeuronObj.transform.position }); } } } return(NextLayer.ComputeLayer(GetInput())); }