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: Olaf Till
Subject: Re: Choose index into array of probabilities
Date: Fri, 25 Aug 2006 09:47:40 +0200
User-agent: Mutt/1.5.9i

On Thu, Aug 24, 2006 at 08:29:52PM +0200, Søren Hauberg wrote:
> 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);
> >   idx = find(cs >= rand());
> Okay, this getting embarresing:
>     cs = cumsum(p);

Sorry for meddling in, but should this not be:

      cs = cumsum (p(:));

Otherwise `cumsum' sums each column separately.

Olaf

>     idx = find(cs >= rand())(1);
> 
> Søren
> 
> P.S. I shouldn't be answering questions, when I'm tired.
> 
> > 
> > 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
> 
> 
> _______________________________________________
> 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]