help-octave
[Top][All Lists]
Advanced

[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:25:32 +0200

tor, 24 08 2006 kl. 20:18 +0200, skrev Søren Hauberg:
> 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);
Sorry, this should of course be
    cs = sumsum(p);

>   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
> 
> 
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave




reply via email to

[Prev in Thread] Current Thread [Next in Thread]