# HG changeset patch
# User Frankie Robertson <frankie@robertson.name>
# Date 1485107914 -3600
#      Sun Jan 22 18:58:34 2017 +0100
# Node ID 72c706a397ff3513691cda02c513732eb87beb51
# Parent  6ffb70ced9eb29274d2480f82a6b9fc11292e7df
Update newff to support Matlab 2007 interface

diff --git a/inst/logsig.m b/inst/logsig.m
--- a/inst/logsig.m
+++ b/inst/logsig.m
@@ -33,7 +33,7 @@ function a = logsig(n)
   a = 1 ./ (1 + exp(-n));
   ## attention with critical values ==> infinite values
   ## must be set to 1! Still the same problem as in "tansig"
-  i = find(!finite(a));
+  i = find(!isfinite(a));
   a(i) = sign(n(i));
 
 endfunction
diff --git a/inst/newff.m b/inst/newff.m
--- a/inst/newff.m
+++ b/inst/newff.m
@@ -44,7 +44,7 @@
 
 ## Author: Michel D. Schmid
 
-function net = newff(Pr,ss,transFunc,trainFunc,notUsed,performFunc)
+function net = newff(Pr,ss,transFunc,trainFunc,notUsed,performFunc,extra)
 
   ## initial descriptipn
   ##  newff(Pr,ss,transfunc,trainFunc,notUsed,performFunc)
@@ -58,9 +58,42 @@ function net = newff(Pr,ss,transFunc,tra
   ##  * notUsed exist only because we have only one train algorithm which doesn't
   ##    need a weight learning function
   ##  * performFunc is written for the performance function, standard is "mse"
+  ## alternative signature
+  ##  newff(input,output,hidden)
+  ##  * input is a matrix containing the inputs to the neural network
+  ##  * output is a matrix containg the output of the neural network
+  ##  * hidden is the number of neurons in the hidden layer(s)
 
-  ## check range of input arguments
-  error(nargchk(2,6,nargin))
+  if (nargin >= 3 && not(iscellstr(transFunc)))
+    # Alternative signature
+    input = Pr;
+    output = ss;
+    hidden = transFunc;
+    Pr = minmax(input);
+    ss = [hidden,size(output)(1)];
+
+    # Move all the later arguments backwards
+    if (nargin > 3)
+      transFunc = trainFunc;
+    else
+      clear transFunc;
+    endif
+    if (nargin > 4)
+      trainFunc = notUsed;
+    endif
+    if (nargin > 5)
+      notUsed = performFunc;
+    endif
+    if (nargin > 6)
+      perfomFunc = extra;
+    endif
+    ## check range of input arguments
+    error(nargchk(3,7,nargin))
+    nargin = nargin - 1;
+  else
+    ## check range of input arguments
+    error(nargchk(2,6,nargin))
+  endif
 
   ## get number of layers (without input layer)
   nLayers = length(ss);
diff --git a/inst/private/__trainlm.m b/inst/private/__trainlm.m
--- a/inst/private/__trainlm.m
+++ b/inst/private/__trainlm.m
@@ -59,7 +59,7 @@
 ## search for 1 letter variable... that's why it is written here like Pp, or Tt
 ## instead only P or T.
 
-function [net] = __trainlm(net,Im,Pp,Tt,VV)
+function [net,tr] = __trainlm(net,Im,Pp,Tt,VV)
 
   ## check range of input arguments
   error(nargchk(5,5,nargin))
@@ -214,6 +214,8 @@ function [net] = __trainlm(net,Im,Pp,Tt,
 
   endfor #for iEpochs = 0:epochs
 
+  tr = struct('perf', perf, 'epochs', epochs);
+
 #=======================================================
 #
 # additional functions
diff --git a/inst/tansig.m b/inst/tansig.m
--- a/inst/tansig.m
+++ b/inst/tansig.m
@@ -33,7 +33,7 @@ function a = tansig(n)
   a = 2 ./ (1 + exp(-2*n)) - 1;
   ## attention with critical values ==> infinite values
   ## must be set to 1
-  i = find(!finite(a));
+  i = find(!isfinite(a));
   a(i) = sign(n(i));
 
 endfunction
diff --git a/inst/train.m b/inst/train.m
--- a/inst/train.m
+++ b/inst/train.m
@@ -49,7 +49,7 @@
 ## search for 1 letter variable... that's why it is written here like Pp, or Tt
 ## instead only P or T.
 
-function [net] = train(net,Pp,Tt,notUsed1,notUsed2,VV)
+function [net,tr] = train(net,Pp,Tt,notUsed1,notUsed2,VV)
 
   ## check range of input arguments
   error(nargchk(3,6,nargin))
@@ -120,7 +120,7 @@ function [net] = train(net,Pp,Tt,notUsed
       if !strcmp(net.performFcn,"mse")
         error("Levenberg-Marquardt algorithm is defined with the MSE performance function, so please set MSE in NEWFF!")
       endif
-      net = __trainlm(net,Im,Pp,Tt,VV);
+      [net, tr] = __trainlm(net,Im,Pp,Tt,VV);
     otherwise
       error("train algorithm argument is not valid!")
   endswitch
