www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregnnet/leastsq.m
function [nn,OK] = leastsq(nn, x, y) %LEASTSQ Initialise and train neural network % % [M, OK] = LEASTSQ(M, X, Y) fits the neural network model M to the data X % and Y. % Copyright 2000-2014 The MathWorks, Inc. and Ford Global Technologies, Inc. net = nn.param; % turn off display during training net.trainParam.showWindow = false; net.trainParam.showCommandLine = false; [nn.param, tr] = train(net, x', y'); OK = isfinite(tr.perf(end)); if OK if strcmpi(nn.param.trainFcn,'trainbr') xsE = sum((y - eval(nn,x)).^2); if tr.ssX(end)==0 alpha = 1; else alpha = tr.gamk(end)/(2*(tr.ssX(end))); end if xsE==0 beta = 1; else beta = (length(y) - tr.gamk(end))/(2*xsE); end nn.lambda = sqrt(alpha/beta); else nn.lambda = 0; end % initialise model nn= InitModel(nn,x,y); end