Ejemplo n.º 1
0
        private static BiasMachine GetBiasMachine()
        {
            BiasMachine machine = new BiasMachine(Input, Output);

            machine.ChangeFunctionsRate = 0.25;

            return(machine);
        }
Ejemplo n.º 2
0
        private static BiasMachine Learn(double RequiredError)
        {
            const int iteration = 10000;
            const int steps     = 100;
            const int count     = 100;
            const int best      = 10;

            BiasMachine[] population = new BiasMachine[count];

            BiasMachine[] successful = new BiasMachine[best];

            RequiredError = Math.Abs(RequiredError);

            for (int j = default; j < count; ++j)
            {
                population[j] = GetBiasMachine();
            }

            for (int i = default; i < iteration; ++i)
            {
                List <KeyValuePair <BiasMachine, double> > scores = new List <KeyValuePair <BiasMachine, double> >(count);

                double[] error = new double[count];

                for (int u = default; u < steps; ++u)
                {
                    double[] input = GetInput();

                    double[] result = GetOutput(input);

                    for (int j = default; j < count; ++j)
                    {
                        double[] solution = population[j].Compute(input);

                        for (int z = default; z < Output; ++z)
                        {
                            error[j] += Math.Abs(solution[z] - result[z]);
                        }
                    }
                }

                for (int j = default; j < count; ++j)
                {
                    error[j] /= (steps * Output);

                    scores.Add(new KeyValuePair <BiasMachine, double>(population[j], error[j]));
                }

                scores.Sort((x, y) => x.Value.CompareTo(y.Value));

                if (i % 20 == default)
                {
                    Console.Clear();

                    Console.WriteLine("Itteration: " + (i + 1) + " error: " + Format(scores[0].Value) + "\n\n");
                }

                if (Math.Abs(scores[default].Value) <= RequiredError)