# Napkin Folding — camdp.com

## Generating exponential survival data

Posted by Cameron Davidson-Pilon at

Suppose we interested in generating exponential survival times with scale parameter $$\lambda$$, and having $$\alpha$$ probability of censorship, $$0 \le \alpha < 1$$. This is actually, at least from what I tried, a non-trivial problem. I've derived a few algorithms: Algorithm 1  Generate $$T \sim \text{Exp}( \lambda )$$. If $$\alpha = 0$$, return $$(T, 1)$$.   Solve $$\frac{ \lambda h }{ \exp (\lambda h) -1 } = \alpha$$ for $$h$$.  Generate $$E \sim \text{TruncExp}( \lambda, h )$$, where $$\text{TruncExp}$$ is...

## Multi-Armed Bandits

Posted by Cameron Davidson-Pilon at

Preface: This example is a (greatly modified) excerpt from the open-source book Bayesian Methods for Hackers, currently being developed on Github Adapted from an example by Ted Dunning of MapR Technologies The Multi-Armed Bandit Problem Suppose you are faced with $$N$$ slot machines (colourfully called multi-armed bandits). Each bandit has an unknown probability of distributing a prize (assume for now the prizes are the same for each bandit, only the probabilities differ). Some bandits are very generous, others not so...

## An algorithm to sort "Top" comments

Posted by Cameron Davidson-Pilon at

(originally posted on camdp.com) Preface: This example is a (greatly modified) excerpt from the open-source book Bayesian Methods for Hackers, currently being developed on Github ;) Why is sorting from "best" to "worst" so difficult? Consider ratings on online products: how often do you trust an average 5-star rating if there is only 1 reviewer? 2 reviewers? 3 reviewers? We implicitly understand that with such few reviewers that the average rating is not a good reflection of the true value...