Skip to content

Commit

Permalink
Merge pull request #939 from flatironinstitute/dev
Browse files Browse the repository at this point in the history
Merge dev -> master for release
  • Loading branch information
pgunn authored Dec 2, 2021
2 parents 4c2a683 + 553389e commit 70e6451
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 5 additions & 1 deletion caiman/source_extraction/cnmf/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import scipy.sparse as spr
from skimage.morphology import disk
from sklearn.decomposition import NMF, FastICA
from sklearn.exceptions import ConvergenceWarning
from sklearn.utils.extmath import randomized_svd, squared_norm, randomized_range_finder
import sys
from typing import List
import warnings

import caiman
from .deconvolution import constrained_foopsi
Expand All @@ -47,6 +49,8 @@
except:
pass

warnings.filterwarnings(action='ignore', category=ConvergenceWarning)

def resize(Y, size, interpolation=cv2.INTER_LINEAR):
"""faster and 3D compatible version of skimage.transform.resize"""
if Y.ndim == 2:
Expand Down Expand Up @@ -1274,7 +1278,7 @@ def compute_B(b0, W, B): # actually computes -B to efficiently compute Y-B in p
for i in range(init_iter - 1):
if max_number is not None:
max_number -= A.shape[-1]
if max_number is not 0:
if max_number != 0:
if i == init_iter-2 and seed_method.lower()[:4] == 'semi':
seed_method, min_corr, min_pnr = 'manual', 0, 0
logging.info('Searching for more neurons in the residual')
Expand Down
24 changes: 13 additions & 11 deletions caiman/source_extraction/cnmf/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from scipy.ndimage.morphology import generate_binary_structure, iterate_structure
import shutil
from sklearn.decomposition import NMF
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
import tempfile
import time
import psutil
Expand Down Expand Up @@ -405,13 +407,12 @@ def regression_ipyparallel(pars):
elif method_least_square == 'lasso_lars': # lasso lars function from scikit learn
lambda_lasso = 0 if np.size(cct_) == 0 else \
.5 * noise_sn[px] * np.sqrt(np.max(cct_)) / T
clf = linear_model.LassoLars(alpha=lambda_lasso, positive=True,
fit_intercept=True)
# clf = linear_model.Lasso(alpha=lambda_lasso, positive=True,
# fit_intercept=True, normalize=True,
# selection='random')
a_lrs = clf.fit(np.array(c.T), np.ravel(y))
a = a_lrs.coef_
model = make_pipeline(
StandardScaler(with_mean=False),
linear_model.LassoLars(alpha=lambda_lasso, positive=True,
fit_intercept=True, normalize=False)
)
a = model.fit(np.array(c.T), np.ravel(y))['lassolars'].coef_

else:
raise Exception(
Expand Down Expand Up @@ -1055,14 +1056,15 @@ def computing_indicator(Y, A_in, b, C, f, nb, method, dims, min_size, max_size,
dist_indicator_av = old_div(dist_indicator.astype(
'float32'), np.sum(dist_indicator.astype('float32'), axis=0))
px = (np.sum(dist_indicator, axis=1) > 0)
not_px = 1 - px
not_px = ~px
if Y.shape[-1] < 30000:
f = Y[not_px, :].mean(0)
else: # memory mapping fails here for some reasons
else:
print('estimating f')
f = 0
for xxx in not_px:
f = (f + Y[xxx]) / 2
for xxx in np.where(not_px)[0]:
f += Y[xxx]
f /= not_px.sum()

f = np.atleast_2d(f)

Expand Down

0 comments on commit 70e6451

Please sign in to comment.