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

[RELEASE] v2.0.2 #128

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
84c820f
Proposed fix
daducci Nov 17, 2023
558d333
Reorder parameters
daducci Dec 1, 2023
49c09bc
Removed unused statement
daducci Dec 1, 2023
3eb5729
Commented unused norms
daducci Dec 1, 2023
7d85634
Commented unused norms
daducci Dec 1, 2023
08077b3
Commented unused norms
daducci Dec 1, 2023
3e93727
Added scaling parameter to prox (to account,possibly, for step_size)
daducci Dec 1, 2023
8ab7ad8
Increased version
daducci Dec 1, 2023
d82c781
Removed unused returns in proximal operators
daducci Dec 1, 2023
4aa2dbb
Considered step_size also in group sparsity prox
daducci Dec 1, 2023
733598b
Added scaling parameter to overall prox function
daducci Dec 4, 2023
49bc9ab
Replaced sum with l1 norm to consider possible cases with negative x …
daducci Dec 4, 2023
89c65c9
Added explicitly 'None' as possible regularization norm
daducci Dec 4, 2023
18f6920
Separated non_negativity from the regularizers
daducci Dec 4, 2023
05695bf
Fixed segmentation fault
daducci Dec 4, 2023
7c5c98e
Removed group_norm option
daducci Dec 4, 2023
e7af30e
Removed group_norm option
daducci Dec 4, 2023
b7504a1
Renamed parameters for clarity
daducci Dec 4, 2023
829f06b
Renamed parameters for clarity
daducci Dec 4, 2023
280f327
Renamed parameters for clarity
daducci Dec 4, 2023
7eee16a
refactor: 'operator' module reload
nightwnvol Dec 5, 2023
2de6b82
chore: don't write 'operator.pyc' in __pycache__
nightwnvol Dec 5, 2023
34e5aa0
build: bump to v2.0.2
nightwnvol Dec 5, 2023
4edc2f2
Merge pull request #127 from daducci/bug_build_operator
nightwnvol Dec 6, 2023
103c60d
Merge pull request #129 from daducci/fix_fista_update
nightwnvol Dec 6, 2023
9b1dbfe
docs: update CHANGELOG.md
nightwnvol Dec 6, 2023
e8b6139
Fixed if condition for reg_EC and removed unused parameter in group s…
fullbat Dec 6, 2023
e1e1b14
fix: import indentation
nightwnvol Dec 12, 2023
73edf29
Removed authorship statements for uniformity, contributors are acknow…
daducci Dec 12, 2023
621ceeb
Removed 'from __future__ import print_function' statements
daducci Dec 12, 2023
3b94d7c
Remove unused Version: ImageMagick 7.1.1-22 Q16-HDRI aarch64 21779 ht…
daducci Dec 12, 2023
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Change Log
### All notable changes to `COMMIT` will be documented in this file.

## `v2.0.2`<br>_2023-12-06_
### 🐛Fixed
- Merged PR [#127](https://github.com/daducci/COMMIT/pull/127): [FIX] Operator is not recompiled when some parameters are changed
- Merged PR [#129](https://github.com/daducci/COMMIT/pull/129): [FIX] Fista update

---
---

## `v2.0.1`<br>_2023-10-31_
### 🛠️Changed
- Bump dependencies
Expand Down
16 changes: 8 additions & 8 deletions commit/core.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!python
#cython: language_level=3, boundscheck=False, wraparound=False, nonecheck=False, cdivision=True, initializedcheck=False, binding=False
from __future__ import print_function
cimport cython
import numpy as np
cimport numpy as np
Expand All @@ -16,6 +15,7 @@ import commit.models
import commit.solvers
import amico.scheme
import amico.lut
from importlib import reload, invalidate_caches
import pyximport
from pkg_resources import get_distribution

Expand Down Expand Up @@ -170,7 +170,7 @@ cdef class Evaluation :
ERROR( 'Scheme does not match with input data' )
if self.scheme.dwi_count == 0 :
ERROR( 'There are no DWI volumes in the data' )

# Check for Nan or Inf values in raw data
if np.isnan(self.niiDWI_img).any() or np.isinf(self.niiDWI_img).any():
if replace_bad_voxels is not None:
Expand Down Expand Up @@ -728,14 +728,14 @@ cdef class Evaluation :
config.nISO = self.KERNELS['iso'].shape[0]
config.build_dir = build_dir

sys.dont_write_bytecode = True
pyximport.install( reload_support=True, language_level=3, build_dir=build_dir, build_in_temp=True, inplace=False )

if not 'commit.operator.operator' in sys.modules :
import commit.operator.operator
else :
reload( sys.modules['commit.operator.operator'] )
if 'commit.operator.operator' in sys.modules :
del sys.modules['commit.operator.operator']
import commit.operator.operator

self.A = sys.modules['commit.operator.operator'].LinearOperator( self.DICTIONARY, self.KERNELS, self.THREADS )
self.A = commit.operator.operator.LinearOperator( self.DICTIONARY, self.KERNELS, self.THREADS )

LOG( ' [ %.1f seconds ]' % ( time.time() - tic ) )

Expand Down Expand Up @@ -1127,7 +1127,7 @@ cdef class Evaluation :
temp_weights[temp_weights>0] = xic[self.DICTIONARY['TRK']['kept']>0]
unravel_weights[ordered_idx] = temp_weights
xic = unravel_weights

else:
if dictionary_info['blur_gauss_extent'] > 0 or dictionary_info['blur_core_extent'] > 0:
xic[ self.DICTIONARY['TRK']['kept']==1 ] *= self.DICTIONARY['TRK']['lenTot'] / self.DICTIONARY['TRK']['len']
Expand Down
2 changes: 1 addition & 1 deletion commit/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Format version as expected by setup.py (string of form "X.Y.Z")
_version_major = 2
_version_minor = 0
_version_micro = 1
_version_micro = 2
_version_extra = '' #'.dev'
__version__ = "%s.%s.%s%s" % (_version_major,_version_minor,_version_micro,_version_extra)

Expand Down
93 changes: 35 additions & 58 deletions commit/proximals.pyx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!python
#cython: language_level=3, boundscheck=False, wraparound=False, profile=False
"""
Author: Matteo Frigo - lts5 @ EPFL and Dep. of CS @ Univ. of Verona

This structure is based on the previous work of Rafael Carrillo and was
supported by the LTS5 laboratory at EPFL, Lausanne.
"""
cimport cython
import numpy as np
cimport numpy as np
Expand All @@ -32,10 +26,16 @@ cpdef soft_thresholding(double [::1] x, double lam, int compartment_start, int c
cdef:
int i
for i in xrange(compartment_start, compartment_start+compartment_size):
if x[i] <= lam:
x[i] = 0.0
else:
# if x[i] <= lam:
# x[i] = 0.0
# else:
# x[i] = x[i] - lam
if x[i] > lam:
x[i] = x[i] - lam
elif x[i] < -lam:
x[i] = x[i] + lam
else:
x[i] = 0.0
return np.asarray( x )


Expand All @@ -60,7 +60,7 @@ cpdef projection_onto_l2_ball(double [::1] x, double lam, int compartment_start,
return np.asarray( x )


cpdef omega_group_sparsity(double [::1] x, int [::1] group_idx, int [::1] group_size, double [::1] group_weight, double lam, double n) :
cpdef omega_group_sparsity(double [::1] x, int [::1] group_idx, int [::1] group_size, double [::1] group_weight, double lam) :
"""
References:
[1] Jenatton et al. - `Proximal Methods for Hierarchical Sparse Coding`
Expand All @@ -71,29 +71,18 @@ cpdef omega_group_sparsity(double [::1] x, int [::1] group_idx, int [::1] group_
double omega = 0.0, gNorm, x_i

if lam != 0:
if n == 2:
for k in xrange(nG):
N = group_size[k]
gNorm = 0.0
for i in xrange(j,j+N) :
x_i = x[group_idx[i]]
gNorm += x_i*x_i
omega += group_weight[k] * sqrt( gNorm )
j += N
elif n == np.inf:
for k in xrange(nG):
N = group_size[k]
gNorm = x[group_idx[j]]
for i in xrange(j+1,j+N) :
x_i = x[group_idx[i]]
if x_i > gNorm :
gNorm = x_i
omega += group_weight[k] * gNorm
j += N
for k in xrange(nG):
N = group_size[k]
gNorm = 0.0
for i in xrange(j,j+N) :
x_i = x[group_idx[i]]
gNorm += x_i*x_i
omega += group_weight[k] * sqrt( gNorm )
j += N
return lam*omega


cpdef prox_group_sparsity( double [::1] x, int [::1] group_idx, int [::1] group_size, double [::1] group_weight, double lam, double n ) :
cpdef prox_group_sparsity( double [::1] x, int [::1] group_idx, int [::1] group_size, double [::1] group_weight, double lam) :
"""
References:
[1] Jenatton et al. - `Proximal Methods for Hierarchical Sparse Coding`
Expand All @@ -109,33 +98,21 @@ cpdef prox_group_sparsity( double [::1] x, int [::1] group_idx, int [::1] group_
x[i] = 0.0

if lam != 0:
if n == 2 :
for k in xrange(nG) :
N = group_size[k]
gNorm = 0.0
for i in xrange(j,j+N) :
x_i = x[group_idx[i]]
gNorm += x_i*x_i
gNorm = sqrt( gNorm )
for k in xrange(nG) :
N = group_size[k]
gNorm = 0.0
for i in xrange(j,j+N) :
x_i = x[group_idx[i]]
gNorm += x_i*x_i
gNorm = sqrt( gNorm )

wl = group_weight[k] * lam
if gNorm <= wl :
for i in xrange(j,j+N) :
x[ group_idx[i] ] = 0.0
else :
wl = (gNorm-wl)/gNorm
for i in xrange(j,j+N) :
x[ group_idx[i] ] *= wl
j += N
# elif n == np.inf :
# [TODO] TO be correctly implemented
# for k in range(nG) :
# idx = subtree[k]
# # xn = max( v[idx] )
# r = weight[k] * lam
# for i in idx :
# if v[i] <= r:
# v[i] = 0.0
# else :
# v[i] -= r
wl = group_weight[k] * lam
if gNorm <= wl :
for i in xrange(j,j+N) :
x[ group_idx[i] ] = 0.0
else :
wl = (gNorm-wl)/gNorm
for i in xrange(j,j+N) :
x[ group_idx[i] ] *= wl
j += N
return np.asarray( x )
Loading