From d6a21639740c415e55b945ef9b327f8ef2fe011c Mon Sep 17 00:00:00 2001 From: David Nabergoj Date: Sat, 21 Oct 2023 12:10:28 +0200 Subject: [PATCH 1/7] Add markdown file with examples --- examples/README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 examples/README.md diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..0c02e7c --- /dev/null +++ b/examples/README.md @@ -0,0 +1,46 @@ +# Examples + +We provide minimal working examples on how to perform various common tasks with normalizing flows. +We use Real NVP as an example, but you can replace it with any other bijections from `normalizing_flows.bijections`. + +## Training a normalizing flow on a fixed dataset +```python +import torch +from normalizing_flows import Flow +from normalizing_flows.bijections import RealNVP + +torch.manual_seed(0) + +# We support arbitrary event and batch shapes +event_shape = (2, 3) +batch_shape = (5, 7) +x_train = torch.randn(size=(*batch_shape, *event_shape)) + +bijection = RealNVP(event_shape=event_shape) +flow = Flow(bijection) + +flow.fit(x_train, show_progress=True) +``` + +## Computing the log determinant of the Jacobian transformation given a Flow +```python +import torch +from normalizing_flows import Flow +from normalizing_flows.bijections import RealNVP + +torch.manual_seed(0) + +batch_shape = (5, 7) +event_shape = (2, 3) +x = torch.randn(size=(*batch_shape, *event_shape)) +z = torch.randn(size=(*batch_shape, *event_shape)) + +bijection = RealNVP(event_shape=event_shape) +flow = Flow(bijection) + +_, log_det_forward = flow.bijection.forward(x) +# log_det_forward.shape == batch_shape + +_, log_det_inverse = flow.bijection.inverse(z) +# log_det_inverse.shape == batch_shape +``` \ No newline at end of file From 74e75b1fe310984a6a4421ef5d508db4e4e0bd98 Mon Sep 17 00:00:00 2001 From: David Nabergoj Date: Sat, 21 Oct 2023 12:11:28 +0200 Subject: [PATCH 2/7] Fix typo --- examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index 0c02e7c..9cadc02 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,7 +1,7 @@ # Examples We provide minimal working examples on how to perform various common tasks with normalizing flows. -We use Real NVP as an example, but you can replace it with any other bijections from `normalizing_flows.bijections`. +We use Real NVP as an example, but you can replace it with any other bijection from `normalizing_flows.bijections`. ## Training a normalizing flow on a fixed dataset ```python From 0783079cb08f626f05381d96f0f126c6d705d173 Mon Sep 17 00:00:00 2001 From: David Nabergoj Date: Sat, 21 Oct 2023 12:14:52 +0200 Subject: [PATCH 3/7] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 722dfa5..c3799c4 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ print(log_prob.shape) # (100,) print(x_new.shape) # (50, 3) ``` +We provide more examples [here](examples/README.md). + ## Brief background A normalizing flow (NF) is a flexible distribution, defined as a bijective transformation of a simple statistical From c9604467f91ced26a58981d9f2d033f5d32d1659 Mon Sep 17 00:00:00 2001 From: David Nabergoj Date: Sat, 21 Oct 2023 12:25:02 +0200 Subject: [PATCH 4/7] Update workflow --- .github/workflows/python-package-conda.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index 97e72b8..b7632e7 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -1,26 +1,33 @@ -name: Python Package using Conda +name: Setup and run tests -on: [push] +on: + push: + branches: [ "main", "dev"] + pull_request: + branches: [ "main", "dev" ] + workflow_dispatch: jobs: - build-linux: + build: + runs-on: ubuntu-latest strategy: - max-parallel: 5 + fail-fast: false + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v3 - - name: Set up Python 3.10 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: - python-version: '3.10' + python-version: ${{ matrix.python-version }} - name: Add conda to system path run: | # $CONDA is an environment variable pointing to the root of the miniconda directory echo $CONDA/bin >> $GITHUB_PATH - name: Install dependencies run: | - # conda env update --file environment.yml --name base pip install -r requirements.txt - name: Lint with flake8 run: | From 6924c3d94571b2a74ceaa2b6603905e6ebff56ff Mon Sep 17 00:00:00 2001 From: David Nabergoj Date: Sat, 21 Oct 2023 12:32:54 +0200 Subject: [PATCH 5/7] Add python versions 3.5 and 3.6 to workflow --- .github/workflows/python-package-conda.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index b7632e7..fc0943d 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v3 From c00117ab9c7eff48a8583f5ce348b9c96cab52bb Mon Sep 17 00:00:00 2001 From: David Nabergoj Date: Sat, 21 Oct 2023 12:36:18 +0200 Subject: [PATCH 6/7] Update README.md --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index c3799c4..b534770 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,17 @@ print(x_new.shape) # (50, 3) We provide more examples [here](examples/README.md). +## Installing + +We support Python versions 3.6 and upwards. + +Install via git: +```python +git clone https://github.com/davidnabergoj/normalizing-flows.git +cd normalizing-flows +pip install -r requirements.txt +``` + ## Brief background A normalizing flow (NF) is a flexible distribution, defined as a bijective transformation of a simple statistical From a7e66a91250e5ebde66d0eb7823e89e4a7f94f3a Mon Sep 17 00:00:00 2001 From: David Nabergoj Date: Sat, 21 Oct 2023 12:38:59 +0200 Subject: [PATCH 7/7] Remove Python versions 3.5 and 3.6 from build support. --- .github/workflows/python-package-conda.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index fc0943d..b7632e7 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v3 diff --git a/README.md b/README.md index b534770..113990c 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ We provide more examples [here](examples/README.md). ## Installing -We support Python versions 3.6 and upwards. +We support Python versions 3.7 and upwards. Install via git: ```python