annotate general/numerical/stoch.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents e44f49929e56
children
rev   line source
samer@4 1 function [Y,Z]=stoch(X),
samer@4 2 % stoch- make columns sum to one (like probabilities)
samer@4 3 %
samer@4 4 % stoch:: [[N,M]] -> [[N,M]], [[M]].
samer@4 5 %
samer@4 6 % optionally returns the column sums as well.
samer@4 7 % NOTE: this function assumes that X contains no NaNs and
samer@4 8 % at most one Inf per column. Eg, the function will map
samer@4 9 %
samer@4 10 % [2;3;6;Inf;1;8] -> [0;0;0;1;0;0]
samer@4 11 %
samer@4 12 % See also: the function stochastic works on ROWS not columns.
samer@4 13
samer@4 14
samer@4 15 Z=sum(X,1);
samer@4 16 Y=X./repmat(Z,size(X,1),1);
samer@4 17
samer@4 18 % any nans are assumed to be inf/inf so are replaced with 1
samer@4 19 Y(isnan(Y))=1;
samer@4 20