Back to the main page.

Bug 1205 - implement cfg.seed input to ft_componentanalysis

Status CLOSED FIXED
Reported 2011-11-30 14:39:00 +0100
Modified 2012-01-11 14:28:02 +0100
Product: FieldTrip
Component: core
Version: unspecified
Hardware: All
Operating System: All
Importance: P3 enhancement
Assigned to: Johanna
URL:
Tags:
Depends on:
Blocks:
See also:

Johanna - 2011-11-30 14:39:42 +0100

(may be a better name than 'seed' to indicate the matlab randomization seed). Purpose: so that one may obtain the same component output in different calls to the function. Does it need to be different per type of cfg.method, or is one general one sufficient? Also, save out the rand seed to comp.cfg for future use.


Robert Oostenveld - 2011-11-30 17:50:45 +0100

there is something like this already in manzana> grep randomseed *.m statistics_montecarlo.m:% cfg.randomseed = 'yes', 'no' or a number (default = 'yes') statistics_montecarlo.m:if ~isfield(cfg, 'randomseed'), cfg.randomseed = 'yes'; end statistics_montecarlo.m:if strcmp(cfg.randomseed, 'no') statistics_montecarlo.m:elseif strcmp(cfg.randomseed, 'yes') statistics_montecarlo.m: rand('state',cfg.randomseed);


Robert Oostenveld - 2011-11-30 18:00:07 +0100

have a look at 2011b (the latest) http://www.mathworks.nl/help/techdoc/math/bsn94u0-1.html and please note that "rng" does not exist in 2009b, but that in that version rand('seed',x) was also deprecated. There you are supposed to use RandStream. So overall it is a mess, with the old rand('seed'), the intermediate RandStream and the new Rng. I guess nobody understood the RandStream (at least I don't get it as I am not a random numbers expert), and that therefore they added the Rng layer on top of it. Please make sure that you properly test it on all matlab versions that we have at the donders (at from 7.1 upwards). I can imagine it to be easier to make a fieldtrip/private/randomseed function that contains the actual logic depending on the matlab version.


Boris Reuderink - 2011-12-01 22:12:11 +0100

Issued by developer, changed status to new. Johanna, I have assigned this bug to you --- I hope you don't mind.


Robert Oostenveld - 2011-12-14 14:00:27 +0100

recording the state in cfg.callinfo.state and setting the seed should be tightly linked to each other -> solution is to implement ft_preamble_randomseed


Johanna - 2011-12-14 18:26:15 +0100

bash-3.2$ svn commit private/randomseed.m test/test_randomseed.m Adding private/randomseed.m Adding test/test_randomseed.m Transmitting file data .. Committed revision 5044. and then added a copy: bash-3.2$ svn copy private/randomseed.m test/private/randomseed.m A test/private/randomseed.m bash-3.2$ svn commit test/private/randomseed.m Adding test/private/randomseed.m Committed revision 5045. and it needed matlabversion bash-3.2$ svn copy private/matlabversion.m test/private/matlabversion.m A test/private/matlabversion.m bash-3.2$ svn commit test/private/matlabversion.m Adding test/private/matlabversion.m Committed revision 5046. Next step to work on ft_preamble_randomseed.


Johanna - 2011-12-14 19:11:41 +0100

bash-3.2$ svn mv private/randomseed.m utilities/private/randomseed.m A utilities/private/randomseed.m D private/randomseed.m bash-3.2$ svn cp private/matlabversion.m utilities/private/matlabversion.m A utilities/private/matlabversion.m bash-3.2$ svn commit utilities/private/matlabversion.m utilities/private/randomseed.m Adding utilities/private/matlabversion.m Adding utilities/private/randomseed.m Committed revision 5048.


Johanna - 2011-12-14 19:34:33 +0100

Hi Robert, I've created ft_preamble_randseed (not yet committed) which contains these lines: cfg.randomseed=ft_getopt(cfg, 'randomseed', []); cfg.callinfo.state=randomseed(cfg.randomseed); I've tested it so far on cfg.method='fastica' and it works (random output when [], and it reproduces results identically when cfg.randomseed set to state of previous call). Is it ok to set cfg.callinfo.state early on in the high-level function in the preamble like this? (I ask because the other 'amble' functions only save out to the cfg in the 'post' not 'pre').


Robert Oostenveld - 2011-12-15 12:20:01 +0100

(In reply to comment #7) I think it is more consistent to have ft_postamble_callinfo add it to the output cfg and there do something like if exist('ftFuncRandomseed', 'var') cfg.callinfo.randomseed = ftFuncRandomseed; end and have ftFuncRandomseed be created in ft_preamble_randomseed


Johanna - 2011-12-16 12:56:17 +0100

bash-3.2$ svn commit utilities/private/ft_preamble_randomseed.m utilities/private/ft_postamble_randomseed.m ft_componentanalysis.m test/private/randomseed.m Sending ft_componentanalysis.m Replacing test/private/randomseed.m Adding utilities/private/ft_postamble_randomseed.m Adding utilities/private/ft_preamble_randomseed.m Transmitting file data ... Committed revision 5051.