Before training, it is often useful to scale the inputs and targets so that they always
fall within a specified range. The function mapminmax
scales inputs and
targets so that they fall in the range [–1,1]. The following code illustrates how to use this
function.
[pn,ps] = mapminmax(p);
[tn,ts] = mapminmax(t);
net = train(net,pn,tn);
The original network inputs and targets are given in the matrices p
and
t
. The normalized inputs and targets pn
and tn
that
are returned will all fall in the interval [–1,1]. The structures ps
and
ts
contain the settings, in this case the minimum and maximum values of the
original inputs and targets. After the network has been trained, the ps
settings should be used to transform any future inputs that are applied to the network. They
effectively become a part of the network, just like the network weights and biases.
If mapminmax
is used to scale the targets, then the output of the
network will be trained to produce outputs in the range [–1,1]. To convert these outputs back
into the same units that were used for the original targets, use the settings
ts
. The following code simulates the network that was trained in the
previous code, and then converts the network output back into the original units.
an = sim(net,pn);
a = mapminmax('reverse',an,ts);
The network output an
corresponds to the normalized targets
tn
. The unnormalized network output a
is in the same
units as the original targets t
.
If mapminmax
is used to preprocess the training set data, then whenever
the trained network is used with new inputs they should be preprocessed with the minimum and
maximums that were computed for the training set stored in the settings ps
.
The following code applies a new set of inputs to the network already trained.
pnewn = mapminmax('apply',pnew,ps);
anewn = sim(net,pnewn);
anew = mapminmax('reverse',anewn,ts);
For most networks, including feedforwardnet
, these steps are done
automatically, so that you only need to use the sim
command.