Bound propagation
Linear and interval bound propagation in Pytorch with easy-to-use API, GPU support, and heavy parallization. Initially made as an alternative to the original CROWN implementation which featured only Numpy, lots of for-loops, and a cumbersome API.
To install:
pip install bound-propagation
Supported bound propagation methods:
For the examples below assume the following network definition:
from torch import nn
from bound_propagation import crown, crown_ibp, ibp
# The decorators _must_ be on a subclass of nn.Sequential
@crown
@crown_ibp
@ibp
class Network(nn.Sequential):
def __init__(self, *args):
if args:
# To support __get_index__ of nn.Sequential when slice indexing
# CROWN (and implicitly CROWN-IBP) is doing this underlying
super().__init__(*args)
else:
in_size = 30
classes = 10
super().__init__(
nn.Linear(in_size, 16),
nn.Tanh(),
nn.Linear(16, 16),
nn.Tanh(),
nn.Linear(16, classes)
)
net = Network()
Alternatively, you can add the functions to your network by calling the functions with an instance of your network:
from torch import nn
from bound_propagation import crown, crown_ibp, ibp
class Network(nn.Sequential):
def __init__(self, *args):
if args:
# To support __get_index__ of nn.Sequential when slice indexing
# CROWN (and implicitly CROWN-IBP) is doing this underlying
super().__init__(*args)
else:
in_size = 30
classes = 10
super().__init__(
nn.Linear(in_size, 16),
nn.Tanh(),
nn.Linear(16, 16),
nn.Tanh(),
nn.Linear(16, classes)
)
# The instance _must_ be an nn.Sequential or a subclass thereof
net = crown(crown_ibp(ibp(Network())))
The method also works with nn.Sigmoid and nn.ReLU.
Interval bounds
To get interval bounds for either IBP, CROWN, or CROWN-IBP:
x = torch.rand(100, 30)
epsilon = 0.1
lower, upper = x - epsilon, x + epsilon
ibp_bounds = net.ibp(lower, upper)
crown_bounds = net.crown_interval(lower, upper)
crown_ibp_bounds = net.crown_ibp_interval(lower, upper)
Linear bounds
To get linear bounds for either CROWN or CROWN-IBP:
x = torch.rand(100, 30)
epsilon = 0.1
lower, upper = x - epsilon, x + epsilon
crown_bounds = net.crown_linear(lower, upper)
crown_ibp_bounds = net.crown_ibp_linear(lower, upper)
Authors
- Frederik Baymler Mathiesen - PhD student @ TU Delft
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bound_propagation-0.1.2.tar.gz.
File metadata
- Download URL: bound_propagation-0.1.2.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7006b785f68f96ac6e854eb3fcccf7d5c536ad7fa9c50f45e0a4bf4fbb3af006
|
|
| MD5 |
3269e93e1ab2307c74977644a29204ca
|
|
| BLAKE2b-256 |
f60e38e421db072920777e1aa19730ee3ae71cdb0c69a01d6f7db52da26b0dc3
|
File details
Details for the file bound_propagation-0.1.2-py3-none-any.whl.
File metadata
- Download URL: bound_propagation-0.1.2-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac00f55a4cdc9d60ddd8563b2129085147dda3533af8126cf88a2d34bffdda0f
|
|
| MD5 |
58ad1193582b13324790a74c20cd164f
|
|
| BLAKE2b-256 |
ec238e811e3a8222c19a92984110f970dd94315f8429607e398b24284142b6cd
|