示例#1
0
        /// <summary>
        /// Create new NeuralNetworkEvolver to train on specific input/target data.
        /// </summary>
        /// <param name="breed">Breeding flag.</param>
        /// <param name="sourcenn">NeuralNetwork to evolve.</param>
        /// <param name="nThreads">Number of threads to simulate evolution on.</param>
        /// <param name="inData">Input data.</param>
        /// <param name="targetDat">Target output data.</param>
        public NeuralNetworkEvolver(bool breed, NeuralNetwork sourcenn, int nThreads, float[][] inData, float[][] targetDat)
        {
            numThreads              = nThreads;
            sourceNetwork           = sourcenn;
            inputOutputLossFunction = premadePerfFunc;
            inputData  = inData;
            targetData = targetDat;

            breeding = breed;

            threads       = new Thread[numThreads];
            subjects      = new NeuralNetworkProgram[numThreads];
            readyNextData = new bool[numThreads];

            for (int i = 0; i < nThreads; i++)
            {
                int ci = i;
                threads[i]       = new Thread(() => evolverThread(ci));
                readyNextData[i] = false;

                subjects[i] = new NeuralNetworkProgram(sourcenn);
                subjects[i].neuralNetwork = new NeuralNetwork(sourceNetwork);
                subjects[i].neuralNetwork.CopyWeightsAndBiases(sourceNetwork);
            }
        }
示例#2
0
        /// <summary>
        /// Create new NeuralNetworkEvolver to train using a custom performance function.
        /// </summary>
        /// <param name="breed">Breeding flag.</param>
        /// <param name="sourcenn">NeuralNetwork to evolve.</param>
        /// <param name="nThreads">Number of threads to simulate evolution on.</param>
        /// <param name="perfFunc">Performance/InputOutput processing function.</param>
        public NeuralNetworkEvolver(bool breed, NeuralNetwork sourcenn, int nThreads, ProcessOutputInputGetLoss lossFunc)
        {
            numThreads              = nThreads;
            sourceNetwork           = sourcenn;
            inputOutputLossFunction = lossFunc;

            breeding = breed;

            threads       = new Thread[numThreads];
            subjects      = new NeuralNetworkProgram[numThreads];
            readyNextData = new bool[numThreads];

            for (int i = 0; i < nThreads; i++)
            {
                int ci = i;
                threads[i]       = new Thread(() => evolverThread(ci));
                readyNextData[i] = false;

                subjects[i] = new NeuralNetworkProgram(sourcenn);
                subjects[i].neuralNetwork = new NeuralNetwork(sourceNetwork);
                subjects[i].neuralNetwork.CopyWeightsAndBiases(sourceNetwork);
            }
        }