function [pop] = mutate(pop,mu) % MUTATE - Implements mutation on the genetic population % % Inputs: % % Outputs: % % Written by: % -- % John L. Weatherwax 2006-08-28 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- [N_pop,N_bits] = size(pop); num_of_mutations = ceil( mu * ( N_pop - 1 ) * N_bits ); % -1 => we don't mutate our best chromosome mrow = ceil( rand(1,num_of_mutations)*(N_pop - 1) ) + 1; ncol = ceil( rand(1,num_of_mutations)*N_bits ); pop(mrow,ncol) = abs( pop(mrow,ncol) - 1 );