Created
October 13, 2014 14:51
-
-
Save tonyfast/172f73c2612f841e7055 to your computer and use it in GitHub Desktop.
Create noneigen discretization of the equispaced local state spaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function [MF, bins ] = noneigen( X, xx ); | |
| %% | |
| % X :: values to be binned | |
| % xx :: cellarray for the local state space | |
| dims = cumprod(cellfun(@(x)numel(x),xx)); | |
| %% | |
| MF = zeros( size(X,1), ... | |
| dims(end) ); | |
| for ii = 1 : numel( dims ); | |
| dx = mean( diff(xx{ii})) | |
| D = 1 - abs(bsxfun(@minus, X(:,ii), xx{ii})./dx); | |
| D(:) = ( D>=0 & D<=1 ) .* D; | |
| if ii == 1 | |
| bins = xx{ii}'; | |
| MF( :, 1 : dims(ii)) = D; | |
| else | |
| bins = [repmat(bins,numel(xx{ii}),1), reshape( ... | |
| repmat(xx{ii}(:)' , size(bins, 1) ,1), dims(ii), 1) ]; | |
| MF(:, 1 : dims(ii) ) = reshape( ... | |
| bsxfun( @times, MF(:, 1 : dims(ii-1) ) , permute( D, [ 1 3 2] ) ), ... | |
| size(X,1),[]) | |
| end | |
| end | |
| %% Check | |
| % V = zeros( size(X,1), numel(xx)); | |
| % for jj = 1 : size(bins,2) | |
| % V(:,jj) = sum( bsxfun( @times, MF, bins(:,jj)'), 2 ); | |
| % end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % Sample points | |
| X = rand(10,3); | |
| % Three axes in the local state space | |
| xx{1} = linspace(0,1,11); | |
| xx{2} = linspace(0,1,5); | |
| xx{3} = linspace(0,1,4); | |
| [MF, bins ] = noneigen( X, xx ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment