Question: 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!

PLEASE USE MATLAB! Task 1.1:Randomly generate initial population of strings We are

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!