Process matrices by mapping row minimum and maximum values to [-1 1]
[Y,PS] = mapminmax(X,YMIN,YMAX)
[Y,PS] = mapminmax(X,FP)
Y = mapminmax('apply',X,PS)
X = mapminmax('reverse',Y,PS)
dx_dy = mapminmax('dx_dy',X,Y,PS)
mapminmax processes matrices by normalizing the minimum and maximum values of each row to [YMIN, YMAX].
[Y,PS] = mapminmax(X,YMIN,YMAX) takes X and optional parameters
N-by-Q matrix or a 1-by-TS row cell array of N-by-Q matrices
Minimum value for each row of Y (default is –1)
Maximum value for each row of Y (default is +1)
Each M-by-Q matrix (where M == N) (optional)
Process settings that allow consistent processing of values
[Y,PS] = mapminmax(X,FP) takes parameters as a struct: FP.ymin, FP.ymax.
Y = mapminmax('apply',X,PS) returns Y, given X and settings PS.
X = mapminmax('reverse',Y,PS) returns X, given Y and settings PS.
dx_dy = mapminmax('dx_dy',X,Y,PS) returns the reverse derivative.
Here is how to format a matrix so that the minimum and maximum values of each row are mapped to default interval [-1,+1].
x1 = [1 2 4; 1 1 1; 3 2 2; 0 0 0] [y1,PS] = mapminmax(x1)
Next, apply the same processing settings to new values.
x2 = [5 2 3; 1 1 1; 6 7 3; 0 0 0] y2 = mapminmax('apply',x2,PS)
Reverse the processing of y1 to get x1 again.
x1_again = mapminmax('reverse',y1,PS)
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.