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

[DOC] Update docstring for fixed_seed to ref None option #104

Merged
merged 3 commits into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions tedana/decomposition/eigendecomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ def tedica(n_components, dd, conv, fixed_seed, cost, final_cost,
conv : :obj:`float`
Convergence limit for ICA
fixed_seed : :obj:`int`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:obj:int or :obj:None

Seed for ensuring reproducibility of ICA results
Value passed to ``mdp.numx_rand.seed()``.
Set to an integer value for reproducible ICA results;
otherwise, set to -1 for varying results across calls.
cost : {'tanh', 'pow3', 'gaus', 'skew'}
Initial cost function for ICA.
final_cost : {'tanh', 'pow3', 'gaus', 'skew'}
Expand All @@ -281,6 +283,8 @@ def tedica(n_components, dd, conv, fixed_seed, cost, final_cost,

import mdp
climit = float(conv)
if fixed_seed == -1:
fixed_seed = np.random.randint(low=1, high=1000)
mdp.numx_rand.seed(fixed_seed)
icanode = mdp.nodes.FastICANode(white_comp=n_components, approach='symm',
g=cost, fine_g=final_cost,
Expand All @@ -290,4 +294,4 @@ def tedica(n_components, dd, conv, fixed_seed, cost, final_cost,
smaps = icanode.execute(dd) # noqa
mmix = icanode.get_recmatrix().T
mmix = stats.zscore(mmix, axis=0)
return mmix
return mmix, fixed_seed
16 changes: 12 additions & 4 deletions tedana/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def writefeats(data, mmix, mask, ref_img, suffix=''):
return fname


def writect(comptable, n_vols, acc, rej, midk, empty, ctname='comp_table.txt',
def writect(comptable, n_vols, fixed_seed, acc, rej, midk, empty, ctname='comp_table.txt',
varexpl='-1'):
"""
Saves component table to disk
Expand All @@ -277,6 +277,8 @@ def writect(comptable, n_vols, acc, rej, midk, empty, ctname='comp_table.txt',
component, and (5) normalized variance explained by component
n_vols : :obj:`int`
Number of volumes in original time series
fixed_seed : :obj:`int`
Integer value used in seeding ICA
acc : :obj:`list`
Indices of accepted (BOLD) components in `mmix`
rej : :obj:`list`
Expand Down Expand Up @@ -321,6 +323,7 @@ def writect(comptable, n_vols, acc, rej, midk, empty, ctname='comp_table.txt',

_computed_vars = dict(file=op.abspath(op.curdir),
vex=varexpl,
seed=fixed_seed,
n_components=n_components,
dfe=len(acc),
rjn=len(midk) + len(rej),
Expand All @@ -332,6 +335,7 @@ def writect(comptable, n_vols, acc, rej, midk, empty, ctname='comp_table.txt',
heading = textwrap.dedent("""\
# ME-ICA Component statistics table for: {file} #
# Dataset variance explained by ICA (VEx): {vex:.2f}
# Integer value used in seeding ICA: {seed}
# Total components generated by decomposition (TCo): {n_components}
# No. accepted BOLD-like components, i.e. effective degrees
of freedom for correlation (lower bound; DFe): {dfe}
Expand All @@ -355,8 +359,8 @@ def writect(comptable, n_vols, acc, rej, midk, empty, ctname='comp_table.txt',
sortab[i, 4]))


def writeresults(ts, mask, comptable, mmix, n_vols, acc, rej, midk, empty,
ref_img):
def writeresults(ts, mask, comptable, mmix, n_vols, fixed_seed,
acc, rej, midk, empty, ref_img):
"""
Denoises `ts` and saves all resulting files to disk

Expand All @@ -373,6 +377,10 @@ def writeresults(ts, mask, comptable, mmix, n_vols, acc, rej, midk, empty,
mmix : (C x T) array_like
Mixing matrix for converting input data to component space, where `C`
is components and `T` is the same as in `data`
n_vols : :obj:`int`
Number of volumes in original time series
fixed_seed: :obj:`int`
Integer value used in seeding ICA
acc : :obj:`list`
Indices of accepted (BOLD) components in `mmix`
rej : :obj:`list`
Expand Down Expand Up @@ -425,7 +433,7 @@ def writeresults(ts, mask, comptable, mmix, n_vols, acc, rej, midk, empty,
mmix[:, acc], mask, ref_img, suffix='OC2')
LGR.info('Writing Z-normalized spatial component maps: {}'.format(op.abspath(fout)))

writect(comptable, n_vols, acc, rej, midk, empty, ctname='comp_table.txt',
writect(comptable, n_vols, fixed_seed, acc, rej, midk, empty, ctname='comp_table.txt',
varexpl=varexpl)
LGR.info('Writing component table: {}'.format(op.abspath('comp_table.txt')))

Expand Down
18 changes: 11 additions & 7 deletions tedana/workflows/tedana.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ def _get_parser():
parser.add_argument('--seed',
dest='fixed_seed',
type=int,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break with None. Also (and this might not matter to anyone), but typing --fixed_seed None is a little awkward. I think I've seen something like --fixed_seed -1 which would then be coerced to None later.

help='Seeded value for ICA, for reproducibility.',
help=('Value passed to repr(mdp.numx_rand.seed()) '
'Set to an integer value for reproducible ICA results; '
'otherwise, set to -1 for varying results across calls.'),
default=42)
parser.add_argument('--debug',
dest='debug',
Expand Down Expand Up @@ -228,7 +230,9 @@ def tedana_workflow(data, tes, mixm=None, ctab=None, manacc=None, strict=False,
Other Parameters
----------------
fixed_seed : :obj:`int`, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:obj:int or :obj:None, I think.

Seeded value for ICA, for reproducibility.
Value passed to ``mdp.numx_rand.seed()``.
Set to a positive integer value for reproducible ICA results;
otherwise, set to -1 for varying results across calls.
debug : :obj:`bool`, optional
Whether to run in debugging mode or not. Default is False.
quiet : :obj:`bool`, optional
Expand Down Expand Up @@ -388,9 +392,9 @@ def tedana_workflow(data, tes, mixm=None, ctab=None, manacc=None, strict=False,
t2s, t2sG, stabilize, ref_img,
tes=tes, kdaw=kdaw, rdaw=rdaw,
ste=ste, wvpca=wvpca)
mmix_orig = decomposition.tedica(n_components, dd, conv, fixed_seed,
cost=initcost, final_cost=finalcost,
verbose=debug)
mmix_orig, fixed_seed = decomposition.tedica(n_components, dd, conv, fixed_seed,
cost=initcost, final_cost=finalcost,
verbose=debug)
np.savetxt(op.join(out_dir, '__meica_mix.1D'), mmix_orig)
LGR.info('Making second component selection guess from ICA results')
seldict, comptable, betas, mmix = model.fitmodels_direct(catd, mmix_orig,
Expand Down Expand Up @@ -425,8 +429,8 @@ def tedana_workflow(data, tes, mixm=None, ctab=None, manacc=None, strict=False,
LGR.warning('No BOLD components detected! Please check data and '
'results!')

utils.writeresults(OCcatd, mask, comptable, mmix, n_vols, acc, rej, midk,
empty, ref_img)
utils.writeresults(OCcatd, mask, comptable, mmix, fixed_seed, n_vols,
acc, rej, midk, empty, ref_img)
utils.gscontrol_mmix(OCcatd, mmix, mask, acc, ref_img)
if dne:
utils.writeresults_echoes(catd, mmix, mask, acc, rej, midk, ref_img)
Expand Down