[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Choose index into array of probabilities
From: |
Søren Hauberg |
Subject: |
Re: Choose index into array of probabilities |
Date: |
Thu, 24 Aug 2006 20:18:57 +0200 |
tor, 24 08 2006 kl. 23:38 +0530, skrev Masatran (Deepak), R.:
> I have an array, of probabilities which add up to 1. How can I generate an
> index into this array with each array cell being chosen with probability
> equal to the cell value?
Assuming p is the array of probabilities:
cs = cumsum(a);
idx = find(cs >= rand());
This should do it. I think I've written those line of code 100 times
(it's a central part of the particle filter)
Søren
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
- Choose index into array of probabilities, Masatran (Deepak), R., 2006/08/24
- Re: Choose index into array of probabilities,
Søren Hauberg <=
- Re: Choose index into array of probabilities, Søren Hauberg, 2006/08/24
- Re: Choose index into array of probabilities, Søren Hauberg, 2006/08/24
- Re: Choose index into array of probabilities, Olaf Till, 2006/08/25
- Re: Choose index into array of probabilities, Søren Hauberg, 2006/08/25
- Re: Choose index into array of probabilities, Dushan Mitrovich, 2006/08/25
- reading mail problems (was Re: Choose index into array of probabilities), Quentin Spencer, 2006/08/25
- Re: reading mail problems (was Re: Choose index into array of probabilities), Joshua Rigler, 2006/08/25
- Re: reading mail problems (was Re: Choose index into array of probabilities), Steven Levine, 2006/08/25
- Re: reading mail problems (was Re: Choose index into array of probabilities), Søren Hauberg, 2006/08/26