Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit 3: Programming “Encoding and Decoding”. We can now take a simple message like, Hello and convert it in stages: Hello 73 102 109 109 112 1001001 1100110.

Similar presentations


Presentation on theme: "Unit 3: Programming “Encoding and Decoding”. We can now take a simple message like, Hello and convert it in stages: Hello 73 102 109 109 112 1001001 1100110."— Presentation transcript:

1 Unit 3: Programming “Encoding and Decoding”

2 We can now take a simple message like, Hello and convert it in stages: Hello Hello But is this message really safe from your classmates? C = [ ] Knapsack Sequence But is even this message really safe from your classmates?

3 “Encoding and Decoding” Now let’s let genetic algorithms have a chance at it… = “Encoded Message” Someone provide me with an encoded message using your knapsack encoding…don’t give me your secret code!

4 “Encoding and Decoding” Two encoded messages broken GA’s: 1) “After time adrift among open stars, along tides of light and through shoals of dust, I will return to where I began.”~ Michael Leung 2) “Cody approves of the JEWS encoding system. Stop asking about the name. Happy Hanukkah everyone!”~ Justus Jackson

5 Perfect Solution

6 Imperfect Solutions

7 “Encoding and Decoding” Now that we have managed to both encode and decode a message using a Knapsack sequence, let’s begin work on a GA that can break a code… …even without knowing the knapsack sequence!!!

8 “Encoding and Decoding” What’s the first step in any GA routine? Need a reminder???

9 Genetic Algorithms Genetic algorithms usually consist of the following five steps: 1.Create a starting population randomly 2.Test the fitness of each member and assign selection probability 3.Reproduce 4.Test new population for threshold criteria 5.Wash, rinse and repeat…

10 “Encoding and Decoding” The starting population for our problem should be a set of guesses for what the Knapsack sequence might be, so we know something about the constraints. Any guess must be: Same length as the actual sequence Super increasing Randomly created

11 “Encoding and Decoding” Write a function called superIncreasing that will create M sets of guesses for the knapsack sequence arranged in an MxN array, where N is the length of the sequence. Input:Description: MThe number of guesses to create NLength of each knapsack sequence Output:Description: PAn MxN array of guesses for the Knapsack sequence Super Increasing – every element is greater than the sum of all previous elements Ex: [ ]

12 “Encoding and Decoding” [ P ] = superIncreasing( M,N ) Hint: Pick a random number between 1-5 Add this number to the superincreasing series Repeat – Sum the series – Add to the sum a random number between 1-5 – Add that new number to the series

13 “Encoding and Decoding” Write a function called Crossover that will take in P, an mxn array of guesses for the knapsack sequence, and output N a similar array where every two guesses have been randomly allowed to replicate by crossover at a randomly selected point. Input:Description: Parray of guessed knapsack sequences Output:Description: Narray of crossover-replicated sequences

14 “Encoding and Decoding” Write a function called Mutate that will take in P, an mxn array of guesses for the knapsack sequence, and output N, a similar array where a random element in each row may have been “mutated”; for our purposes mutation is adding +/-1 to an element. Input:Description: Parray of guessed knapsack sequences Output:Description: Narray of crossover-replicated sequences

15 “Encoding and Decoding” Let’s get to work on a fitness function that will help us to home in on a solution for the encoded message. 1)Download the function, knapsackFitness.m, from the BPI website. 2)Read through the comments and begin work on coding the steps described. A set of sample input and output data is included so that you can test your function when completed.

16 “Lockers” At the end of the school year, an obsessive/compulsive worker is asked to clean out N lockers, initially all closed. Each time he cleans, he leaves the door open if it was closed, or closed if it was open. The first time he cleans, he leaves all the doors open. The second time, he closes every second door. The third time he cleans, he closes every third door if it is open, or opens it if was closed. The fourth time…well this continues until he has cleaned the lockers N times. How many lockers are open if N = 4? N=6? N = 1000?

17 “Lockers” How many lockers are open if N = 4? N=6? N = 1000? Open Closed Open

18 “Slope” Write a script that will create an empty figure containing only a 8 x 8 grid (i.e. x ranges from 1 to 8, as does y). Using the ginput function, allow the user to plot two points on the grid by clicking anywhere on the grid. Calculate the slope and the distance between the two points.


Download ppt "Unit 3: Programming “Encoding and Decoding”. We can now take a simple message like, Hello and convert it in stages: Hello 73 102 109 109 112 1001001 1100110."

Similar presentations


Ads by Google