Genetic Algorithms

A genetic algorithm (GA) is a search method inspired by natural evolution. A candidate solution is a chromosome, a string of bits. A fitness function scores each chromosome. Steps: create an initial population; select fitter chromosomes (roulette wheel selection, probability = fitness / total fitness); apply crossover (swap tails of two parents at a cut point) and mutation (flip a bit with a small probability); repeat for many generations. In classification a rule such as IF A1 AND NOT A2 THEN C2 is encoded as a bit string and the fitness is its accuracy.

Rough Set Approach

Rough set theory handles vague or inconsistent data. Objects that cannot be told apart by their attributes form an equivalence class. A target set X is approximated by the lower approximation (classes entirely inside X, certainly in X) and the upper approximation (classes that touch X, possibly in X). The boundary region is upper minus lower. It is used to find reducts (minimal attribute sets that keep the same classification) and to derive rules.

Fuzzy Set Approach

In a fuzzy set an element belongs with a degree of membership between 0 and 1 instead of yes or no. A value such as temperature is described with linguistic terms (cold, warm, hot) by membership functions. The operations are AND = minimum, OR = maximum and NOT = 1 - membership. Fuzzy rules such as IF income is high THEN credit is good are used for classification and give smooth decisions near class boundaries.

Definition: Fuzzy set. A set in which each element has a degree of membership between 0 and 1, allowing partial belonging.

Table 3.6: Soft computing approaches

Approach Key idea Use
Genetic algorithm Evolution of solutions Optimisation, rule search
Rough set Lower and upper approximation Vague data, reducts
Fuzzy set Degree of membership Linguistic rules

Example 3.6: One generation of a genetic algorithm

Problem: Maximise f(x) = x² for x from 0 to 31 with 5-bit chromosomes. The population is 01101 (13), 11000 (24), 01000 (8) and 10011 (19). Find the fitness values and selection probabilities, then cross 11000 with 10011 after the second bit.

Solution:

  1. Fitness = 169, 576, 64 and 361, with total 1170.
  2. Selection probabilities: 14.4 percent, 49.2 percent, 5.5 percent and 30.9 percent.
  3. Crossover of 11|000 and 10|011 gives the children 11011 and 10000.
  4. 11011 = 27 with fitness 729; 10000 = 16 with fitness 256.

Result: The best fitness improves from 576 to 729 in one generation.

pop = ["01101", "11000", "01000", "10011"]
fit = [int(c, 2) ** 2 for c in pop]
print("Fitness:", fit, "Total:", sum(fit))
print("Prob %:", [round(f / sum(fit) * 100, 1) for f in fit])
a, b, cut = "11000", "10011", 2
c1, c2 = a[:cut] + b[cut:], b[:cut] + a[cut:]
print("Children:", c1, c2, [int(c, 2) ** 2 for c in (c1, c2)])
classes = [{1, 2}, {3, 4, 5}, {6}, {7, 8}]
X = {1, 2, 3, 6, 7}
lower = set().union(*[c for c in classes if c <= X])
upper = set().union(*[c for c in classes if c & X])
print("Lower:", lower, "Upper:", upper)
print("Accuracy:", len(lower) / len(upper))
hot = lambda t: min(1, max(0, (t - 20) / 20))
print("Hot(30):", hot(30), "Hot(35):", hot(35))

Output

Fitness: [169, 576, 64, 361] Total: 1170
Prob %: [14.4, 49.2, 5.5, 30.9]
Children: 11011 10000 [729, 256]
Lower: {1, 2, 6} Upper: {1, 2, 3, 4, 5, 6, 7, 8}
Accuracy: 0.375
Hot(30): 0.5 Hot(35): 0.75

Common mistakes

  • Setting the mutation rate too high, which turns the search into random guessing.
  • Choosing a fitness function that does not reflect the real goal.
  • Confusing fuzzy membership with probability.
  • Forgetting that a rough set has a boundary region of uncertain objects.

Key takeaways

  • GA: population, fitness, selection, crossover, mutation.
  • Rough set: lower approximation certain, upper approximation possible.
  • Fuzzy set: membership between 0 and 1; AND is min, OR is max.
  • These are soft computing methods for vague or complex problems.

Practice questions

  1. What do crossover and mutation do in a GA?
  2. What is the boundary region of a rough set?
  3. What does a fuzzy membership value of 0.5 mean?

Answers to the practice questions

  1. Crossover swaps parts of two parents; mutation flips bits at random.
  2. Upper approximation minus lower approximation.
  3. The element belongs to the set to a degree of half.

Sources

  • Official BCA syllabus Data Warehousing and Mining, course code 25BCA406DS03, Unit III