First time here? Check out the FAQ!
x

How does nextRandomIndexFromDistribution work with positive integers as the weights?

+1 vote
48 views

really interesting family of randomIndexDistribution: CapyTalk

I was looking at the Help description, and do understand it but then confused by one example:

 

(1 bpm: !BPM) nextRandomIndexFromDistribution: (0 to: 15 collect: [ :i | i twoExp])

 

this expands to

 (1 bpm: !BPM dutyCycle: 0.5) nextRandomIndexFromDistribution: #( 1.0 2.0 4.0 8.0 16.0 32.0 64.0 128.0 256.0 512.0 1024.0 2048.0 4096.0 8192.0 16384.0 32768.0 )

as the two Exponential becomes large integers, then how does that relate to a percentage probability, as described in the description?

 for example, if #(aStatisticalDistribution) is #(0 0.5 0.25 0.25), there is a zero likelihood of selecting a 0, a 50% chance of selecting 1, and a 25% chance of selecting 2 or 3.

 

asked Jan 18 in Capytalk & Smalltalk by cristian-vogel (Master) (6,890 points)

1 Answer

0 votes
 
Best answer
The weights in the Array are normalized internally before being used as likelihoods. So in this example, all of the weights would be divided by 32768.0 so the likelihoods would be #(1.0/32768.0, 2.0/32768.0, .., 16384.0/32768.0, 1.0).
answered Jan 18 by ssc (Savant) (95,510 points)
selected Jan 21 by cristian-vogel
...