Esempio n. 1
0
        public static double Error(this Network network, TrainingSet[] trainingSets, double[][][] weights)
        {
            double error = 0;

            for (var i = 0; i < trainingSets.Length; i++)
            {
                error += network.Error(trainingSets[i], weights);
            }
            return(error);
        }
Esempio n. 2
0
        public static double[][][] OptimizeSingle(Network network, TrainingSet[] trainingSets, double[][][] weights, int layerIndex, int neuronIndex, int inputIndex, double delta = 10, int recursions = 10)
        {
            //Console.WriteLine("Optimizing: [" + layerIndex + ", " + neuronIndex + ", " + inputIndex + "]...");

            var bestError = network.Error(trainingSets, weights);

            for (var r = 0; r < recursions; r++)
            {
                //Console.WriteLine("START: " + delta + " " + weights[layerIndex][neuronIndex][inputIndex]);
                if (bestError == 0)
                {
                    break;
                }

                weights[layerIndex][neuronIndex][inputIndex] = weights[layerIndex][neuronIndex][inputIndex] + delta;
                var positiveDeltaError = network.Error(trainingSets, weights);
                weights[layerIndex][neuronIndex][inputIndex] = weights[layerIndex][neuronIndex][inputIndex] - (2.0 * delta);
                var negativeDeltaError = network.Error(trainingSets, weights);

                if (Math.Min(negativeDeltaError, positiveDeltaError) < bestError)
                {
                    bestError = Math.Min(negativeDeltaError, positiveDeltaError);
                    if (negativeDeltaError < positiveDeltaError)
                    {
                    }
                    else
                    {
                        weights[layerIndex][neuronIndex][inputIndex] = weights[layerIndex][neuronIndex][inputIndex] + (2.0 * delta);
                    }
                }
                else
                {
                    weights[layerIndex][neuronIndex][inputIndex] = weights[layerIndex][neuronIndex][inputIndex] + delta;
                    delta = delta * 0.5;
                }
                //Console.WriteLine("END: " + delta + " " + weights[layerIndex][neuronIndex][inputIndex]);
            }
            Console.WriteLine("Current best error: " + bestError);
            return(weights);
        }
Esempio n. 3
0
        public static double[][][] OptimizeSingle(Network network, TrainingSet[] trainingSets, double[][][] weights, int layerIndex, int neuronIndex, int inputIndex, double delta = 10, int recursions = 10)
        {
            //Console.WriteLine("Optimizing: [" + layerIndex + ", " + neuronIndex + ", " + inputIndex + "]...");

            var bestError = network.Error(trainingSets, weights);

            for (var r = 0; r < recursions; r++)
            {
                //Console.WriteLine("START: " + delta + " " + weights[layerIndex][neuronIndex][inputIndex]);
                if (bestError == 0) break;

                weights[layerIndex][neuronIndex][inputIndex] = weights[layerIndex][neuronIndex][inputIndex] + delta;
                var positiveDeltaError = network.Error(trainingSets, weights);
                weights[layerIndex][neuronIndex][inputIndex] = weights[layerIndex][neuronIndex][inputIndex] - (2.0 * delta);
                var negativeDeltaError = network.Error(trainingSets, weights);

                if (Math.Min(negativeDeltaError, positiveDeltaError) < bestError)
                {
                    bestError = Math.Min(negativeDeltaError, positiveDeltaError);
                    if (negativeDeltaError < positiveDeltaError)
                    {
                    }
                    else
                    {
                        weights[layerIndex][neuronIndex][inputIndex] = weights[layerIndex][neuronIndex][inputIndex] + (2.0 * delta);
                    }
                }
                else
                {
                    weights[layerIndex][neuronIndex][inputIndex] = weights[layerIndex][neuronIndex][inputIndex] + delta;
                    delta = delta * 0.5;
                }
                //Console.WriteLine("END: " + delta + " " + weights[layerIndex][neuronIndex][inputIndex]);
            }
            Console.WriteLine("Current best error: " + bestError);
            return weights;
        }