Пример #1
0
    IEnumerator AnimationRoutine()
    {
        LayerNeuron inputLayer       = layers[0];
        LayerNeuron firstHiddenLayer = layers[1];

        for (int j = 0; j < firstHiddenLayer.neurons.Length; j++)
        {
            for (int i = 0; i < inputLayer.neurons.Length; i++)
            {
                //On grossie le neuron assez de fois pour qu'il se fasse absorbé par les nexts layers
                Neuron currentNeuron = inputLayer.neurons[i];
                currentNeuron.Growth();
            }
            yield return(new WaitForSeconds(timeBetweenNeuronConnection));
        }

        for (int i = 0; i < layers.Length; i++)
        {
            LayerNeuron currentLayer = layers[i];
            for (int j = 0; j < currentLayer.neurons.Length; j++)
            {
                Neuron currentNeuron       = currentLayer.neurons[j];
                int    connectionPerNeuron = currentNeuron.incomingConnections.Length;

                for (int k = 0; k < connectionPerNeuron; k++)
                {
                    currentNeuron.PlayAnimationWithConnection(k);
                    yield return(new WaitForSeconds(timeBetweenNeuronConnection));
                }

                yield return(new WaitForSeconds(timeBetweenNeuronConnection));
            }
            yield return(new WaitForSeconds(timeBetweenNeuronConnection));
        }


        LayerNeuron outputLayer     = layers[layers.Length - 1];
        LayerNeuron lastHiddenLayer = layers[layers.Length - 2];

        for (int j = 0; j < lastHiddenLayer.neurons.Length; j++)
        {
            for (int i = 0; i < outputLayer.neurons.Length; i++)
            {
                //On grossie le neuron assez de fois pour qu'il se fasse absorbé par les nexts layers
                Neuron currentNeuron = outputLayer.neurons[i];
                currentNeuron.Shrink();
            }
            yield return(new WaitForSeconds(timeBetweenNeuronConnection));
        }
        StartCoroutine(AnimationRoutine());
    }
Пример #2
0
 void CreateConnections()
 {
     //On commence a la première hidden layer, donc i = 1
     for (int i = 1; i < layers.Length; i++)
     {
         LayerNeuron previousLayer = layers[i - 1];
         LayerNeuron currentLayer  = layers[i];
         for (int j = 0; j < currentLayer.neurons.Length; j++)
         {
             //Create connections
             Neuron currentNeuron = currentLayer.neurons[j];
             currentNeuron.incomingConnections = new Connection[previousLayer.neurons.Length];
             for (int k = 0; k < currentNeuron.incomingConnections.Length; k++)
             {
                 CreateSingleConnection(i, previousLayer, currentLayer, currentNeuron, k);
             }
         }
     }
 }
Пример #3
0
    void GenerateNeuralNetwork()
    {
        for (int i = 0; i < layerDimension.Length; i++)
        {
            GameObject  layer       = new GameObject("Layer" + i);
            LayerNeuron layerNeuron = layer.AddComponent <LayerNeuron>();
            layer.transform.SetParent(transform);
            layer.transform.localScale = Vector3.one;

            for (int j = 0; j < layerDimension[i]; j++)
            {
                Neuron newNeuron = Instantiate(prefabNeuron, layer.transform);
                newNeuron.transform.localScale    = Vector3.one;
                newNeuron.transform.localPosition = CalculateNeuronPosition(i, j, layerDimension[i]);
            }
            layerNeuron.Initiate();
        }
        layers = GetComponentsInChildren <LayerNeuron>();
    }
Пример #4
0
    private void CreateSingleConnection(int i, LayerNeuron previousLayer, LayerNeuron currentLayer, Neuron currentNeuron, int k)
    {
        //On spawn autant de connection quia de neuron au previous layer
        Connection newConnection = Instantiate(prefabConnection, currentNeuron.transform);

        currentNeuron.incomingConnections[k] = newConnection;
        newConnection.transform.localScale   = Vector3.one;
        //On connect tous les neurons du previous layer au current neuron
        newConnection.from = previousLayer.neurons[k];
        newConnection.to   = currentNeuron;

        float layerT  = (float)i / layers.Length;
        float neuronT = (float)k / currentLayer.neurons.Length;

        Color layerColor  = gradientLayer.Evaluate(layerT);
        Color neuronColor = gradientNeuron.Evaluate(neuronT);
        Color startColor  = (layerColor * weightColorLayer + neuronColor * (1 - weightColorLayer));

        newConnection.enableColor  = startColor;
        newConnection.disableColor = endColor;

        newConnection.ConnectionFromTo();
    }