function [x_norm] = var_encode(x, bounds) % VAR_ENCODE - Encodes the variables "x" in a normalized representation: 0 <= x_norm <= 1 % % Inputs: % x = [ number_of_samples x number_of_variables ] input matrix of variables to be encoded % bounds = [ number_of_variables x 2 ] input matrix where the ith row is the valid bounds for the ith variable % % Outputs: % x_norm = [ number_of_samples x N_var ] 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: [N_samples,N_var] = size(x); assert( size(bounds,1)==N_var, 'bounds input must have N_var rows' ); assert( size(bounds,2)==2, 'bounds input must have two columns' ); % make sure all our initial input variables are within the required variables bounds before we encode them: % x = enforce_bounds(x,bounds); % compute the normalized variable values: % x_low = repmat( bounds(:,1), [1,N_samples] ).'; x_len = repmat( bounds(:,2) - bounds(:,1), [1,N_samples] ).'; x_norm = ( x - x_low ) ./ x_len;