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

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

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);

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

View Full Document
%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
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); end end min= 1; for c= 1:popsize if (fitOff(c) < fitOff(min)) min= c; end end %Replace worst offspring with best parent offspring(c,:)= max; %Store this generation's stats (parents) solution(i,1)= i; %Store best S if (i==1) solution(i,2)= maxF; fitbest= maxF; sbest= max; else if (maxF > fitbest) solution(i,2)= maxF; fitbest= maxF; sbest= max; else solution(i,2)= solution(i-1,2); end

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern