function [x] = var_decode(x_bin, bounds) % VAR_DECODE - Decodes the binary variables x_bin into a normal float representation % % Inputs: % x_bin = [ number_of_samples x N_var * N_gene binary zero and ones ] input matrix of variables to be decoded % bounds = [ number_of_variables x 2 ] input matrix where the ith row is the valid bounds for the ith variable % % Outputs: % x_bin = [ number_of_samples x N_var * N_gene ] binary encoding of each variable in x % % 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. % %----- % Check inputs: assert( size(bounds,2)==2, 'bounds input must have two columns' ); N_var = size(bounds,1); N_gene = size(x_bin,2)/N_var; N_samples = size(x_bin,1); % Compute the decoded variables: % x_low = repmat( bounds(:,1), [1,N_samples] ).'; x_len = repmat( bounds(:,2) - bounds(:,1), [1,N_samples] ).'; Qm = ( 2.^( -(1:N_gene)) ).'; x_quant = zeros(N_samples,N_var); for ii=1:N_var inds = ( N_gene*(ii-1) + 1 ) : ( N_gene*ii ); vars_bin = x_bin(:,inds); % convert a single of variables at a time x_quant(:,ii) = vars_bin * Qm; % + 2^( -(N_gene+1) ); % I don't think that this term should be added end x = x_quant .* x_len + x_low;