Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Dirichlet distribution
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===From marginal beta distributions=== A less efficient algorithm<ref>{{cite book |author1=A. Gelman |author2=J. B. Carlin |author3=H. S. Stern |author4=D. B. Rubin | year=2003 | title= Bayesian Data Analysis |url=https://archive.org/details/bayesiandataanal00gelm |url-access=limited | edition=2nd | isbn=1-58488-388-X | pages=[https://archive.org/details/bayesiandataanal00gelm/page/n607 582]|publisher=Chapman & Hall/CRC }}</ref> relies on the univariate marginal and conditional distributions being beta and proceeds as follows. Simulate <math>x_1</math> from <math display=block>\textrm{Beta}\left(\alpha_1, \sum_{i=2}^K \alpha_i \right)</math> Then simulate <math>x_2, \ldots, x_{K-1}</math> in order, as follows. For <math>j=2, \ldots, K-1</math>, simulate <math>\phi_j</math> from <math display=block>\textrm{Beta} \left(\alpha_j, \sum_{i=j+1}^K \alpha_i \right ),</math> and let <math display=block>x_j= \left(1-\sum_{i=1}^{j-1} x_i \right )\phi_j.</math> Finally, set <math display=block>x_K=1-\sum_{i=1}^{K-1} x_i.</math> This iterative procedure corresponds closely to the "string cutting" intuition described above. Below is example Python code to draw the sample: <syntaxhighlight lang="python"> params = [a1, a2, ..., ak] xs = [random.betavariate(params[0], sum(params[1:]))] for j in range(1, len(params) - 1): phi = random.betavariate(params[j], sum(params[j + 1 :])) xs.append((1 - sum(xs)) * phi) xs.append(1 - sum(xs)) </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)