Permalink
Browse files

Added get_matlabVersion, check_matlabVersion, explode, implode and up…

…dated train_bp to utilize check_matlabVersion to fix the 'newff used in obsolete way' error.
  • Loading branch information...
Wildcarde committed Nov 18, 2010
1 parent 78b3854 commit 47df1e2e58e96cb52565e7bee1ffb18fb8ed8a81
BIN -1.91 KB (85%) core/learn/smlr_mex.mexa64
Binary file not shown.
@@ -180,7 +180,8 @@
% Initialize a feedforward net with nOut output units and
% act_funct as the activation function

if args.version < 7.5
%if args.version < 7.5
if check_matlabVersion(7,5) < 0
% Old way of initializing network
scratch.net = newff(patsminmax,[scratch.nOut],args.act_funct);
else
@@ -200,7 +201,8 @@
else

% Old way of initializing networks
if args.version < 7.5
%if args.version < 7.5 %this breaks at 7.10 or higher.
if check_matlabVersion(7,5) < 0 %if matlab is below version 7.5 do this.
scratch.net = newff(patsminmax,[args.nHidden scratch.nOut],args.act_funct);

% Get outputs from both the hidden and output layers
@@ -239,7 +241,8 @@
% Note that these contain the activations for all the units (both
% hidden and output). OUTIDX indexes just the output layer (whether
% you have a hidden layer or not)
if args.version < 7.5
%if args.version < 7.5
if check_matlabVersion(7,5) < 0
scratch.outidx = [args.nHidden+1:args.nHidden+scratch.nOut];
else
% IN THE NEW VERSION OF MATLAB, WE DO NOT GET THE OUTPUTS OF
@@ -0,0 +1,66 @@
function [output] = check_matlabVersion(varargin)
%
% This checks the supplied integers against the current version of matlab
% and returns a -1 if the current version is older, a 0 if they are the
% same and a 1 if they are newer. If you would like to only test the major
% and minor versions then you can call the function as:
%
% check_matlabVersion(7,5);
% the function will return the same 3 options, but only utilizing the first
% two pieces of the 4 piece version number.

% cast the matlab version into a series of integers.
[mat_ver(1) mat_ver(2) mat_ver(3) mat_ver(4)] = get_matlabVersion();

newer = 1;
same = 0;
older = -1;


%check major version, if more or less, reply and return
%if (mat_major < major) || (mat_major == major && mat_minor(1)<minor)
% output = older;
% return;
%elseif mat_major > major || (mat_major == major && mat_minor(1)>minor)
% output = newer;
% return;

%end

% if you've gotten this far the major and leading minor revisions are the
% same. If there is a supplied vararg then process it, if not simply
% return.

%if nargin < 3
% output = same;
% return
%else
%keyboard;

%if nargin > 4
% nargin = 4
%end

output = same;
if nargin > 4
length = 4;
else
length = nargin;
end

for index = 1:length

if (mat_ver(index) > varargin{index})
output = newer;
return

elseif (mat_ver(index) < varargin{index})
output = older;
return
end

end

%keyboard;


@@ -0,0 +1,47 @@
function [split,numpieces]=explode(string,delimiters)
%EXPLODE Splits string into pieces.
% EXPLODE(STRING,DELIMITERS) returns a cell array with the pieces
% of STRING found between any of the characters in DELIMITERS.
%
% [SPLIT,NUMPIECES] = EXPLODE(STRING,DELIMITERS) also returns the
% number of pieces found in STRING.
%
% Input arguments:
% STRING - the string to split (string)
% DELIMITERS - the delimiter characters (string)
% Output arguments:
% SPLIT - the split string (cell array), each cell is a piece
% NUMPIECES - the number of pieces found (integer)
%
% Example:
% STRING = 'ab_c,d,e fgh'
% DELIMITERS = '_,'
% [SPLIT,NUMPIECES] = EXPLODE(STRING,DELIMITERS)
% SPLIT = 'ab' 'c' 'd' 'e fgh'
% NUMPIECES = 4
%
% See also IMPLODE, STRTOK
%
% Created: Sara Silva (sara@itqb.unl.pt) - 2002.04.30

if isempty(string) % empty string, return empty and 0 pieces
split{1}='';
numpieces=0;

elseif isempty(delimiters) % no delimiters, return whole string in 1 piece
split{1}=string;
numpieces=1;

else % non-empty string and delimiters, the correct case

remainder=string;
i=0;

while ~isempty(remainder)
[piece,remainder]=strtok(remainder,delimiters);
i=i+1;
split{i}=piece;
end
numpieces=i;

end
@@ -0,0 +1,40 @@
function string=implode(pieces,delimiter)
%IMPLODE Joins strings with delimiter in between.
% IMPLODE(PIECES,DELIMITER) returns a string containing all the
% strings in PIECES joined with the DELIMITER string in between.
%
% Input arguments:
% PIECES - the pieces of string to join (cell array), each cell is a piece
% DELIMITER - the delimiter string to put between the pieces (string)
% Output arguments:
% STRING - all the pieces joined with the delimiter in between (string)
%
% Example:
% PIECES = {'ab','c','d','e fgh'}
% DELIMITER = '->'
% STRING = IMPLODE(PIECES,DELIMITER)
% STRING = ab->c->d->e fgh
%
% See also EXPLODE, STRCAT
%
% Created: Sara Silva (sara@itqb.unl.pt) - 2002.08.25
% Modified: Sara Silva (sara@dei.uc.pt) - 2005.03.11
% - implode did not work if the delimiter was whitespace, so
% line 36 was replaced by line 37.
% - thank you to Matthew Davidson for pointing this out
% (and providing the solution!)

if isempty(pieces) % no pieces to join, return empty string
string='';

else % no need for delimiters yet, so far there's only one piece
string=pieces{1};
end

l=length(pieces);
p=1;
while p<l % more than one piece to join with the delimiter, the interesting case
p=p+1;
%string=strcat(string,delimiter,pieces{p});
string=[string delimiter pieces{p}];
end
@@ -0,0 +1,24 @@
Copyright (c) 2007, Sara Silva
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,28 @@
function [major,minor0,minor1,minor2,revision] = get_matlabVersion()
%
% This is a simple function to return the matlab version as an array of
% integer numbers so that it can be tested against required versions for
% conditional execution. It returns the full version split into an array.
%
% This function utilizes the 'version' command to retrieve the information
% and returns as such: 7.5.0.338 (R2007b) becomes [7,5,0,338] and can be
% test against as such.
%

%capture the version string
mat_version = explode(version(),'.');

major = uint16(str2num(mat_version{1}));

minor0 = uint16(str2num(mat_version{2}));

minor1 = uint16(str2num(mat_version{3}));

%the last segment will look similar to ### (revision) and the revision must
%be removed
%keyboard;
temp = explode(mat_version{4},' ');

minor2 = uint16(str2num(temp{1}));

revision = temp{2};
@@ -22,6 +22,7 @@
myaddpath('core/preproc');
myaddpath('core/subj');
myaddpath('core/util');
myaddpath('core/util/explode_implode');
myaddpath('core/vis');
myaddpath('core/template');

@@ -96,7 +96,6 @@
% the number of times to run things
% dispf('debugging mode')
nTimes = 5000;

subj = create_test_subj(xval_actives);

runs_xval = squeeze(get_group_as_matrix(subj,'selector','runs_xval'));
@@ -159,7 +158,7 @@
% in BAL_MEAN to be within 0.1 of DESIRED
if any(abs(bal_mean(:)-desired(:))>.1), success = false; end

save
%save

if ~success
dispf('Bleurgh. Failure')

0 comments on commit 47df1e2

Please sign in to comment.