Re: ISO help in probability



Helmut Giese wrote:
> Hello out there,
> I have a set of variables each of which has a certain weight or
> probability assigned. Say
> a -> 50
> b -> 30
> c -> 10
> d -> 10
>
> I want an algorithm which (in the above example) selects 'a' in every
> other run and 'c' in 10% of the runs (approximately of course).
>
> My attempt below fails miserably. Using the weights above, 'a' scores
> way too high, mostly at the expense of 'c' and 'd', which are far away
> from their expected 10% shares.
> Evidently my logic is flawed: Foreach variable I get the current
> probability by multiplying a random value with the associated weight,
> and then select the one with the highest result.
>
> Any advice on the 101 of probability applicable here will be greatly
> appreciated.
> Best regards
> Helmut Giese

Basically it works like this:

You divide your probability space [1-100] (if you use percentage) into
intervals based on the weights you have. So for your example you map the
letters to this intervals:

a -> [1 50]
b -> [51 80]
c -> [81 90]
d -> [91 100]

Now you generate a random number between 1 and 100 and lookup in which
interval it is, thats the winner.

If you only allow integer weights, you can get lazy like this:

proc create_wtable {var weights} {
upvar 1 $var table
set table [list {}]
foreach {key weight} $weights {
for {set i 0} {$i < $weight} {incr i} {
lappend table $key
}
}
# return the value for probability 1.0
return [expr {[llength $table]-1}]
}

proc pick_random {var max} {
upvar 1 $var table
lindex $table [math::random 1 $max]
}

# test
set max [create_wtable wtab {a 50 b 30 c 10 d 10} ]
puts [pick_random wtab $max]

Michael
.



Relevant Pages

  • Re: BAYESIAN (weighted) PROBABILITY ??
    ... > where Pis the prior probability. ... liklihood ratio actually already contains the weights. ... that GOD=G_uv is CORRECT, given the scientific evidence". ...
    (sci.stat.math)
  • Re: How do I sample randomly based on some probability(wightage)?
    ... I need to randomly sample from a list where all choices have weights ... In short I mean if prob of a H is .9 and probability of T be 0.1 then ... Replace each item with the sum of all the items up to and including itself. ...
    (comp.lang.python)
  • Logistic Regression
    ... words in training texts, ten per author. ... I start with a 0 vector for the initial set of weights. ... where my 10 "0" texts are assigned a probability very ... differences to be added to the weights < 0.01) in any reasonable time. ...
    (sci.stat.math)
  • Re: Combining Probabilities?
    ... I have two different predictors which generate a probability between ... One predictor has a limited set of symbols it will generate ... You can also use sets of weights selected by some small ... In paq1 I counted 0 and 1 bits in each context, ...
    (comp.compression)
  • Re: version of Golub Chan LeVeque stable algorithm for sample variance applicable to weighted observ
    ... var = 0.0 ... I'm having trouble with the adaptation of the second formula ... to the situation where there is a parallel array of weights p, ... normalize so it has metric of a probability weight ...
    (sci.stat.consult)