Original Translation
7
Fredrik Lundh for his `Alternative Python Reference <http://effbot.org/zone/pyref.htm>`_ project from which Sphinx got many good ideas.
Fredrik Lundh pour son projet `Alternative Python Reference <http://effbot.org/zone/pyref.htm>`_, dont Sphinx a pris beaucoup de bonnes idées.
8
See :ref:`reporting-bugs` for information how to report bugs in this documentation, or Python itself.
Veuillez consulter :ref:`reporting-bugs` pour savoir comment signaler des bugs dans cette documentation ou dans Python lui-même.
9
Contributors to the Python Documentation
Contributeurs de la documentation Python
10
This section lists people who have contributed in some way to the Python documentation. It is probably not complete -- if you feel that you or anyone else should be on this list, please let us know (send email to docs@python.org), and we'll be glad to correct the problem.
Cette section recense les personnes qui ont contribué à la documentation Python. Elle n'est probablement pas complète -- si vous pensez que vous ou quiconque devrait y figurer, faites-le nous savoir (envoyez un e-mail à docs@python.org), nous nous ferons un plaisir de corriger ce problème.
11
Aahz
Suggestion 0 by nobody:
I'ld love to know how this went. I've been teaching Python to bisioglots for the last 1 & 1/2 months and would lie to share notes on methods, your experience trying to hold a seminar, etc etc
Suggestion 1 by nobody:
I did not look at other solutions berofe coding my two that are below. Of my two, I would like to check for applicability then go with the simpler, memory-hungry probchoice2() if possible over the more than twice as long probchoice().The test info given is not repeatable and must be checked by hand In a production environment I would need to select some delta and ensure calculated probabilities are within delta of the input probs.Now looking at other comments, it's nice to see that Miki gave tests too :-)And looking at lorq's comment to Miki, I had thought of precision and made my bin count selectable. I'm working on a PC with a gig of ram, and thought that working to three digits of precision as the default would be OK.The prog:[python] '\Answer to Author Donald Paddy' McCarthy, Feb 2008, paddy3118-at-gmail-dot-com You have a mapping between items and probabilities. You need to choose each item with its probability. For example, consider the items [’good’, ‘bad’, ‘ugly’], with probabilities of [0.5, 0.3, 0.2] accordingly. Your solution should choose good with probability 50%, bad with 30% and ugly with 20%. Sample output: ## ## PROBCHOICE ## Trials: 100000 Target probability: 0.500,0.300,0.200 Attained probability: 0.500,0.302,0.197 ## ## PROBCHOICE2 ## Trials: 100000 Target probability: 0.500,0.300,0.200 Attained probability: 0.502,0.299,0.199 >>> it = probchoice2( good bad ugly'.split(), [0.5, 0.3, 0.2]) >>> for x in range(10): print it.next() bad bad bad ugly good bad good good good bad >>> 'import randomdef probchoice(items, probs): '\ Splits the interval 0.0-1.0 in proportion to probs then finds where each random.random() choice lies ' prob_accumulator = 0 accumulator = [] for p in probs: prob_accumulator += p accumulator.append(prob_accumulator) accumZitems = zip(accumulator, items)[:-1] last_item = items[-1] while True: r = random.random() for prob_accumulator, item in accumZitems: if r <= prob_accumulator: yield item break else: # last range handled by else clause yield last_itemdef probchoice2(items, probs, bincount=1000): '\ Puts items in bins in proportion to probs then uses random.choice() to select items. Larger bincount for more memory use but higher accuracy (on avarage). ' prob_accumulator = 0 bins = [] for item,prob in zip(items, probs): bins += [item]*int(bincount*prob) while True: yield random.choice(bins)def tester(func=probchoice, items='good bad ugly'.split(), probs=[0.5, 0.3, 0.2], trials = 100000 ): def problist2string(probs): '\ Turns a list of probabilities into a string Also rounds FP values ' return , .join( %5.3f' % (p,) for p in probs) from collections import defaultdict counter = defaultdict(int) it = func(items, probs) for dummy in xrange(trials): counter[it.next()] += 1 print \n
##\n
## %s\n
## % func.func_name.upper() print Trials: , trials print Target probability: , problist2string(probs) print Attained probability: , problist2string( counter[x]/float(trials) for x in items)if __name__ == __main__': tester() tester(probchoice2)[/python]
Suggestion 2 by nobody:
BYajUF <a href="http://ivnrytwctrwc.com/">ivnrytwctrwc</a>
Suggestion 3 by nobody:
93VI4H <a href="http://ibncxcjjdjro.com/">ibncxcjjdjro</a>
Suggestion 4 by nobody:
egion6 , [url=http://dhsioekcxwmn.com/]dhsioekcxwmn[/url], [link=http://sdojlgeqkzcy.com/]sdojlgeqkzcy[/link], http://pcqcfddravhp.com/
Suggestion 5 by nobody:
h7pgSO , [url=http://vmctwgtkywtn.com/]vmctwgtkywtn[/url], [link=http://ssdhvpfcjwka.com/]ssdhvpfcjwka[/link], http://tapnatwelmws.com/
Suggestion 6 by nobody:
mwimEq <a href="http://abqcqqkpucrw.com/">abqcqqkpucrw</a>
Suggestion 7 by nobody:
N2FTNF <a href="http://kjevccwqyfpy.com/">kjevccwqyfpy</a>
Suggestion 8 by nobody:
Tj69ny , [url=http://sanrbekqkqpf.com/]sanrbekqkqpf[/url], [link=http://hkbiaqzfqaxv.com/]hkbiaqzfqaxv[/link], http://mcmtlrlachnn.com/
Suggestion 9 by nobody:
wnw7pz , [url=http://rebcfahkjjth.com/]rebcfahkjjth[/url], [link=http://kkhwbtxwwsru.com/]kkhwbtxwwsru[/link], http://yaqsxmfaoafq.com/
Suggestion 10 by nobody:
Thank you for any other fantastic article. The place else may just anybody get that kind of info in such a perfect manner of writing? I've a presentation next week, and I'm on the look for such info.<a href="http://www.wowgolds.ca" title="wow gold">wow gold</a>
12
Michael Abbott
Michael Abbott
13
Steve Alexander
Steve Alexander
14
Jim Ahlstrom
Jim Ahlstrom
15
Fred Allen
Fred Allen
16
A. Amoroso
A. Amoroso