Prev: Single number into vector elements
Next: neural network
From: Alan Chalker on 10 May 2010 00:05 "Jan" <thisis(a)notanemail.com> wrote in message <hs3qch$j13$1(a)fred.mathworks.com>... > > I had a runtime problem (can't restrict execution time within Matlab) with function lsqr() in submission pushy2 (http://www.mathworks.com/matlabcentral/contest/contests/2/submissions/777). It runs forever on my machine. This brings up an interesting question I've always wondered about. How does the contest machinery do this? Would anyone from the MATLAB team be willing to share the details?
From: Alan Chalker on 10 May 2010 00:23 I spent some time this weekend developing several robust 'helper' functions to help with the commenting tasks we are discussing. As a test, I wrote a small 'module' that inserted a comment into an entry describing what phase of the contest the entry was submitted in. I'm running it through the entire test suite right now as a test (the comment submission process is surprisingly slow), and I thought I'd present the details here so if anyone else wants to create any 'modules' for me to run they can. The function code is as follows: ------------------------------------------------------------------------------------- function comment=phasecomment(id) % Given an input entry id, this function determines what contest phase it was in % and provides an appropriate comment % Index cell array of phase start and end times phases={[2010 04 28 16 00 00] [2010 04 29 16 00 00] 'Darkness'; ... [2010 04 29 16 00 01] [2010 04 30 16 00 00] 'Twilight'; ... [2010 04 30 16 00 01] [2010 05 05 16 00 00] 'Daylight'; ... [2010 04 30 16 00 01] [2010 04 30 21 00 00] 'Friday Early Bird'; ... [2010 05 01 00 00 00] [2010 05 01 23 59 59] 'Saturday Leap'; ... [2010 05 02 00 00 00] [2010 05 02 23 59 59] 'Sunday Push'; ... [2010 05 03 18 00 01] [2010 05 03 22 00 00] 'Monday K-Note'; ... [2010 05 04 00 00 00] [2010 05 04 23 59 59] 'Tuesday Longevity'}; % Returns all the data for an entry entry=grabentry(id); if strcmp(entry.status,'Passed') entrytime=datenum(entry.submitted); entryphases=phases(cellfun(@(x) entrytime>=datenum(x),phases(:,1)) ... & cellfun(@(x) entrytime<=datenum(x),phases(:,2)),3); comment=['This entry was submitted during the ' entryphases{1} ' phase']; if numel(entryphases) > 1 comment=[comment ' and was eligible for the ' entryphases{2} ' prize']; end else comment=''; end ------------------------------------------------------------------------------------- The key item is the 'grabentry(id)' function, which does exactly what it sounds like. It returns a structure with all the data for a specific entry as follows: All fields are numeric unless otherwise specified id - the same as the entry id author - the entry author (string) name - the title of the entry (string) status - 'Passed' or 'Failed' (string) results - the numerical results cyc - the Cyclomatic Complexity node - the node length cpu - the CPU time score - the score submitted - the submitted time as a date vector scored - the scored time as a date vector currank - the current rank highrank - the highest rank basedon - the id of the entry it is based on basisfor - a vector of ids of entries based on it error - the error message if status == Failed (string) code - the code (string) comments - all comments as a 3 col cell array {author, date, comment} Note the function outputs a single string that is the comment to insert. Note the comment field is currently limited to 1000 chars and if you want to insert newlines you need to use the following to place them into the appropriate location in your comment string: comment=['1st line of text goes here' sprintf('\n') '2nd line of text goes here. etc etc.']; I have another function called submitcomment that does just that. It has some built in error checking in that it will first check to make sure the text of that comment isn't present in the entry and if it is, won't actually submit the comment since it would just be a duplicate.
From: Alan Chalker on 10 May 2010 00:32 I thought I'd start a list of 'comment modules' to create. If anyone has any suggestions or would like to tackle one of these please let me know. 1. Comment all the entries that show up on the stats page with their corresponding rank. For example, in an entry finished 10th in the K node challenge, the comment would say so. I do know there were some issues with the leader stats, so I might actually write this to calculate the stats directly from the entries, instead of copying what's on the stat page. 2. Indicate the results of running the entry through the test suite, and the corresponding rank (based upon the results Jan ends up with this weekend) 3. Indicate the length of the entry (a stat that disappeared when the node concept appeared) 4. Give a breakdown of what percentage of the entry was 'new code' versus copied from previous entries (and which entries / authors originated the copied code). This would obviously be a bit of a challenge since it would require significant 'fingerprinting' algorithms.
From: Alan Chalker on 10 May 2010 00:35 "Hannes Naudé" <naude.jj+matlab(a)gmail.com> wrote in message <hs1sat$pk8$1(a)fred.mathworks.com>... > > Hannes: Also grabbing it now, thanks. I see there's allready six downloads in the few minutes since it was released, so there's a fair bit of interest in this. > And now it's up to 41 downloads. It seems like this idea has resonated with a lot of people!
From: Jan on 10 May 2010 08:06
On 5/10/2010 6:05 AM, Alan Chalker wrote: > This brings up an interesting question I've always wondered about. How > does the contest machinery do this? Would anyone from the MATLAB team be > willing to share the details? Most probably not within Matlab itself. Since it was annoying me a lot that I could not be sure about the termination of the thousands of algorithms I wanted to have the execution time limit functionality also but failed. Matlab is strictly single threaded. Even the timer when setting the busymode to error will not execute the error function unless the timer function has finished which can potentially take very long. And if you are inside some dll doing some stuff immediate breaking out is dangerous, who will do the clean up? However for automatic testing something like a scheduled ctrl.+c (i.e. if still within my function, in X seconds, do what is normally done upon ctrl.+c but do not print anything and instead execute a function specified by me) would be nice. I guess that the Matlab people had two Matlabs running and remotely controlled one from the other, including a tool that kills a process if a time limit is exceed. Only killing a process really cleans all memory allocation at any time. But maybe there is an easier way? Jan |