choices

For making random decisions
Download

choices Ranking & Summary

Advertisement

  • Rating:
  • License:
  • The Apache License 2.0
  • Price:
  • FREE
  • Publisher Name:
  • Tim McNamara
  • Publisher web site:
  • http://timmcnamara.co.nz

choices Tags


choices Description

choices is designed to make it easy to make it easy to make things happen in a probablistic manner. Provide keys with an associated probability attached, and then call the resulting object when you need a new value. >>> mood = PDist({'happy': 0.3, 'neutral': 0.6, 'sad': 0.1}) >>> mood() 'happy' >>> mood() 'neutral'You can retrieve the distribution of how those values are applied by accessing the PDist.distribution attribute: >>> mood.distribution As well as providing a dict to assign probabilities, you can send in a list of lists/tuples. This allows for for non-hashable types to be used. This means that you provide objects such as functions to be used as keys: >>> def grumpy(news): ... return ':/' >>> def happy(news): ... return ':)' >>> react = PDist() >>> reaction = react() >>> reaction("We're getting married!") ':/'You are not restricted to adding your input variables up to 1. For example, if you only have a tally chart, and wish to calculate a probability distribution from that sample, you can provide that too: >>> spotted = {'geese': 0, 'ducks': 12, 'sparrows': 4, 'other': 39} >>> bird_pdist = PDist(spotted) >>> bird_pdist.distribution Retrieving the probability of a particular key is supported. However, the search strategy is very inefficient and probably shouldn't be used outside of the interactive Python shell. >>> bird_pdist 0.0Product's homepage


choices Related Software