HW6 - 1 a 1xxxx Bits 1 to the crossover point come from...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1. a) 1xxxx: Bits 1 to the crossover point come from parent 1. Therefore, we only care about parent 1's selection in producing a child with 1xxxx. We also want to select parents that have 1 in the most significant bit (the leftmost bit), which would include members 1 and 2. Therefore we want P(select member 1 or member 2) = P(select member 1) + P(select member 2) = . 0xxxx: The same logic applies to produce a child of 0xxxx. We only care about parent 1's selection and we only want parents with 0's in the MSB. We get = . b) We assume that with no crossover, the children will be direct copies of a single parent. This means if we want a child of the form 1xxxx, we want to select a parent that already has a 1 in the MSB and perform no mutation or we want to select a parent that has a 0 in the MSB and perform mutation on it. We therefore want P(A or B) where A is the event where we select a parent with 1 in the MSB and we perform no mutation on it and B is the event where we select a parent with 0 in the MSB and we perform mutation on it. P(A or B) = P(A) + P(B) = P((select parent 1 or 2) && (no mutation)) + P((select parent 3 or 4) && (mutation)) = P(select parent 1 or 2) * P(no mutation) + P(select parent 3 or 4) * P(mutation) = . The same logic applies for obtaining a child of 0xxxx P(A or B) = P(A) + P(B) = P((select parent 1 or 2) && (mutation)) + P((select parent 3 or 4) && * (no mutation)) = P(select parent 1 or 2) * P(mutation) + P(select parent 3 or 4) * P(no mutation) = . 2a. 0 5 10 0 2 4 6 8 10 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 Surface Plot Countour Plot 0 2 4 6 8 10 0 2 4 6 8 10 function output = bump(x) n= length(x);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
%feasibility check feasible= true; for i= 1:n if (x(i) <0 || x(i) > 10) feasible= false; end end if (prod(x) < .75) feasible= false; end %function computation if (feasible == false) output= 0; else a= 0; c= 0; for j= 1:n a= a + (cos(x(j))^4); end b= prod(cos(x).^2); for k= 1:n c= c + k*(x(k)^2); end output= abs((a-(2*b))/sqrt(c)); end 2b. function [solution sbest] = realGA(Xinitial,maxGen,pCrossover,pMutation,V) popsize= length(Xinitial(:,1)); indsize= length(Xinitial(1,:)); currentPop= Xinitial; sbest= zeros(1,indsize); fitbest= -inf; %Evaluate bump of all individuals fitness= zeros(1,popsize); for i= 1:popsize fitness(1,i)= bump(currentPop(i,:)); end %Begin GA numPar= popsize/2; %pairs of parents pairParents= zeros(numPar,2*indsize); offspring= zeros(popsize,indsize); fitOff= zeros(1,popsize); solution= zeros(maxGen,2); for i= 1:maxGen %Create Offspring via Crossover for j= 1:popsize pairParents(j,:)= selection_T(currentPop); offspring(2*j-1:2*j,:)= crossover(pairParents(j,:),pCrossover); end %Mutation
Background image of page 2
for k= 1:popsize offspring(k,:)= mutation(offspring(k,:),pMutation,V); end %bump of offspring for l= 1:popsize fitOff(1,l)= bump(offspring(l,:)); end %Find best parent to carry to next generation and worst child to leave %behind max= currentPop(1,:); maxF= fitness(1); for b= 2:popsize if (fitness(b) > maxF) max= currentPop(b,:); maxF= fitness(b);
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/29/2011 for the course ORIE 5140 taught by Professor Shoemaker during the Fall '11 term at Cornell.

Page1 / 16

HW6 - 1 a 1xxxx Bits 1 to the crossover point come from...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online