110 likes | 233 Views
Tutorial 2. Temi avanzati di Intelligenza Artificiale - Lecture 6 Prof. Vincenzo Cutello Department of Mathematics and Computer Science University of Catania. Binary Representation of Real Values. When designing a representation, try to ensure that:
E N D
Tutorial 2 Temi avanzati di Intelligenza Artificiale - Lecture 6 Prof. Vincenzo Cutello Department of Mathematics and Computer Science University of Catania
Binary Representation of Real Values • When designing a representation, try to ensure that: • 1. Your complete search space is covered • 2. Nothing outside your search space is covered • 3. All areas of your search space are covered with equal density (no bias) (In order of importance) Tutorial 2 - Lecture 6
Simple code to transform from binary to Real (-10.0..10.0) wordLength = genotype.size() / 2; xMax = (1 << wordLength) - 1; yMax = (1 << wordLength) - 1; for (int i=0; i< wordLength; i++) { xRaw = (xRaw <<1) + (genotype.getBinary(i) ? 1 : 0); } for (int i= wordLength; i< genotype.size(); i++) { yRaw = (yRaw <<1) + (genotype.getBinary(i) ? 1 : 0); } x = (-10.0 + 20.0 * ((double) xRaw) / xMax); y = (-10.0 + 20.0 * ((double) yRaw) / yMax); Tutorial 2 - Lecture 6
Problems with Binary Encoding1. Hamming Cliffs • Some far points are easier to reach than some close points • Hamming Distance is Important • Improvement: Hamming Code • Neighbours always have hamming distance one • But: Still not preference for local changes Tutorial 2 - Lecture 6
wordLength = genotype.size() / 2; xMax = (1 << wordLength) - 1; yMax = (1 << wordLength) - 1; invert = false; for (int i=0; i< wordLength; i++) { invert = invert ^ genotype.getBinary (i); xRaw = (xRaw << 1) + (invert ? 1 : 0); } invert = false; for (int i= wordLength; i< genotype.size(); i++) { invert = invert ^ genotype.getBinary (i); yRaw = (yRaw << 1) + (invert ? 1 : 0); } x = (-10.0 + 20.0 * ((double) xRaw) / xMax); y = (-10.0 + 20.0 * ((double) yRaw) / yMax); Tutorial 2 - Lecture 6
Problems with Binary Encoding2. What Bit-length ? • Too short... • .. or too long Tutorial 2 - Lecture 6
Problems with Binary Encoding • Bit-Mutation Probability • Single Mutation... • ... or many-bit mutation Tutorial 2 - Lecture 6
Real-valued Representation • Gaussian or Cauchy Mutation • Different distributions • Very much depens on scaling factor Tutorial 2 - Lecture 6
Implementing Gaussian and Cauchy Mutation • Gaussian distributed random number • In Java: mean + deviation * rng.nextGaussian()), or code below. • In C, C++ use GSL, or code below. • Cauchy distributed random number • In Java: see code below. • In C, C++ use GSL, or code below. • Other distributions • See references • References • Gnu Scientific Library (GSL), http://www.gnu.org/software/gsl/gsl.html • Non-Uniform Random Variate Generation L. Devroye, Springer Verlag, 1986 • Computer Generation of Statistical Distributions Richard Saucier, http://ftp.arl.mil/random/ Tutorial 2 - Lecture 6
Implementing Gaussian and Cauchy MutationCode Examples • double Gaussian (double stdev, double median) { assert( stdev > 0. ); double u,v,x; do { u = 2.0 * rng.nextDouble() - 1.0; v = 2.0 * rng.nextDouble() - 1.0; x = u * u + v * v; } while ( x >= 1.0 ); return median + stdev * u * sqrt( -2. * log( x ) / x ); } • double Cauchy (double formFactor, double median) { assert( formFactor > 0. ); double u, v; do { u = 2.0 * rng.nextDouble() - 1.0; v = 2.0 * rng.nextDouble() - 1.0; } while (u*u+v*v>1.0 || (u==0.0&&v==0.0)); if (u!=0) return (median + formFactor * (v/u)); else return(median); } Tutorial 2 - Lecture 6
Exercise Sheet • Goal: • Goal of this exercise is to get experience with real-valued based representations and self-adpatation in EC. • Task • Write an EA (possibly reusing bits from the previous tutorial), that finds the optimum in one of the test functions shown in last lecture. Use a real-valued representation, with gaussian or cauchy mutation, and self-adaptive mutation parameter. For test functions, use the generalized sphere function of order 4: • , and f8 from last lecture notes. • Hints • Each individual in the population will need two genotypes: one for the actual value, and one for the strategy parameter. You will need to mutate both, using the contents of the second genotype to control the mutation of the first. • Read Evolutionary Programming made Faster • Question • What happens if you do not use a minimum value for the strategy parameter ? • For most global optimisation problems, the ranges of variables are usually given (e.g., -10.0 < xi< 10.0). What do you do if a random mutation takes an offspring outside the range ? Tutorial 2 - Lecture 6