Coder Social home page Coder Social logo

sample_convex_combinations's Introduction

ABANDONED

sample_convex_combinations

Samples from convex combination space.

In theory this module "only" provides a bit of math. In practice, it's a useful piece of abstraction.

This module provides a function that pickes a convex combination of a desired dimension (= number of items), uniformly distributed among all convex combinations. It is possible supply your own RNG, or a hand-picked point from a hypercube (uniform distribution in the hypercube guarantees uniform distribution in "convex combination"-space).

Table of Contents

Install

Just pip install sample_convex_combinations. (As soon as I have uploaded it to PyPI.)

Or just copy sample_convex_combinations/_impl.py into your project as sample_convex_combinations.py.

There are no dependencies outside stdlib.

Usage

Let's say you want to interpolate between three things, and wish the sum of the weights to be 1:

>>> import sample_convex_combinations
>>> sample_convex_combinations.sample(3)
[0.6847422669970515, 0.6847422669970515, 0.6847422669970515]  # FIXME

Or maybe you want the sum of the weights to be between 0 and 1:

>>> sample_convex_combinations.sample(3, span_origin=True)
[0.49931160565103394, 0.49931160565103394, 0.49931160565103394]  # FIXME

The default random.random is not enough for your needs? Sure thing! You can substitute your own RNG, for example from secrets:

>>> import secrets
>>> sample_convex_combinations.sample(3, rng=secrets.randbits(64) / (2 ** 64))
[0.49931160565103394, 0.49931160565103394, 0.49931160565103394]  # FIXME

Isn't that nice? :D

Full documentation

FIXME

TODOs

  • Implement
  • Document
  • Do WeirdStuff™ with it
  • Advertise

Contribute

Feel free to dive in! Open an issue or submit PRs.

sample_convex_combinations's People

Contributors

benwiederhake 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.