MA2760-无代写
时间:2023-04-10
MA2760: Mathematical Investigations in Python
Coursework I (40% of module)
Rhyd Lewis
LewisR9@cf.ac.uk
1 Summary
The infinite monkey theorem states that, given enough time, a monkey hitting a typewriter at random will eventually
recreate the complete works of William Shakespeare, the Bible, the Vedas, the complete DNA sequence of all humans,
plus anything else we care to name. However, the key phrase here is “given enough time”. It is obvious that the
probability of something non-trivial and readable being produced in sensible time is very, very small indeed.
Interestingly, the idea of monkeys on typewriters are sometimes used by creationists as an argument against evolution.
For example, in his book Think Biblically! Recovering a Christian Worldview, J. F. MacArthur, claims that the genetic
mutations necessary to produce a tapeworm from an amoeba are as unlikely as a monkey typing Hamlet’s soliloquy,
and hence the odds against the evolution of all life are impossible to overcome.
In this coursework, we will investigate these ideas by repeating some experiments described by Richard Dawkins in his
book The Blind Watchmaker (see also https://en.wikipedia.org/wiki/Weasel program). We will simulate a “monkey
hitting a typewriter” and, in our case, will seek to recreate the following short quote by Dylan Thomas:
He who seeks rest finds boredom. He who seeks work finds rest.
The idea in our experiments is to demonstrate that the process that drives evolutionary systems (i.e., random variation
combined with non-random cumulative selection) is different to pure chance.
For your coursework you are required to work in your allocated groups and write code that will perform the tasks
described below. Details of your experiments, together with their results (including tables of results and charts), should
be written-up in a formal report. Any charts used in your report should be generated using the matplotlib.pyplot
libraries together with appropriate Python code. However, there is no need to submit the code used to make these
charts.
Some LATEX and Python code has been placed on learning central/blackboard. Please use these as starting points for
your work. Instructions and comments can be found within these files.
2 Problem Specification
As described, we will use random processes to try and generate the target text: “he who seeks rest finds boredom. he
who seeks work finds rest.” To make things easier we will restrict our alphabet to contain only 28 characters: lower
case a–z, spaces, and full-stops. We will also only consider strings of exactly 62 characters. Despite these restrictions,
the total number of different strings that exist is still a massive 2862 ≈ 5.294× 1089.
1
3 Task 1 (approx. 20%)
As you may have realised, the chances of a monkey producing our quote (or, to put it more more accurately, the
chances that a randomly generated 62-character string will equal our target text) is a minuscule 1/2862. Nevertheless,
we will try the following to get started.
• Write a function called genRandText that returns a randomly generated 62-character string over our 28-character
alphabet.
• Now write a second function called score that receives a 62-character string and returns the number of positions
that contain a character equal to the same position in the target string. For example, the string “he who soaks
rest fends boredom. hi who seeks work finds rost.” has a score of 57 out of 62 (the letters in bold are incorrect).
• Now write some code that repeatedly generates these strings at random and evaluates them. The program should
stop when the target text has been produced or (much more likely) some sort of iteration limit has been reached.
• You may wish to look at the best, worst, average, and distribution of scores that were produced during a run to
assess how close this algorithm is able to get to the target string.
• In addition to text output, you may also wish to use various graphical outputs (charts) to illustrate your findings.
These can also be included in your report, if desired.
4 Task 2 (approx. 40%)
We will now try an approach that is more similar to what happens in nature, albeit with some major simplifications.
This is intended to illustrate how species evolve and improve, despite the fact that individual mutations themselves
occur randomly. The process is described as follows.
1. Produce a string S of length n using genRandText and calculate its score.
2. Make an “offspring” string S′. This should be a copy of S except that x = 1 position/character in S′ has been
randomly selected and changed to another randomly selected character from our alphabet. This can be seen as
S′ inheriting its contents from S, subject to occasional random mutations.
3. Calculate the score of S′. If its score is better (higher) than S, replace S by S′.
4. Return to Step 2.
Implement the above process and carry out experiments similar to the previous section. As before, this process should
continue until the target text has been created, or until an iteration limit has been reached.
5 Task 3 (approx. 40%)
In this section, you are asked to explore other areas. Here are some ideas. You are invited—and encouraged—to also
formulate your own.
1. The value of x used in the previous section is sometimes known as a mutation rate. It has been hypothesized
that, on average, a different mutation rate might allow the target text to be reached in fewer iterations. Investigate
this and explain any findings.
2
2. It has also been suggested that the target text will be established more quickly if it contains fewer characters.
In his original experiments for instance, Richard Dawkins used the Shakespeare quote “methinks it is like a
weasel”. Investigate this.
Note that all of the processes described here are randomized. You will therefore need to perform multiple runs, calcu-
late statistics, and perhaps carry out statistical tests, for your findings to be scientifically valid.
6 Extra Information
• You will have noticed that some of these tasks are open ended. You are encouraged to choose your own directions
for these parts and document your activities.
• Extra marks will be allocated to groups who write neat, elegant, efficient code that is appropriately commented.
• At the start of a run, you may wish to ask the user what options they want to select (the iteration limit, mutation
rates, etc.).
• Marks are also allocated to reports that are written accurately and succinctly, with appropriate typesetting.
(Please use the supplied LATEX code on Learning Central/Blackboard.) You may also wish to use various figures
and tables in your report. In your reports try to focus on the methods themselves as opposed to how they were
implemented—avoid saying things like “we used a while-loop and an if-statement in our Python program”.
Having said that, it is acceptable to include small pieces of your Python code in your report if it helps to explain
something. However, bear in mind that you are also required to submit your code in a separate file.
7 Assessment and Submission
Marks will be allocated subject to the above tasks being carried out and documented appropriately. Note that it is
usually preferable to have a less-advanced program that runs correctly rather than a more advanced program that does
not run or that has bugs in it. The coursework should be submitted in paper form to the school office by midday,
Wednesday 19th April.
• In their submissions, groups should provide (a) their report (b) neat printouts of their final code and (c) a
completed and signed peer assessment form.
• The recommended length of the report is five pages using the supplied LATEX template. Reports should not
exceed eight pages under any circumstances.
• Before the deadline, one member of the group should also email the lecturer a single Python file containing their
code, and a single pdf file containing their report. The title of the email and names of these files should be your
group number: (i.e. Group1, Group1.py and Group1.pdf).
• During a lab session, each group will also be required to sit with the lecturer and give them a short overview of
the code, demonstrating how it is run. There is no need to prepare any materials for this part.
Please note that, according to university rules, unauthorised late submissions must be allocated a mark of zero by
default. Also according to university rules, instances of plagiarism are not be tolerated; indeed, one member of each
group will be required to sign a form indicating that your work has not been plagiarised on submission in the school
office. It is natural that students from different groups will sometimes exchange ideas and help each other out in
completing coursework of this nature; however, please be mindful that flagrant instances of copying will result in both
parties receiving zero (this has happened in some of my modules in the past, so you have been warned!).


essay、essay代写