Skip to content

Commit

Permalink
FIX: Missed some verbose spots
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored and agramfort committed Nov 5, 2012
1 parent a45e1a4 commit 0175d59
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 113 deletions.
7 changes: 3 additions & 4 deletions mne/fiff/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def make_dir_tree(fid, directory, start=0, indent=0, verbose=None):
else:
block = 0

logger.info(' ' * indent + 'start { %d' % block)
logger.debug(' ' * indent + 'start { %d' % block)

this = start

Expand Down Expand Up @@ -97,10 +97,9 @@ def make_dir_tree(fid, directory, start=0, indent=0, verbose=None):
if tree['nent'] == 0:
tree['directory'] = None

logger.info(' ' * (indent + 1) + 'block = %d nent = %d nchild = %d'
logger.debug(' ' * (indent + 1) + 'block = %d nent = %d nchild = %d'
% (tree['block'], tree['nent'], tree['nchild']))
logger.info(' ' * indent, 'end } %d' % block)

logger.debug(' ' * indent + 'end } %d' % block)
last = this
return tree, last

Expand Down
3 changes: 1 addition & 2 deletions mne/minimum_norm/inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,7 @@ def _prepare_forward(forward, info, noise_cov, pca=False, verbose=None):
if (c['ch_name'] not in info['bads'])
and (c['ch_name'] in fwd_ch_names)]
n_chan = len(ch_names)
if verbose:
logger.info("Computing inverse operator with %d channels." % n_chan)
logger.info("Computing inverse operator with %d channels." % n_chan)

#
# Handle noise cov
Expand Down
36 changes: 17 additions & 19 deletions mne/mixed_norm/inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
from ..forward import compute_orient_prior, is_fixed_orient
from ..fiff.pick import pick_channels_evoked
from .optim import mixed_norm_solver, norm_l2inf
from .. import verbose


@verbose
def _prepare_gain(gain, forward, whitener, depth, loose, weights, weights_min,
verbose=True):
if verbose:
logger.info('Whitening lead field matrix.')
verbose=None):
logger.info('Whitening lead field matrix.')
gain = np.dot(whitener, gain)

# Handle depth prior scaling
Expand Down Expand Up @@ -56,16 +57,15 @@ def _prepare_gain(gain, forward, whitener, depth, loose, weights, weights_min,
mask = (weights > weights_min)
gain = gain[:, mask]
n_sources = np.sum(mask) / n_dip_per_pos
if verbose:
logger.info("Reducing source space to %d sources" % n_sources)
logger.info("Reducing source space to %d sources" % n_sources)

return gain, source_weighting, mask


def _make_sparse_stc(X, active_set, forward, tmin, tstep, verbose=True):
@verbose
def _make_sparse_stc(X, active_set, forward, tmin, tstep, verbose=None):
if not is_fixed_orient(forward):
if verbose:
logger.info('combining the current components...')
logger.info('combining the current components...')
X = combine_xyz(X)

active_idx = np.where(active_set)[0]
Expand All @@ -84,10 +84,11 @@ def _make_sparse_stc(X, active_set, forward, tmin, tstep, verbose=True):
return stc


@verbose
def mixed_norm(evoked, forward, noise_cov, alpha, loose=0.2, depth=0.8,
maxit=3000, tol=1e-4, active_set_size=10, pca=True,
debias=True, time_pca=True, weights=None, weights_min=None,
return_residual=False, verbose=True):
return_residual=False, verbose=None):
"""Mixed-norm estimate (MxNE)
Compute L1/L2 mixed-norm solution on evoked data.
Expand Down Expand Up @@ -134,8 +135,8 @@ def mixed_norm(evoked, forward, noise_cov, alpha, loose=0.2, depth=0.8,
is less than weights_min.
return_residual : bool
If True, the residual is returned as an Evoked instance.
verbose : bool
Print status messages.
verbose : bool, str, int, or None
If not None, override default verbose level (see mne.verbose).
Returns
-------
Expand All @@ -159,15 +160,13 @@ def mixed_norm(evoked, forward, noise_cov, alpha, loose=0.2, depth=0.8,

# Whiten lead field.
gain, source_weighting, mask = _prepare_gain(gain, forward, whitener,
depth, loose, weights, weights_min,
verbose)
depth, loose, weights, weights_min)

sel = [all_ch_names.index(name) for name in ch_names]
M = np.concatenate([e.data[sel] for e in evoked], axis=1)

# Whiten data
if verbose:
logger.info('Whitening data matrix.')
logger.info('Whitening data matrix.')
M = np.dot(whitener, M)

if time_pca:
Expand All @@ -186,7 +185,7 @@ def mixed_norm(evoked, forward, noise_cov, alpha, loose=0.2, depth=0.8,
source_weighting *= alpha_max

X, active_set, E = mixed_norm_solver(M, gain, alpha,
maxit=maxit, tol=tol, verbose=True,
maxit=maxit, tol=tol,
active_set_size=active_set_size,
debias=debias,
n_orient=n_dip_per_pos)
Expand All @@ -213,7 +212,7 @@ def mixed_norm(evoked, forward, noise_cov, alpha, loose=0.2, depth=0.8,
tmin = float(e.first) / e.info['sfreq']
tstep = 1.0 / e.info['sfreq']
stc = _make_sparse_stc(X[:, cnt:(cnt + len(e.times))], active_set,
forward, tmin, tstep, verbose)
forward, tmin, tstep)
stcs.append(stc)

if return_residual:
Expand All @@ -223,8 +222,7 @@ def mixed_norm(evoked, forward, noise_cov, alpha, loose=0.2, depth=0.8,
r.data -= np.dot(forward['sol']['data'][sel, :][:, active_set], X)
residual.append(r)

if verbose:
logger.info('[done]')
logger.info('[done]')

if len(stcs) == 1:
out = stcs[0]
Expand Down
32 changes: 18 additions & 14 deletions mne/mixed_norm/optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import numpy as np
from scipy import linalg

import logging
logger = logging.getLogger('mne')

from .debiasing import compute_bias
from .. import verbose


def groups_norm2(A, n_orient):
Expand Down Expand Up @@ -153,7 +157,8 @@ def dgap_l21(M, G, X, active_set, alpha, n_orient):
return gap, pobj, dobj, R


def _mixed_norm_solver(M, G, alpha, maxit=200, tol=1e-8, verbose=True,
@verbose
def _mixed_norm_solver(M, G, alpha, maxit=200, tol=1e-8, verbose=None,
init=None, n_orient=1):
"""Solves L21 inverse solver"""
n_sensors, n_times = M.shape
Expand Down Expand Up @@ -207,17 +212,17 @@ def _mixed_norm_solver(M, G, alpha, maxit=200, tol=1e-8, verbose=True,
else:
R = GTM - np.dot(gram[:, Y_as], Y[Y_as])

if verbose: # log cost function value
gap, pobj, dobj, _ = dgap_l21(M, G, X, active_set, alpha, n_orient)
E.append(pobj)
print "pobj : %s -- gap : %s" % (pobj, gap)
if gap < tol:
print 'Convergence reached ! (gap: %s < %s)' % (gap, tol)
break
gap, pobj, dobj, _ = dgap_l21(M, G, X, active_set, alpha, n_orient)
E.append(pobj)
logger.debug("pobj : %s -- gap : %s" % (pobj, gap))
if gap < tol:
logger.debug('Convergence reached ! (gap: %s < %s)' % (gap, tol))
break
return X, active_set, E


def mixed_norm_solver(M, G, alpha, maxit=200, tol=1e-8, verbose=True,
@verbose
def mixed_norm_solver(M, G, alpha, maxit=200, tol=1e-8, verbose=None,
active_set_size=50, debias=True, n_orient=1):
"""Solves L21 inverse solver with active set strategy
Expand All @@ -237,8 +242,8 @@ def mixed_norm_solver(M, G, alpha, maxit=200, tol=1e-8, verbose=True,
The number of iterations
tol : float
Tolerance on dual gap for convergence checking
verbose : bool
Use verbose output
verbose : bool, str, int, or None
If not None, override default verbose level (see mne.verbose).
active_set_size : int
Size of active set increase at each iteration.
debias : bool
Expand Down Expand Up @@ -269,7 +274,7 @@ def mixed_norm_solver(M, G, alpha, maxit=200, tol=1e-8, verbose=True,
init = None
for k in xrange(maxit):
X, as_, E = _mixed_norm_solver(M, G[:, active_set], alpha,
maxit=maxit, tol=tol, verbose=False,
maxit=maxit, tol=tol,
init=init, n_orient=n_orient)
as_ = np.where(active_set)[0][as_]
gap, pobj, dobj, R = dgap_l21(M, G, X, as_, alpha, n_orient)
Expand Down Expand Up @@ -305,8 +310,7 @@ def mixed_norm_solver(M, G, alpha, maxit=200, tol=1e-8, verbose=True,
active_set[as_] = True
else:
X, active_set, E = _mixed_norm_solver(M, G, alpha, maxit=maxit,
tol=tol, verbose=verbose,
n_orient=n_orient)
tol=tol, n_orient=n_orient)

if (active_set.sum() > 0) and debias:
bias = compute_bias(M, G[:, active_set], X, n_orient=n_orient)
Expand Down
4 changes: 2 additions & 2 deletions mne/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def parallel_func(func, n_jobs, verbose=None):
try:
from joblib import Parallel, delayed
except ImportError:
logger.info("joblib not installed. Cannot run in parallel.")
logger.warn("joblib not installed. Cannot run in parallel.")
n_jobs = 1
my_func = func
parallel = list
Expand All @@ -57,7 +57,7 @@ def parallel_func(func, n_jobs, verbose=None):
import multiprocessing
n_jobs = multiprocessing.cpu_count()
except ImportError:
logger.info('multiprocessing not installed. Cannot run in '
logger.warn('multiprocessing not installed. Cannot run in '
'parallel.')
n_jobs = 1

Expand Down
Loading

0 comments on commit 0175d59

Please sign in to comment.