By Developers, For Developers

Historical errata for Genetic Algorithms and Machine Learning for Programmers

PDF PgPaper PgTypeDescriptionFixed onComments
ManyTYPO

PAGE48,“The GA need pairs” —- Shouldn’t this be “The GA needs pairs”?

PAGE49,“lets cerate a GA” —- Shouldn’t this be “let’s create a GA”?

PAGE66,“Staying with particles tending to follow each other, but keep track of good directions give a different approach.” —- I could not pin down the subject of the sentence.

PAGE74,“In contrast, [1, 0, 1, 1] and [0, 0, 1, 1] agree on one of the fours bits, so have a distance of 3.” —- Shouldn’t this be “three of the four bits”?

PAGE78,“wieght” —- typo.

2018-08-21
BookSUGGEST

CONTEXT: I picked up this book to assess if it would serve as a good hands-on introduction to GA and ML for senior undergrads and beginning grad students who are good at programming.

SUGGESTION: After reading the book, in its current state, here’s why and how I think it can be improved for the intended audience.

1) I had a hard time following the examples as they switched between languages. I am wondering if non-polyglots interested in ML would also face this issue as they have to switch between languages (while switching between different styles of algorithms). I think the content would be easier to follow if all examples were in the same language (say, Python).

2) The lack of pseudo code of each algorithm hinders setting up the skeleton of the algorithms before grokking the details that flesh out the skeleton; more so, when there are multiple options to flesh out the details, e.g., different kind of crossovers in GA. I think providing the pseudo code for each algorithm and then highlighting which step in the pseudo code is realized by a (set of) functions will make the content more comprehensible.

3) Since the book is geared towards programmers, I think describing few software engineering or software systems related problems that could be tackled with the described algorithms will help programmers appreciate the benefits for the algorithms. It would be cool if these problems are used as examples to illustrate the examples. For example, mutation testing could be used to illustrate the benefits of GP (GA).

I hope this feedback helps improve the book :)

2018-09-30These are good suggestions. \n \n1) I have deliberately used a mix of languages to make the point the choice doesn't really matter. \nI hear you, but don't want to change this. \n \n2) I do have a high-level view of each algorithm in each chapter, without the gory details of, say, different crossover methods. I have tweaked the words to call out the main algorithm in chapters where this wasn't clear. \n \n3) I do have mutation testing with Cosmic Ray in the first GA chapter, \n \nThanks for the suggestions. \n \n \n \n
viTYPO

In Acknowledgments, Kevlin Henny => should be Henney

2018-08-21
26TYPO

When giving an example of the python code to load the data from the previous chapters, I believe the read command should look more like:

L = pickle.load(f)

instead of :

L = pickle.load(L, f)

You may wish to add an L = [] above the pseudo sample to make a a bit more digestible for someone starting out.

2018-09-30Oops. Good spot. \nThe actual code with the book uses L =[], then L = pickle.load(f) as you suggests. \nFixed the code in the chapter to match. \n
27SUGGEST

Just wondering if err’ing on the side of more explicit variable names might help the reader comprehend the components that make up your functions for calculating things. For example, might it not be better if the entropy function was closer to this?

def entropy(data):
frequency_of_out_state = collections.Counter([entry[–1] for entry in data])
def item_entropy(count):
ratio = float(count) / len(data)
return –1 * ratio * math.log(ratio, 2)
return sum(item_entropy(count) for count in frequency_of_out_state.values())

2018-09-30I've used ``item instead of i, and called the inner function item_entropy. \nHope that helps.
21TYPO

I’ve been trying to run escape.py in Visual Studio Code and as usual had a few teething troubles setting up the environment. I found what I guess is an error (this is my first time playing with python) which is in the routine draw_squares
print number rather than print(number)

I’ve also had problems with getting the windows version of python 3.7.1 to properly understand method references here and there. I’ve also added breaks into the draw_squares and draw_triangles routines so they terminate when leaving the paper bad. Anyhow, I’ve copied my own version of the code below. I must admit I’ve made all the lines drawn by turtles as I like turtles!

Best wishes, Mark Lawrence

import argparse
import inspect
import random
import pickle
import turtle

def draw_bag():
bag = turtle.Turtle()
bag.pen(pencolor=‘brown’, pensize=5)
bag.penup()
bag.goto(–35, 35)
bag.pendown()
bag.right(90)
bag.forward(70)
bag.left(90)
bag.forward(70)
bag.left(90)
bag.forward(70)
bag.hideturtle()

def draw_line():
angle = 0
step = 5
t = turtle.Turtle()
while not escaped(t.position()):
t.left(angle)
t.forward(step)

def draw_square(t, size):
L = []
for i in range(4):
t.forward(size)
t.left(90)
store_position_data(L, t)
return L

def draw_squares(number):
print(number)
t = turtle.Turtle()
t.shape(‘turtle’)
t.pen(pencolor=‘red’, pensize=2)
L = []
for i in range(1, number + 1):
t.penup()
t.goto(-i, -i)
t.pendown()
L.extend(draw_square(t, i * 2))
if escaped(t.position()):
break
return L

def draw_triangles(number):
t = turtle.Turtle()
t.shape(‘turtle’)
t.pen(pencolor=‘blue’, pensize=2)
for i in range(1, number):
t.forward(i*10)
t.right(120)
if escaped(t.position()):
break

def escaped(position):
x = int(position[0])
y = int(position[1])
return x < –35 or x > 35 or y < –35 or y > 35

def store_position_data(L, t):
position = t.position()
L.append([position[0], position[1], escaped(position)])

def draw_spirals_until_escaped():
t = turtle.Turtle()
t.shape(‘turtle’)
t.pen(pencolor=‘green’, pensize=2)
t.penup()
t.left(random.randint(0, 360))
t.pendown()

i = 0
turn = 360/random.randint(1, 10)
L = []
store_position_data(L, t)
while not escaped(t.position()):
i += 1
t.forward(i*5)
t.right(turn)
store_position_data(L, t)

return L

def draw_squares_until_escaped(n):
t = turtle.Turtle()
L = draw_squares(n)
with open(“data_square”, “wb”) as f:
pickle.dump(L, f)

def draw_random_spirangles():
L = []
for i in range (10):
L.extend(draw_spirals_until_escaped())

with open(“data_rand”, “wb”) as f:
pickle.dump(L, f)

if name == ‘main’:
fns = {“line”: draw_line,
“squares”: draw_squares_until_escaped,
“triangles”: draw_triangles,
“spirangles” : draw_random_spirangles}

parser = argparse.ArgumentParser()
parser.add_argument(“-f”, “—function”,
choices = fns,
help=“One of ” + ‘, ’.join(fns.keys()))
parser.add_argument(“-n”, “—number”,
default = 50,
\t\t type=int, help=“How many?”)
args = parser.parse_args()

try:
f = fns[args.function]
turtle.setworldcoordinates(–70., –70., 70., 70.)
draw_bag()
if len(inspect.getargspec(f).args)==1:
f(args.number)
else:
f()
turtle.mainloop()
except KeyError:
parser.print_help()

2018-12-01I left the print behind when checking 2.7, so have removed it now. \nThanks for the if escaped suggestions - the point is you can try either. You guess a number, or let the code run until it stops. I think either way works. I have left the code as it is though. \nGlad you like the turtles. \n
41TYPO

“let’s cerate a GA since right now”

2018-12-01Fixed in copy edit process.
68TYPO

They can even move randomly but do not improvement over time if that is all
they do.

Should be:
They can even move randomly but do not show improvement over time if that is all
they do.

2018-12-01
30ERROR

This
finds (–35, 35, –35, 35), give or take some rounding. Should it be (–35, –35) (35, 35) ?

30ERROR

if x < 35.0 or x > 35.0 or y < 35.0 or y > 35.0 then True else False
should it be
if x < –35.0 or x > 35.0 or y < –35.0 or y > 35.0 then True (out of paper bag) else False ?

48ERROR

I can’t find the definition of “random_tries()” in this book.

Categories: