forked from viggin/yan-prtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regress_ann_tr.m
35 lines (30 loc) · 1.03 KB
/
regress_ann_tr.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function model = regress_ann_tr(X,Y,param)
%Train an artificial neural network regressor.
% There are many network functions in Matlab. You can choose what's best
%
% X : each row is a sample.
% Y : a column vector.
% PARAM: struct of parameters. The beginning part of this code (before
% defParam) explains each parameter, and also sets the default parameters.
% You can change parameter p to x by setting PARAM.p = x. For parameters
% that are not set, default values will be used.
% Return:
% MODEL: a struct containing coefficients.
%
% Ke YAN, 2016, Tsinghua Univ. http://yanke23.com, [email protected]
elNum = 6;
hidFcn = 'tansig'; % choose 'purelin' if you want to avoid overfitting
epochs = 100;
goal = 1e-1;
defParam
% net = newff(X,Yvec,elNum,{hidFcn,'purelin'},'trainlm'); % old style
model = feedforwardnet(elNum);
model.layers{1}.transferFcn = hidFcn;
model.trainParam.showWindow = 0;
model.trainParam.epochs = epochs;
model.trainParam.goal = goal;
model = train(model,X',Y');
% another model
% net = newrbe(X,Y);
% view(net)
end