Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE USE MATLAB! Task 1.1:Randomly generate initial population of strings We are going to write a function buildPopulation that will initialize 200 random strings (all

PLEASE USE MATLAB!

image text in transcribed

Task 1.1:Randomly generate initial population of strings We are going to write a function buildPopulation that will initialize 200 random strings (all the same length as the target phrase) containing upper/lowercase letters and spaces You should store these population members in a single cell, which your function should output. In this function you should also define the population size as a variable, an important quantity that we will come back to often in this project. To generate random characters, we simply have to generate random integers which correspond to text characters in the ASCII table (more information http://www.asciitable.com), and use the char() typecast to turn them into characters Following the biology analogy, our population (cell) now contains organisms (strings) with DNA bits (individual characters) that were randomly generated. We are going to try and match that DNA to the target phrase's DNA. Task 1.2: Calculate fitness of each member in the population In this example, we will simply define fitness as how many characters the current member of the population has correct when compared to our target phrase. For example, if our target phrase is 'Hello World', and we are assessing the fitness of the string 'qK IfdRoPLd' we would compare it as follows: Target: Test string: aK lf d ROP L d DNA match: 0 0 0 1 000 1 0 0 1 He ll oW O rld The test string would have a fitness score of 3, due to having 3 DNA matches to the target phrase. A phrase with 100% fitness (ie, the phrase ?ello world') would have a fitness score of 11 in this example. You can see that with a longer target string, the maximum possible fitness goes up. Furthermore, having a fitness of 3 in a phrase like ?ello world, is much less significant to having a fitness of 3 in a shorter phrase like 'Hello'. Therefore, it is going to be more useful for us to look at the string's fitness as a percentage, where 0 has no matches, and 1 is completely matching (also known as normalizing the fitness score). In this case the test string has a fitness of approximately 0.273, or 27.3% Task 1.1:Randomly generate initial population of strings We are going to write a function buildPopulation that will initialize 200 random strings (all the same length as the target phrase) containing upper/lowercase letters and spaces You should store these population members in a single cell, which your function should output. In this function you should also define the population size as a variable, an important quantity that we will come back to often in this project. To generate random characters, we simply have to generate random integers which correspond to text characters in the ASCII table (more information http://www.asciitable.com), and use the char() typecast to turn them into characters Following the biology analogy, our population (cell) now contains organisms (strings) with DNA bits (individual characters) that were randomly generated. We are going to try and match that DNA to the target phrase's DNA. Task 1.2: Calculate fitness of each member in the population In this example, we will simply define fitness as how many characters the current member of the population has correct when compared to our target phrase. For example, if our target phrase is 'Hello World', and we are assessing the fitness of the string 'qK IfdRoPLd' we would compare it as follows: Target: Test string: aK lf d ROP L d DNA match: 0 0 0 1 000 1 0 0 1 He ll oW O rld The test string would have a fitness score of 3, due to having 3 DNA matches to the target phrase. A phrase with 100% fitness (ie, the phrase ?ello world') would have a fitness score of 11 in this example. You can see that with a longer target string, the maximum possible fitness goes up. Furthermore, having a fitness of 3 in a phrase like ?ello world, is much less significant to having a fitness of 3 in a shorter phrase like 'Hello'. Therefore, it is going to be more useful for us to look at the string's fitness as a percentage, where 0 has no matches, and 1 is completely matching (also known as normalizing the fitness score). In this case the test string has a fitness of approximately 0.273, or 27.3%

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago

Question

3. SCC Soft Computer

Answered: 1 week ago

Question

2. KMPG LLP

Answered: 1 week ago

Question

5. Wyeth Pharmaceuticals

Answered: 1 week ago