% gene_to_values(gene)
%   Given a binary array chromosome, returns real values for beta and delta
%
% Inputs:
%   gene  - A 1D binary array, the first half representing beta and
%           the second half representing delta.
% Output:
%   beta  - The value for beta
%   delta - The value for delta
%
function [beta, delta] = gene_to_values(gene) 

% Set the min and max ranges for the exponents (base 10)
beta_min_exponent = -7;
beta_max_exponent = 1;
delta_min_exponent = -4;
delta_max_exponent = 2;

% The length of a gene within the chromosome is half the total length
gene_len = size(gene, 2)/2;

% Use bi2de to convert binary arrays to decimal numbers
beta_decimal = bi2de(gene(1:gene_len));
delta_decimal = bi2de(gene((gene_len+1):end));
    
% Convert the decimal values to real numbers inside the
% ranges established above.
beta_exponent = beta_min_exponent + ...
                  ((beta_max_exponent-beta_min_exponent) * ...
                   beta_decimal / 2^gene_len);
delta_exponent = delta_min_exponent + ...
                  ((delta_max_exponent-delta_min_exponent) * ...
                   delta_decimal / 2^gene_len);
   
% We are using base 10 exponents               
beta = 10^beta_exponent;
delta = 10^delta_exponent;