Skip to content

Commit

Permalink
fixing a test and some docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
shailesh1729 committed Oct 17, 2023
1 parent 7539eb9 commit d4dc60c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.

[Documentation](https://cr-sparse.readthedocs.io/en/latest/)

## [0.4.0] - 2023-10-16
## [0.4.0] - 2023-10-17

[Documentation](https://cr-sparse.readthedocs.io/en/v0.4.0/)

Expand Down
6 changes: 3 additions & 3 deletions src/cr/sparse/_src/cvx/adm/yall1.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def finalize(state, b_max, n_times, n_trans, W=None, nonneg=False):
n_trans=state.n_trans+n_trans)

def solve_bp(A, b, x0, z0, w, nonneg, gamma, tolerance, max_iters):
"""
r"""
Solves the problem :math:`\min \| x \|_1 \, \\text{s.t.}\, A x = b` using ADMM
This function implements eq 2.29 of the paper.
Expand Down Expand Up @@ -202,7 +202,7 @@ def cond(state):


def solve_l1_l2(A, b, x0, z0, w, nonneg, rho, gamma, tolerance, max_iters):
"""
r"""
Solves the problem :math:`\min \| x \|_1 + \\frac{1}{2 \\rho} \| A x - b \|_2^2` using ADMM
This function implements eq 2.25 of the paper.
Expand Down Expand Up @@ -328,7 +328,7 @@ def cond(state):


def solve_l1_l2con(A, b, x0, z0, w, nonneg, delta, gamma, tolerance, max_iters):
"""
r"""
Solves the problem :math:`\min \| x \|_1 \\text{s.t.} \| A x - b \|_2 \\leq \\delta` using ADMM
This function implements eq 2.27 of the paper.
Expand Down
6 changes: 3 additions & 3 deletions src/cr/sparse/_src/cvx/l1ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class State(NamedTuple):

def solve_from(A, y, lambda_, x0, u0, tol=1e-3, xi=1e-3, t0=None,
max_iters=MAX_ITERS, pcg_max_iters=PCG_MAX_ITERS):
"""
r"""
Solves :math:`\min \| A x - b \|_2^2 + \\lambda \| x \|_1` using the Truncated Newton Interior Point Method
"""
trans = A.trans
Expand Down Expand Up @@ -234,7 +234,7 @@ def hessian(x):
p3 = prb / prs

def preconditioner(x):
"""Computes the inverse y = M \ x where M is the preconditioner operator"""
r"""Computes the inverse y = M \ x where M is the preconditioner operator"""
x1 = x[:n]
x2 = x[n:]
upper = p1 * x1 - p2 * x2
Expand Down Expand Up @@ -371,7 +371,7 @@ def cond(state):

def solve(A, y, lambda_, x0=None, u0=None, tol=1e-3, xi=1e-3, t0=None,
max_iters=MAX_ITERS, pcg_max_iters=PCG_MAX_ITERS):
"""
r"""
Solves :math:`\min \| A x - b \|_2^2 + \\lambda \| x \|_1` using the Truncated Newton Interior Point Method
"""
m, n = A.shape
Expand Down
2 changes: 1 addition & 1 deletion src/cr/sparse/_src/opt/projectors/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def projector(x):
y = box_bound(x - beta * a)

def proj_conic():
"""Projector function for Lorentz/ice-cream cone {(x,t): \| x \|_2 \leq t}
r"""Projector function for Lorentz/ice-cream cone {(x,t): \| x \|_2 \leq t}
"""
@jit
def proj(x):
Expand Down
2 changes: 1 addition & 1 deletion src/cr/sparse/_src/opt/proximal_ops/lpnorms.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def proximal_op(x, t):
return build(func, proximal_op)

def prox_l1_ball(q=1.):
"""Returns a prox-capable wrapper for the l1-ball :math:`\{ x : \| x \|_1 \leq q \}` indicator
r"""Returns a prox-capable wrapper for the l1-ball :math:`\{ x : \| x \|_1 \leq q \}` indicator
Returns:
ProxCapable: A prox-capable function
Expand Down
2 changes: 1 addition & 1 deletion src/cr/sparse/_src/pursuit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def largest_indices(h, K):


def gram_chol_update(L, v):
"""Incrementally updates the Cholesky factorization :math:`G = L L^T` where :math:`G = \Phi^T \Phi`
r"""Incrementally updates the Cholesky factorization :math:`G = L L^T` where :math:`G = \Phi^T \Phi`
"""
m, n = L.shape
z = jnp.zeros((m, 1))
Expand Down
6 changes: 4 additions & 2 deletions tests/cluster/test_spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ def test_spectral6():
affinity = jnp.vstack((az, za))
print(affinity)
true_labels = cluster.labels_from_sizes(jnp.array([m, m]))
print("True Labels: ", true_labels)
affinity = BCOO.fromdense(affinity)
k = 2
res = spectral.normalized_symmetric_sparse_fast_k_jit(cnb.KEYS[1], affinity, k)
res = spectral.normalized_symmetric_sparse_fast_k_jit(cnb.KEYS[2], affinity, k)
pred_labels = res.assignment
print("Predicted Labels: ", pred_labels)
error = cluster.clustering_error(true_labels, pred_labels)
assert error.error == 0
assert_almost_equal(error.error, 0)

0 comments on commit d4dc60c

Please sign in to comment.