Skip to main content

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bound_propagation-0.2.2.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bound_propagation-0.2.2-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file bound_propagation-0.2.2.tar.gz.

File metadata

  • Download URL: bound_propagation-0.2.2.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for bound_propagation-0.2.2.tar.gz
Algorithm Hash digest
SHA256 1488af9c9f1669cd20bb967c4e9e50f5144ec1c1b9290228c37b7d10c5f2c3f7
MD5 2bfea32c63f8c19ee99dcf73808388b0
BLAKE2b-256 77d06b95c8f995803bf2be999f8716a8cc42e3b25af57718964111c66cfc8391

See more details on using hashes here.

File details

Details for the file bound_propagation-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: bound_propagation-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for bound_propagation-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 426ffb188d74aff015260218dbed08bcd307906228d69748498bec87763fb25b
MD5 b1906823b85c7d8878ae4429a41ce30f
BLAKE2b-256 02c8562597cd83dc10a80ccffa1d271d2d17f06c47640ba7af0e9e5e8f848e27

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.11

2 files

0.3.10

2 files

0.3.9

2 files

0.3.8

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.13

2 files

0.2.12

2 files

0.2.11

2 files

0.2.10

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

This release

0.2.2 This release

2 files

0.2.1

2 files

0.2.0

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page