/// <summary>
    /// Displays the connections of a neuron of one layer to all neurons of the next layer.
    /// </summary>
    /// <param name="neuronIndex">The neuron to display the connections of.</param>
    /// <param name="currentLayer">The layer of the neuron to be displayed.</param>
    /// <param name="nextLayer">The layer the neuron to be displayed is connected to.</param>
    public void DisplayConnections(int neuronIndex, NeuralLayer currentLayer, UINeuralNetworkLayerPanel nextLayer)
    {
        //Set dummyConnection to active again, just in case it was hidden at some point.
        Image dummyConnection = Connections[0];

        dummyConnection.gameObject.SetActive(true);

        //Duplicate dummyConnection
        for (int i = Connections.Count; i < currentLayer.OutputCount; i++)
        {
            Image newConnection = Instantiate(dummyConnection);
            newConnection.transform.SetParent(this.transform, false);
            Connections.Add(newConnection);
        }

        //Destroy all unnecessary connections
        for (int i = this.Connections.Count - 1; i >= currentLayer.OutputCount; i++)
        {
            Image toBeDestroyed = Connections[i];
            Connections.RemoveAt(i);
            Destroy(toBeDestroyed);
        }


        //Position connections
        for (int i = 0; i < Connections.Count; i++)
        {
            PositionConnection(Connections[i], nextLayer.Nodes[i], neuronIndex, i, currentLayer.Weights);
        }
    }
    /// <summary>
    /// Displays the given neural network.
    /// </summary>
    /// <param name="neuralNet">The neural network to be displayed.</param>
    public void Display(NeuralNetwork neuralNet)
    {
        UINeuralNetworkLayerPanel dummyLayer = Layers[0];

        //Duplicate dummyLayer
        for (int i = Layers.Count; i < neuralNet.Layers.Length + 1; i++)
        {
            UINeuralNetworkLayerPanel newPanel = Instantiate(dummyLayer);
            newPanel.transform.SetParent(this.transform, false);
            Layers.Add(newPanel);
        }

        //Destory all unnecessary layers
        for (int i = this.Layers.Count - 1; i >= neuralNet.Layers.Length + 1; i++)
        {
            UINeuralNetworkLayerPanel toBeDestroyed = Layers[i];
            Layers.RemoveAt(i);
            Destroy(toBeDestroyed);
        }

        //Set layer contents
        for (int l = 0; l < this.Layers.Count - 1; l++)
        {
            this.Layers[l].Display(neuralNet.Layers[l]);
        }

        this.Layers[Layers.Count - 1].Display(neuralNet.Layers[neuralNet.Layers.Length - 1].OutputCount);

        StartCoroutine(DrawConnections(neuralNet));
    }
Esempio n. 3
0
 /// <summary>
 /// Displays all connections from between the given two layers.
 /// </summary>
 /// <param name="currentLayer">The layer that is connected to the other layer.</param>
 /// <param name="nextLayer">The layer that the other layer is connected to.</param>
 public void DisplayConnections(NeuralLayer currentLayer, UINeuralNetworkLayerPanel nextLayer)
 {
     for (int i = 0; i < Nodes.Count; i++)
     {
         Nodes[i].DisplayConnections(i, currentLayer, nextLayer);
     }
 }
Esempio n. 4
0
    public void DisplayConnections(int neuronIndex, NeuralLayer currentLayer, UINeuralNetworkLayerPanel nextLayer)
    {
        Image dummyConnection = Connections[0];

        dummyConnection.gameObject.SetActive(true);

        for (int i = Connections.Count; i < currentLayer.OutputCount; i++)
        {
            Image newConnection = Instantiate(dummyConnection);
            newConnection.transform.SetParent(this.transform, false);
            Connections.Add(newConnection);
        }

        for (int i = this.Connections.Count - 1; i >= currentLayer.OutputCount; i++)
        {
            Image toBeDestroyed = Connections[i];
            Connections.RemoveAt(i);
            Destroy(toBeDestroyed);
        }

        for (int i = 0; i < Connections.Count; i++)
        {
            PositionConnection(Connections[i], nextLayer.Nodes[i], neuronIndex, i, currentLayer.Weights);
        }
    }