I have a list of 10 probabilities that I want to transform to line segments so I can perform roulette wheel selection. How can I transform to line segments?
Probability list:
[0.17 0.15 0.14 0.14 0.11 0.1 0.06 0.06 0.04 0.03]
When transformed into line segments should be:
[0.17 0.32 0.46 0.60 0.71 0.81 0.87 0.93 0.97 1.0]
Right now this is my code:
to calculate-s
let i 1 ;; previously added a 0 to list using set p-list fput 0 p-list
while [i < 11] [
ask turtles [
if [p] of self = item i p-list [
let s (p + item (i - 1) p-list)
]
]
set i (i + 1)
]
end
But of course it just sums the current probability and the previous one so I get:
[0.17 0.32 0.29 0.28 etc]