% % 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. % %----- clear; close all; clc; randn('seed',0); N_var = 2; N_samples = 13; bounds = [ -10, +10 ; -5, +5 ]; % do a single example to check the code: % x = 10*randn( N_samples, N_var ); x = enforce_bounds( x, bounds ); x % print x N_gene = 8; % larger values make the binary approximation more accurate x_bin = var_encode(x, bounds, N_gene); %x_bin % print x_bin x_encode_decode = var_decode(x_bin, bounds); x_encode_decode % print x_encode_decode. The larger the value of N_gene the closer this matrix equals the original x norm( x - x_encode_decode ) mean_error = []; num_of_genes = 10:25; for ng = num_of_genes, N_gene = ng; samples = []; for ii=1:100 x = 10*randn( N_samples, N_var ); x = enforce_bounds( x, bounds ); x_bin = var_encode(x, bounds, N_gene); % transform x_encode_decode = var_decode(x_bin, bounds); % transform back samples = [ samples, norm( x - x_encode_decode ) ]; end mean_error = [ mean_error, mean( samples ) ]; end figure; plot( num_of_genes, mean_error, '-o' ); xlabel('number of genes to use in binary representation'); ylabel('average error over 100 discretizations'); %saveas( gcf, '../../WriteUp/Graphics/Chapter2/verification_of_binary_representation.eps', 'epsc' );