Пример #1
0
        /// <summary>
        /// Returns a list with floats ranging between 0 and 1
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public List <float> GetNext()
        {
            List <float> input = Input;

            //update it to hold new input
            if (input.Count != weights[0].Length)
            {
                float[][] newInputLayer = new float[input.Count][];
                float[]   weightConnections;
                for (int neuron = 0; neuron < weights[0].Length; neuron++)
                {
                    weightConnections = weights[0][neuron];
                    for (int weight = 0; weight < input.Count; weight++)
                    {
                        newInputLayer[neuron][weight] =
                            weight < weightConnections.Length ?
                            weightConnections[weight] : memoryPrefab[neuron][weight - input.Count];
                    }
                }

                weights[0] = newInputLayer;
            }

            //nX = neurons list length, nX = neurons y length, nZ = next neurons list length
            int          nX = neurons.Length - 1, nY, nZ;
            float        res;
            List <float> results = input, newInput = new List <float>();

            for (int neuronList = 0; neuronList < nX; neuronList++)
            {
                nY = neurons[neuronList].Length;
                nZ = neurons[neuronList + 1].Length;
                for (int i = 0; i < nZ; i++)
                {
                    newInput.Add(0);
                }

                for (int neuron = 0; neuron < nY; neuron++)
                {
                    res = results[neuron];
                    for (int weightConnection = 0; weightConnection < nZ; weightConnection++)
                    {
                        newInput[weightConnection] += res * weights[neuronList][neuron][weightConnection];
                    }
                }

                results = Methods.CloneList(newInput);
                for (int f = 0; f < results.Count; f++)
                {
                    results[f] = Methods.Activation(results[f]);
                }

                newInput.Clear();
            }

            //change it from -1 and 1 to 0 and 1
            for (int returnable = 0; returnable < results.Count; returnable++)
            {
                results[returnable] = (results[returnable] + 1) / 2;
            }

            return(results);
        }