Book 7 · Chapter 7
Emerging technologies
B7·7This chapter is in the ebook.
Read it in full on cswithzak.com. Every question has its mark scheme and every program is ready to run. The free practice for each section is below, with the short code the book prints beside it.
For the whole chapter
- Topic pageEmerging technologies (2029–2031)
B7·7·T - QuizEmerging technologies
B7·7·Q1 - LabAlgorithm Lab — a neural network
B7·7·X1
§7.1 Artificial Intelligence
Short code B7·7·1
- FlashcardsFlashcards §7.1: AI: features, learning and neural networks
B7·7·F1 - FlashcardsFlashcards §7.1: AI: applications, bias, ethics and implications
B7·7·F2
What is artificial intelligence?
Short code B7·7·10
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
The main features of AI
Short code B7·7·11
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Supervised learning
Short code B7·7·12
redness = [12, 25, 38, 47, 55, 63, 71, 88]
# the labels: is each tomato ripe?
label = ["no", "no", "no", "no",
"yes", "yes", "yes", "yes"]
best_rule = 0
best_correct = 0
for rule in range(30, 71, 10):
correct = 0
for i in range(len(redness)):
if redness[i] >= rule:
guess = "yes"
else:
guess = "no"
if guess == label[i]:
correct = correct + 1
print("rule", rule, "->", correct, "of 8 correct")
if correct > best_correct:
best_correct = correct
best_rule = rule
print("Learned: ripe if redness >=", best_rule)
for new in [42, 67]:
print("New tomato", new, "ripe?", new >= best_rule)Output
rule 30 -> 6 of 8 correct rule 40 -> 7 of 8 correct rule 50 -> 8 of 8 correct rule 60 -> 7 of 8 correct rule 70 -> 6 of 8 correct Learned: ripe if redness >= 50 New tomato 42 ripe? False New tomato 67 ripe? True
Unsupervised and reinforcement learning
Short code B7·7·13
import statistics
# unlabelled data: visits to a shop last month by eight customers
visits = [2, 15, 4, 18, 3, 20, 5, 17]
centre1 = visits[0]
centre2 = visits[2]
for rnd in range(1, 4):
group1 = []
group2 = []
for v in visits:
d1 = v - centre1
if d1 < 0:
d1 = -d1
d2 = v - centre2
if d2 < 0:
d2 = -d2
if d1 <= d2:
group1.append(v)
else:
group2.append(v)
centre1 = statistics.mean(group1)
centre2 = statistics.mean(group2)
print("round", rnd, group1, group2)
print("Group centres:", centre1, "and", centre2)Output
round 1 [2, 3] [15, 4, 18, 20, 5, 17] round 2 [2, 4, 3, 5] [15, 18, 20, 17] round 3 [2, 4, 3, 5] [15, 18, 20, 17] Group centres: 3.5 and 17.5
Neural networks
Short code B7·7·14
inputs = [1, 0, 1]
weights = [3, 2, -4]
threshold = 0
total = 0
for i in range(len(inputs)):
total = total + inputs[i] * weights[i]
print("input", inputs[i], "x weight", weights[i], "-> total", total)
if total > threshold:
print("Output: 1 (open the window)")
else:
print("Output: 0 (keep it shut)")Output
input 1 x weight 3 -> total 3 input 0 x weight 2 -> total 3 input 1 x weight -4 -> total -1 Output: 0 (keep it shut)
How a neural network learns
Short code B7·7·15
a = [0, 0, 1, 1]
b = [0, 1, 0, 1]
target = [0, 0, 0, 1]
w1 = 0
w2 = 0
threshold = 1
rnd = 0
print("round mistakes w1 w2 threshold")
while True:
rnd = rnd + 1
mistakes = 0
for i in range(4):
out = 0
if a[i] * w1 + b[i] * w2 >= threshold:
out = 1
error = target[i] - out
if error != 0:
mistakes = mistakes + 1
w1 = w1 + error * a[i]
w2 = w2 + error * b[i]
threshold = threshold - error
print(rnd, mistakes, w1, w2, threshold)
if mistakes == 0:
breakOutput
round mistakes w1 w2 threshold 1 1 1 1 0 2 3 2 1 1 3 3 2 1 2 4 2 2 2 2 5 1 2 1 3 6 0 2 1 3
# 2 inputs -> 2 hidden nodes -> 1 output
def node(values, weights, threshold):
total = 0
for i in range(len(values)):
total = total + values[i] * weights[i]
if total >= threshold:
return 1
else:
return 0
for a in range(2):
for b in range(2):
h1 = node([a, b], [1, 1], 1)
h2 = node([a, b], [1, 1], 2)
out = node([h1, h2], [1, -1], 1)
print(a, b, "hidden:", h1, h2, "output:", out)Output
0 0 hidden: 0 0 output: 0 0 1 hidden: 1 0 output: 1 1 0 hidden: 1 0 output: 1 1 1 hidden: 1 1 output: 0
Applications of AI
Short code B7·7·16
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Using AI in a given context
Short code B7·7·17
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Fairness and bias
Short code B7·7·18
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Ethics and society
Short code B7·7·19
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Jobs, safety and the environment
Short code B7·7·20
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Quantum computers
Short code B7·7·21
for n in [2, 3, 10, 20]:
print(n, "bits or qubits:", 2 ** n, "patterns")Output
2 bits or qubits: 4 patterns 3 bits or qubits: 8 patterns 10 bits or qubits: 1024 patterns 20 bits or qubits: 1048576 patterns
Advantages and disadvantages of quantum computers
Short code B7·7·22
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Past-paper practice
Short code B7·7·90
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Workbook: Emerging technologies
Short code W7·7 · Computer Systems Workbook
The write-in workbook for this chapter has drills, exam-style practice, trace tables, fix-the-mistake and mark-it-yourself pages. Its full mark schemes and an interactive version arrive here with the chapter.


