Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeneticSharp.Domain.Selections.SelectionException"/> class.
 /// </summary>
 /// <param name="selection">The Selection where ocurred the error.</param>
 /// <param name="message">The error message.</param>
 /// <param name="innerException">The inner exception.</param>
 public SelectionException(ISelection selection, string message, Exception innerException)
     : base("{0}: {1}".With(selection != null ? selection.GetType().Name : String.Empty, message), innerException)
 {
     Selection = selection;
 }
Ejemplo n.º 2
0
        public int Prediction(Customer customer)
        {
            double prediction = 0.0;
            double cutoffRate = 0.85;

            for (int i = 0; i < customer.attributes.Count; i++)
            {
                prediction += customer.attributes[i] * topSeed.attributes[i];
            }

            Console.WriteLine("Genetic Algorithms");
            Console.WriteLine("population size: " + size);
            Console.WriteLine("generations: " + k);
            Console.WriteLine("crossover rate: " + crossoverRate);
            Console.WriteLine("mutation rate: " + mutationRate);
            Console.WriteLine("selection method: " + selection.GetType().Name);
            Console.WriteLine("crossover method: " + crossover.GetType().Name);
            Console.WriteLine("size of training data: " + trainingData.Count);
            Console.WriteLine();
            Console.WriteLine("the best fitness value (" + topSeed.fitness + ") belongs to the following seed:");
            Console.Write("[");
            for (int i = 0; i < topSeed.attributes.Count; i++)
            {
                if (i < topSeed.attributes.Count - 1)
                {
                    Console.Write(Math.Round(topSeed.attributes[i], 3) + ", ");
                }
                else
                {
                    Console.Write(Math.Round(topSeed.attributes[i], 3) + "]");
                }
            }
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("The customer that was input has the following attributes:");
            Console.Write("[");
            for (int i = 0; i < customer.attributes.Count; i++)
            {
                if (i < customer.attributes.Count - 1)
                {
                    Console.Write(customer.attributes[i] + ", ");
                }
                else
                {
                    Console.Write(customer.attributes[i] + "]");
                }
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("After multiplying the customer with the top seed we receive the following prediction: " + prediction);

            if (prediction > cutoffRate)
            {
                Console.WriteLine("The prediction is greater than the cutoffrate (" + cutoffRate + ")");
                Console.WriteLine("We can therefore assume that this customer is pregnant");
                return(1);
            }
            else
            {
                Console.WriteLine("The prediction is lower than the cutoffrate (" + cutoffRate + ")");
                Console.WriteLine("We can therefore assume that this customer is not pregnant");
                return(0);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GeneticSharp.Domain.Selections.SelectionException"/> class.
 /// </summary>
 /// <param name="selection">The Selection where ocurred the error.</param>
 /// <param name="message">The error message.</param>
 /// <param name="innerException">The inner exception.</param>
 public SelectionException(ISelection selection, string message, Exception innerException)
     : base("{0}: {1}".With(selection != null ? selection.GetType().Name : String.Empty, message), innerException)
 {
     Selection = selection;
 }