Skip to content

Instantly share code, notes, and snippets.

@berrytj
Last active August 29, 2015 14:05
Show Gist options
  • Save berrytj/e83e56a52f1737e7ac5a to your computer and use it in GitHub Desktop.
Save berrytj/e83e56a52f1737e7ac5a to your computer and use it in GitHub Desktop.
Curried
from __future__ import division
from funcy.curried import *
from fn import _ as __
from bookends import _
import survey
def total_probability((outcome, pmf)):
return (_| pmf
| select_keys(__ == outcome)
| __.values
| call
| sum
|_)
def prglength_pmf(records):
return (_| records
| count_by(__.prglength)
| walk_values(__ / len(records))
|_)
@curry
def born_on_or_after(records, week):
return filter(__.prglength >= week,
records)
def main():
births = survey.read_records()
outcomes = range(60)
prglength_groups = map(born_on_or_after(births),
outcomes)
print (_| prglength_groups
| map(prglength_pmf)
| partial(zip, outcomes)
| map(total_probability)
|_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment