No project description provided
Project description
malib
A few utilities that I find useful.
RateLimiter
from malib import RateLimiter
# call a function at most 10 times per minute
rl = RateLimiter(max_calls=10, period=60)
# call .wait() every time before calling the function
rl.wait()
Exact cover
Code inspired by this blog post.
from malib import exact_cover
piece_to_constraints = {"A": {1}, "B": {2, 4}, "C": {2, 3, 5}, "D": {3, 5}}
next(exact_cover(piece_to_constraints))
# ("A", "B", "D")
PyTorch bivariate normal cdf
Provide two functions to compute a differentiable cumulative distribution function of a bivariate normal distribution.
Requires scipy and pytorch.
import torch
from malib import standard_bivariate_normal_cdf, bivariate_normal_cdf
# standard bivariate normal cdf
x = torch.tensor([0.0, 0.0], requires_grad=True)
cor = 0.5
y = standard_bivariate_normal_cdf(x, cor)
print(y)
# tensor(0.3333, grad_fn=<StandardBivariateNormalCDFBackward>)
y.backward()
print(x.grad)
# tensor([0.1995, 0.1995])
# bivariate_normal_cdf
x = torch.tensor([0.0, 0.0], requires_grad=True)
mean = torch.tensor([0.0, 0.0])
cov = torch.tensor([[1.0, 0.5], [0.5, 1.0]])
y = bivariate_normal_cdf(x, mean, cov)
print(y)
# tensor(0.3333, grad_fn=<BivariateNormalCDFBackward>)
y.backward()
print(x.grad)
# tensor([0.1995, 0.1995])
Testing
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
malib-0.3.0.tar.gz
(2.9 kB
view details)
Built Distribution
malib-0.3.0-py3-none-any.whl
(3.9 kB
view details)
File details
Details for the file malib-0.3.0.tar.gz
.
File metadata
- Download URL: malib-0.3.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b2ac25661a8eede50db9b2adba0539d7a8a2aa0de50dcaee4bf5b8b827bbab7 |
|
MD5 | ba75e85730521b30999e0034dfb201b7 |
|
BLAKE2b-256 | 2dd6a97d914d7e84fb5181e7e1f78092b4e276a1f8c55fdd6dae5e01c5b704bb |
File details
Details for the file malib-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: malib-0.3.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a10e635a294791406a055d95cee219a9395933281997e3397e8f5830b07865c |
|
MD5 | 3231073ebbc735e28d95ecd80b4b81c4 |
|
BLAKE2b-256 | 07f0d20a531def08127fe1995dffaef9feaedc05068dbdd8909fb3f62125ae9e |