Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using GA’s X 3 – y 2 + Z = 25. 1. Create a random population Function name – population Inputs: – N, size of the population – R, range of values for each.

Similar presentations


Presentation on theme: "Using GA’s X 3 – y 2 + Z = 25. 1. Create a random population Function name – population Inputs: – N, size of the population – R, range of values for each."— Presentation transcript:

1 Using GA’s X 3 – y 2 + Z = 25

2 1. Create a random population Function name – population Inputs: – N, size of the population – R, range of values for each gene (from 1 to R) Outputs: – Pop, an Nx3 matrix of genes where each row represents the X, Y, and Z gene for a member of the population Syntax: >> [Pop] = population(N, R) Example: [Pop] = population(6, 3) Pop = 3 3 3 2 3 3 3 2 3 1 1 2 2 3 2 3 3 1

3 2. Calculate the population’s fitness Function name – fitness Inputs: – N, size of the population – Pop, Nx3 matrix of genes Outputs: – F, an Nx1 matrix listing the fitness of each set of genes in Pop Syntax: >> [F] = fitness(Pop,N) Example: [F] = fitness(Pop,N) F = 4 23 1 23 24 6 Note: uses Pop, N from previous slide

4 3. Choose parents based on fitness Function name – ChooseParents Inputs: – Pop, Nx3 matrix of genes – F, Nx1 vector of fitnesses Outputs: – Parents, Mx3 matrix of genes, where M = 2*N/3; Parents should be the top rated 2/3 of the gene pool pulled from Pop Syntax: >> [parents] = chooseParents(Pop,F,N) Example: [parents] = chooseParents(Pop,F,N) parents = 3 2 3 3 3 3 3 3 1 2 3 3 Note: uses Pop, F from previous slide

5 4. Pass on genes to next generation Function name – NextGen Inputs: – Parents, Nx3 matrix of genes with the top 2/3 fitness values – F, Nx1 vector of fitnesses Outputs: – Parents, Mx3 matrix of genes, where M = 2*N/3; Parents should be the top rated 2/3 of the gene pool pulled from Pop Syntax: >> [kids] = NextGen (Parents) Example: [kids] = NextGen(Parents) kids = 3 2 3 3 3 3 3 3 1 2 3 3 Note: uses Pop, F from previous slide

6 Parents XYZ 323 333 4. Pass on genes to next generation Parents XYZ 323 333 331 233 Rock, Paper Scissors For X, Y genes This was so we could pass on genes randomly From either P1 or P2 We could just use a random number and IF Statements… IF a random number is drawn less than 0.5, choose P1; else choose P2. 1 To pass on the Z gene, we need to know which parent lost the first round. 2 IF P1 wins, loser equals the row number for P2; else loser equals P1’s row number. IF a random number is drawn less than 0.3, pass on an averaged Z; else pass on loser’s Z. >> rand ans = 0.231 P1 is the winner! Kids XYZ 000 000 XYZ 320 P2 is the loser… >> rand ans = 0.531 Pass on Z from P2 If the random number had been less than 0.3, pass on (Z1 + Z2)/2


Download ppt "Using GA’s X 3 – y 2 + Z = 25. 1. Create a random population Function name – population Inputs: – N, size of the population – R, range of values for each."

Similar presentations


Ads by Google