Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit model specification #68

Merged
merged 20 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a6b9de9
move actions from core, stop from being a provider module
wilsonmr Apr 28, 2021
5b6b28d
add new type of model, which is a sequence of other models, allowing …
wilsonmr Apr 28, 2021
7b6b3c5
remove duplicate import
wilsonmr Apr 29, 2021
4122eb7
only allow explicit specification of models
wilsonmr Apr 29, 2021
4dbe1a4
move sequential to layers
wilsonmr Apr 30, 2021
8be7987
update module names, cleanup some docs warnings
wilsonmr Apr 30, 2021
2e3d670
remove spurious comment in train
wilsonmr Apr 30, 2021
76cb8ea
flatten out the inner layers in model_to_load
wilsonmr Apr 30, 2021
4d287db
might as well just call the model params input model
wilsonmr Apr 30, 2021
3a1232e
add basic layers tests
wilsonmr Apr 30, 2021
4f68d58
model tests, probably could be improved but at least have coverage.
wilsonmr Apr 30, 2021
20a41de
renamed coupling_pair to coupling_block
jmarshrossney May 14, 2021
af77d41
layer actions for batch norm and global rescaling
jmarshrossney May 14, 2021
3b52d3c
update example runcards
jmarshrossney May 14, 2021
5bfc87a
remove default scale factor for global rescaling layer
jmarshrossney May 14, 2021
6e44773
add epsilon and remove shift from data standardisation
jmarshrossney May 14, 2021
ff02307
update tests
jmarshrossney May 14, 2021
f147afa
add test for independence of rescaling layers, including breaking exa…
jmarshrossney May 14, 2021
8abf747
update layer independence test for generic layers
jmarshrossney May 14, 2021
3e50d20
raise AssertionError instead of custom exception
jmarshrossney May 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions anvil/benchmark_config/free_scalar_train.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ couplings:
# Model
base: gaussian

#model: rational_quadratic_spline
#model: real_nvp
model: nice
model_params:
n_affine: 2
n_additive: 2
model:
- layer: nice
n_blocks: 2
hidden_shape: [36]
activation: tanh
z2_equivar: True
- layer: global_rescaling
scale: 1
learnable: True

# Training length
n_batch: 2000
Expand Down
4 changes: 2 additions & 2 deletions anvil/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def free_scalar_theory(couplings, lattice_length):
def fourier_transform(configs, training_geometry):
"""Takes the Fourier transform of a sample of field configurations.

Inputs
------
Parameters
----------
configs: torch.tensor
A (hopefully decorrelated) sample of field configurations in the
split representation. Shape: (sample_size, lattice_size)
Expand Down
8 changes: 4 additions & 4 deletions anvil/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from anvil.geometry import Geometry2D
from anvil.checkpoint import TrainingOutput
from anvil.models import MODEL_OPTIONS
from anvil.models import LAYER_OPTIONS
from anvil.distributions import BASE_OPTIONS, TARGET_OPTIONS

from random import randint
Expand Down Expand Up @@ -84,12 +84,12 @@ def parse_parameterisation(self, param: str):
return param

@explicit_node
def produce_model_action(self, model: str):
def produce_layer_action(self, layer: str):
"""Given a string, return the flow model action indexed by that string."""
try:
return MODEL_OPTIONS[model]
return LAYER_OPTIONS[layer]
except KeyError:
raise ConfigError(f"Invalid model {model}", model, MODEL_OPTIONS.keys())
raise ConfigError(f"Invalid model {layer}", layer, LAYER_OPTIONS.keys())

def parse_n_batch(self, nb: int):
"""Batch size for training."""
Expand Down
24 changes: 14 additions & 10 deletions anvil/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Gaussian:
"""
Class which handles the generation of a sample of latent Gaussian variables.

Inputs:
-------
Parameters
----------
lattice_size: int
Number of nodes on the lattice.
sigma: float
Expand Down Expand Up @@ -59,6 +59,18 @@ class PhiFourScalar:
The forward pass returns the corresponding log density (unnormalised) which
is equal to -S

The parameters required differ depending on the parameterisation you're
using:

================ =============
parameterisation couplings
================ =============
standard m_sq, g
albergo2019 m_sq, lam
nicoli2020 kappa, lam
bosetti2015 beta, lam
================ =============

Parameters
----------
geometry:
Expand All @@ -70,14 +82,6 @@ class PhiFourScalar:
dictionary with two entries that are the couplings of the theory.
See below.


parameterisation couplings
-------------------------------------
standard m_sq, g
albergo2019 m_sq, lam
nicoli2020 kappa, lam
bosetti2015 beta, lam

Notes
-----
The general form of the action is
Expand Down
24 changes: 12 additions & 12 deletions anvil/free_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def gen_complex_normal(n_sample, sigma, real=False):
"""Returns a stack of complex arrays where real and imaginary components
are drawn from a Gaussian distribution with the same width.

Inputs:
-------
Parameters
----------
n_sample: int
sample size
sigma: numpy.ndarray
Expand All @@ -137,8 +137,8 @@ def gen_complex_normal(n_sample, sigma, real=False):
(optional) flag. If True, the imaginary component is set to
zero, but a complex array is still returned.

Returns:
--------
Returns
-------
out: numpy.ndarray
complex array of shape (n_sample, *sigma.shape)
"""
Expand All @@ -157,13 +157,13 @@ def gen_eigenmodes(self, n_sample):
Gaussian distributions with variances given by the eigenvalues of the
kinetic operator - see _variance() method above.

Inputs:
-------
Parameters
----------
n_sample: int
sample size

Returns:
--------
Returns
-------
eigenmodes: numpy.ndarray
complex array of eigenmodes with shape (n_sample, L, L)
where L is the side length of the square lattice.
Expand Down Expand Up @@ -206,13 +206,13 @@ def gen_eigenmodes(self, n_sample):
def gen_real_space_fields(self, n_sample):
"""Returns the inverse fourier transform of a sample of eigenmodes.

Inputs:
-------
Parameters
----------
n_sample: int
sample size

Returns:
--------
Returns
-------
fields: numpy.ndarray
real array of real-space fields, with shape (n_sample, L, L),
where L is the side-length of the square lattice.
Expand Down
Loading