GithubHelp home page GithubHelp logo

fakir's Introduction

fakir

a mildly monadic module for fast faking

A deliberately minimalist library for building graphs of random number generators with interesting dependencies, and running them to generate plausible-looking "fake data" for a variety of domains.

Pure Python with type annotations; depends only on the standard random module.

Let's generate some bogus data with a vaguely oil-and-gas flavor:

from fakir import fixed, rng_fn, uniform, normal, choice, tupled, ifelse
from random import Random
import sys

from typing import List

def main(argv: List[str]) -> int:
    animal = choice(['Wolf', 'Eagle', 'Cheetah'])
    geo = choice(['Outcrop', 'Karst', 'Tundra'])

    formation = animal + fixed(' ') + geo

    area = normal(40, 10)
    height = uniform(10, 100)
    volume = area * height

    phase = choice(['Oil', 'Gas'])
    price = ifelse(phase == fixed('Oil'),
        uniform(30, 60),
        uniform(1.5, 4.5)
    )

    row = tupled(formation, area, height, volume, phase, price, area.iid(), price.iid())

    r = Random(12345)
    for i in range(100):
        print(row.generate(r))

    return 0

if __name__ == '__main__':
    sys.exit(main(sys.argv))

fakir is "monad-inspired": there's an explicit bind, but graphs are implicitly monadic by default. That is, in the example above, price generates prices corresponding to the phase generated by phase in a given "generation cycle"---it's as if we really had written (using the phase and price produced "tupled" by phase_price):

phase = choice(['Oil', 'Gas'])
phase_price = phase.bind(
        lambda p: (
            uniform(30, 60) if p == 'Oil' else uniform(1.5, 4.5)
        ).fmap(lambda pr: (p, pr))) 

To "opt out" of this implicit bind, clone Fakir objects into independent identically distributed objects with the iid method.

Why is this a "package" and not a "module"? PEP 561 says that's the only way to get type information distributed (with py.typed). Someone who actually cares enough to bother should start a petition or something, because this kind of unbridled complexity addiction is what's destroying Python and the last shreds of my sanity.

View the full pdocs-generated API documentation.

Install with:

pip install fakir

Or download directly from PyPI.

(c) 2020 dwt | terminus data science, LLC

available under the Apache License 2.0

fakir's People

Contributors

derrickturk avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.