Skip to content
Open
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions src/dspeed/processors/nnls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

@guvectorize(
[
"void(float32[:,::1], float32[::1], float32, float32, boolean, float32, float32[::1])",
"void(float64[:,::1], float64[::1], float64, float32, boolean, float32, float64[::1])",
"void(float32[:,::1], float32[::1], float32, float32, boolean, float32, float32, float32[::1])",
"void(float64[:,::1], float64[::1], float64, float32, boolean, float32, float32, float64[::1])",
],
"(m,n),(m),(),(),(),(),(n)",
"(m,n),(m),(),(),(),(),(),(n)",
nopython=True,
**nb_kwargs,
)
Expand All @@ -23,6 +23,7 @@ def optimize_nnls(
tol: float,
allow_singularity: bool,
min_value: float,
lmb: float,
x: np.ndarray,
) -> None:
"""Solve ``argmin_x || ax - b ||_2`` for ``x>=0``.
Expand All @@ -45,6 +46,10 @@ def optimize_nnls(
If matrix is not solvable (e.g. because of non full rank caused by
float precision), no error is raised but all elements of the
solution vector are set NaN
min_value: float
Threshold for noise reduction
lmb : float
L1 penalty to enforce sparsity in the solution.
x : ndarray
Solution vector.

Expand All @@ -58,7 +63,7 @@ def optimize_nnls(
"module": "dspeed.processors",
"args": ["db.coefficient_matrix",
"wf_blsub",
"1000", "1e-6", "True"
"1000", "1e-6", "True", 0.3, 3e4,
"nnls_solution"],
}
"""
Expand Down Expand Up @@ -100,7 +105,7 @@ def is_singular(matrix):
)

ata = np.transpose(a) @ a
atb = b @ a # Result is 1D - let NumPy figure it out
atb = b @ a - lmb # Result is 1D - let NumPy figure it out

# Initialize vars
x[:] = np.zeros(n, dtype=np.float64)
Expand Down