source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/lightspeed/sample_vector.m @ 86

Last change on this file since 86 was 37, checked in by (none), 15 years ago

Added original make3d

  • Property svn:executable set to *
File size: 667 bytes
Line 
1function x = sample_vector(p,col)
2%SAMPLE_VECTOR    Sample from multiple categorical distributions.
3% X = SAMPLE_VECTOR(P) returns a row vector of cols(P) integers, where
4% X(I) = SAMPLE(P(:,I)).
5%
6% X = SAMPLE_VECTOR(P,COL) returns a row vector of length(COL) integers, where
7% X(I) = SAMPLE(P(:,COL(I))).
8% This is equivalent to SAMPLE_VECTOR(P(:,COL)), but faster.
9
10% Written by Tom Minka
11% (c) Microsoft Corporation. All rights reserved.
12
13cdf = cumsum(p);
14if nargin >= 2
15  cdf = cdf(:,col);
16end
17if any(cdf(end,:) <= 0)
18  error('distribution is all zeros');
19end
20u = rand(1,cols(cdf)).*cdf(end,:);
21x = col_sum(cdf < repmat(u,rows(cdf),1)) + 1;
Note: See TracBrowser for help on using the repository browser.