Skip to content

Commit

Permalink
Update package structure for pypi release
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmoMatt committed Jun 30, 2022
1 parent a0a72e6 commit 97c23d7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
10 changes: 7 additions & 3 deletions ProxNest/tests/test_optimisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import ProxNest.utils as utils
import ProxNest.optimisations as opts
from ProxNest.operators import sensing_operators as sense_ops


@pytest.mark.parametrize("tight", [True, False])
Expand All @@ -20,7 +21,8 @@ def test_l2_ball_projection(tight: bool, pos: bool):
tau = -LogLikeliL(x0) * 1e-1

# Create a parameters structure.
params = utils.create_parameters_dict(y=data, tight=tight, pos=pos, reality=True)
id = sense_ops.Identity()
params = utils.create_parameters_dict(y=data, Phi=id, Psi=id, tight=tight, pos=pos, reality=True)

# Evaluate the projection algorithm
z = opts.l2_ball_proj.sopt_fast_proj_B2(x0, tau, params)
Expand All @@ -34,7 +36,8 @@ def test_l1_norm_projection_extremes(tight: bool, pos: bool):
x = np.random.randn(64, 64)

# Create a parameters structure.
params = utils.create_parameters_dict(tight=tight, pos=pos, reality=True)
id = sense_ops.Identity()
params = utils.create_parameters_dict(tight=tight, Phi=id, Psi=id, pos=pos, reality=True)

if tight:
# Evaluate the l1-norm sub-iterations lambda=0
Expand All @@ -56,7 +59,8 @@ def test_l1_norm_projection_specific(tight: bool, pos: bool):
obj_pred = (3 / 8) * len(x.flatten("C"))

# Create a parameters structure.
params = utils.create_parameters_dict(tight=tight, pos=pos, reality=True)
id = sense_ops.Identity()
params = utils.create_parameters_dict(tight=tight, Phi=id, Psi=id, pos=pos, reality=True)

# Evaluate the l1-norm sub-iterations
z = opts.l1_norm_prox.l1_norm_prox(x, lamb, params)
Expand Down
13 changes: 6 additions & 7 deletions ProxNest/tests/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import ProxNest.utils as utils
import ProxNest.sampling as sampling
import ProxNest.optimisations as optimisations
import ProxNest.operators as operators
from ProxNest.operators import sensing_operators as sense_ops

def test_against_analytic_gaussian():
""" Tests ProxNest against analytic Gaussian """

# A simple identity forward model and redundant dictionary
phi = operators.sensing_operators.Identity()
psi = operators.sensing_operators.Identity()
id = sense_ops.Identity()
sigma = 1
iterations = 20
delta = 1/2
Expand All @@ -22,7 +21,7 @@ def test_against_analytic_gaussian():
# Parameter dictionary associated with optimisation problem of resampling from the prior subject to the likelihood iso-ball
params = utils.create_parameters_dict(
y = image, # Measurements i.e. data
Phi = phi, # Forward model
Phi = id, # Forward model
epsilon = 1e-3, # Radius of L2-ball of likelihood
tight = True, # Is Phi a tight frame or not?
nu = 1, # Bound on the squared-norm of Phi
Expand Down Expand Up @@ -55,16 +54,16 @@ def test_against_analytic_gaussian():
params["y"] = image

# Lambda functions to evaluate cost function
LogLikeliL = lambda sol : - np.linalg.norm(image-phi.dir_op(sol))**2/(2*sigma**2)
LogLikeliL = lambda sol : - np.linalg.norm(image-id.dir_op(sol))**2/(2*sigma**2)

# Lambda function for L2-norm identity prior backprojection steps
proxH = lambda x, T : x - 2*T*psi.adj_op(psi.dir_op(x))*2*delta
proxH = lambda x, T : x - 2*T*id.adj_op(id.dir_op(x))*2*delta

# Lambda function for L2-ball likelihood projection during resampling
proxB = lambda x, tau: optimisations.l2_ball_proj.sopt_fast_proj_B2(x, tau, params)

# Select a starting position
X0 = np.abs(phi.adj_op(image))
X0 = np.abs(id.adj_op(image))

# Perform proximal nested sampling
NS_BayEvi, NS_Trace = sampling.proximal_nested.ProxNestedSampling(X0, LogLikeliL, proxH, proxB, params, options)
Expand Down
12 changes: 4 additions & 8 deletions ProxNest/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import numpy as np
from ProxNest.operators import sensing_operators as sense


def create_parameters_dict(
y=0,
Phi=sense.Identity(),
Psi=sense.Identity(),
Phi=None,
Psi=None,
epsilon=1e-3,
tight=True,
nu=1,
Expand All @@ -23,9 +19,9 @@ def create_parameters_dict(
Args:
y (np.ndarray): Measurements (default = 0).
Phi (linear operator): Sensing operator (default = sense.Identity).
Phi (linear operator): Sensing operator (default = None).
Psi (linear operator): Redundant dictionary (default = sense.Identity).
Psi (linear operator): Redundant dictionary (default = None).
epsilon (float): Radius of the :math:`\ell_2` ball (default = 1e-3).
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def read_file(file):
author_email="[email protected]",
license="GNU General Public License v3 (GPLv3)",
install_requires=required,
description="Proximal nested sampling for high-dimensional Bayesian inference",
description="Proximal nested sampling for high-dimensional Bayesian model selection",
long_description_content_type="text/x-rst",
long_description=long_description,
packages=["ProxNest"],
packages=["ProxNest", "ProxNest.operators", "ProxNest.optimisations", "ProxNest.sampling"],
)

0 comments on commit 97c23d7

Please sign in to comment.