when to use mapstd, mapminmax

Illustration
Jana_salim - 2021-07-08T10:27:35+00:00
Question: when to use mapstd, mapminmax

Mapstd is used for standardization, mapminmax is for normalization. But When to use mapstd and mapminmax? I want to do a regression(function fitting) with neural network. While I am creating the nn with nftool, it normalize the input data and target(mapminmax) automatically. So I was wondered that.  

Expert Answer

Profile picture of Neeta Dsouza Neeta Dsouza answered . 2025-11-20

Both mapstd and mapminmax are used for transforming data before feeding it into a neural network, but they serve different purposes and are suitable for different situations. Here's a breakdown of when and why to use each of them, especially in the context of regression with neural networks.

1. mapstd (Standardization):

  • Purpose: It standardizes the input data by transforming it to have a mean of 0 and a standard deviation of 1. This is useful when the data has different units or widely varying scales.

  • Formula:

    xnew=x−μσx_{\text{new}} = \frac{x - \mu}{\sigma}

    where:

    • μ\mu is the mean of the data.
    • σ\sigma is the standard deviation of the data.
  • When to use mapstd:

    • Use mapstd when your data has different units, scales, or distributions. For example, if one feature ranges from 0 to 1 and another ranges from 0 to 1000, standardizing the data ensures that each feature contributes equally to the model.
    • It’s also helpful when the input data has outliers, as standardization reduces the influence of extreme values.
    • If your neural network has a sigmoid or tanh activation function, it is often beneficial to standardize the data to ensure the activations are within a similar scale (e.g., the range [−1,1][-1, 1] for tanh).
    • Example:
% Standardize data (mean=0, std=1)
[X_standardized, settings] = mapstd(X);
/pre>

 

 

2. mapminmax (Normalization):

  • Purpose: It normalizes the input data by scaling it to a specified range, typically between 0 and 1. This can be useful when your features are on different scales but need to be treated equally in terms of importance.

  • Formula:

    xnew=x−minmax−minx_{\text{new}} = \frac{x - \text{min}}{\text{max} - \text{min}}

    where:

    • min\text{min} and max\text{max} are the minimum and maximum values of the data.
  • When to use mapminmax:

    • Use mapminmax when you want to scale the data into a fixed range, typically [0, 1], and the neural network activation function (like the sigmoid) expects inputs in this range.
    • This is useful when your data has different magnitudes but is well-behaved, with no extreme outliers.
    • Normalizing to the range [0, 1] can help prevent issues with training stability in certain models, especially when using activation functions like sigmoid or tanh, as they can saturate if the input is too large or small.
  • Example:

% Normalize data (scale to [0, 1])
[X_normalized, settings] = mapminmax(X);

3. Neural Networks (nftool):

  • Default Behavior in nftool:

    • When you use nftool for regression with a neural network, it automatically normalizes the data with mapminmax by default, scaling both the inputs and targets to the range [0, 1].
    • This is because the sigmoid and other activation functions typically perform better when the input values are scaled within a similar range (e.g., [0, 1] or [-1, 1]).
  • How to handle normalization manually:

    • If you're manually processing your data before passing it to the neural network, you can use mapminmax to normalize the data. However, if the automatic normalization of nftool works well for your data, you may not need to do it manually.
    • Ensure that you use the same normalization settings for both training and validation data.

Key Differences:

  • Use mapstd when:

    • You want to standardize the data to have zero mean and unit variance, typically when using activation functions that are sensitive to scale like tanh.
    • Your data has varying units and scales, and you want to bring all features to a comparable scale.
  • Use mapminmax when:

    • You want to scale the data into a fixed range (e.g., [0, 1]) which is especially useful when using sigmoid activation functions in neural networks.
    • You are working with data that doesn't have extreme outliers and where scaling to [0, 1] or [-1, 1] will be beneficial for network convergence.

Conclusion:

  • mapminmax is typically preferred for neural networks, especially when using activation functions like sigmoid or tanh, because it ensures the input data is in a range that avoids saturation of the activations.
  • mapstd is useful if you want to standardize the data, especially when the data has a Gaussian distribution or different scales across features.

If you're using nftool and it automatically normalizes the data using mapminmax, it's likely best to let it do so unless you have a specific reason to manually adjust the normalization or standardization.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!