Last change
on this file since 177 was
37,
checked in by (none), 15 years ago
|
Added original make3d
|
-
Property svn:executable set to
*
|
File size:
667 bytes
|
Line | |
---|
1 | function 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 |
|
---|
13 | cdf = cumsum(p);
|
---|
14 | if nargin >= 2
|
---|
15 | cdf = cdf(:,col);
|
---|
16 | end
|
---|
17 | if any(cdf(end,:) <= 0)
|
---|
18 | error('distribution is all zeros');
|
---|
19 | end
|
---|
20 | u = rand(1,cols(cdf)).*cdf(end,:);
|
---|
21 | x = col_sum(cdf < repmat(u,rows(cdf),1)) + 1;
|
---|
Note: See
TracBrowser
for help on using the repository browser.