主要内容

ExponentiallyWeightedNormalizer

Exponentially weighted normalizer

Since R2026a

Description

An ExponentiallyWeightedNormalizer model object represents an incremental normalizer that uses exponential weighting, where newer observations receive higher weight than older ones. After creating the object, you can use the fit object function to update the weighted Center (mean) and Scale (standard deviation) property values of the object based on new data. You can return normalized data by using the fit or transform function.

Creation

Create an exponentially weighted normalizer object using incrementalNormalizer.

Properties

expand all

This property is read-only.

List of categorical predictors, represented as a vector of positive integers. Each entry in the vector is an index value corresponding to the column of the predictor data that contains a categorical variable.

For categorical predictors:

Data Types: single | double

This property is read-only.

Predictor variable names, represented as a string array. If you do not specify PredictorNames when you create the object, then PredictorNames is ["x1" "x2" ... "xN"], where N is the value of NumPredictors.

Data Types: string

This property is read-only.

Number of predictor variables, represented as a nonnegative integer.

  • If Center is not empty, NumPredictors equals the number of elements in Center.

  • If PredictorNames is not empty, NumPredictors equals the number of elements in PredictorNames.

  • If NumPredictors is 0, when you call the incremental fit function, the software sets NumPredictors to the number of predictors in the training data.

Data Types: single | double

This property is read-only.

Warm-up period before the normalized predictor output, represented as a nonnegative integer. The WarmupPeriod value is the number of observations to which the incremental model must be fit before the incremental fit function returns predictor data that is not NaN.

Data Types: single | double

This property is read-only.

Training period before Center and Scale are fixed, represented as a positive integer. After the incremental fit function processes TrainingPeriod observations, the function no longer updates Center (and Scale, if ScaleData is true).

Data Types: single | double

This property is read-only.

Flag indicating whether the incremental fit function updates Scale, represented as a numeric or logical 0 (false) or 1 (true).

When ScaleData is false, Scale is [] and the normalized predictor data returned by fit or transform is centered and not scaled.

Data Types: logical

This property is read-only.

Update frequency, represented as a positive integer. The incremental fit function updates Center (and Scale, if ScaleData is true) each time the function processes UpdateFrequency observations.

Data Types: single | double

This property is read-only.

Predictor means, represented as a 1-by-NumPredictors numeric array. The Center values that correspond to CategoricalPredictors are NaN.

Data Types: single | double

This property is read-only.

Predictor standard deviations, represented as a 1-by-NumPredictors numeric array. The Scale values that correspond to CategoricalPredictors are NaN. If ScaleData is false, the Scale values that correspond to noncategorical predictors are 0.

Data Types: single | double

This property is read-only.

Sum of weights, represented as a 1-by-NumPredictors array of positive scalar values. The SumOfWeights values that correspond to CategoricalPredictors are NaN. The incremental fit function uses SumOfWeights to update Center (and Scale, if ScaleData is true).

Data Types: single | double

This property is read-only.

Flag indicating whether the incremental fit function returns normalized predictor values, represented as a numeric or logical 0 (false) or 1 (true). IsWarm becomes true after fit processes WarmupPeriod observations. If IsWarm is false, the normalized output of fit consists of NaN values.

Data Types: single | double | logical

This property is read-only.

Number of observations used for training, represented as a nonnegative integer. If NumTrainingObservations exceeds TrainingPeriod, the incremental fit function does not update Center and Scale.

Data Types: double

Forgetting factor for the Center and Scale values calculated by fit, represented as a scalar value from 0 to 1. A high ForgettingFactor value gives more weight to newer observations than older ones. A value of 0 indicates infinite memory, where all the previous observations have equal weight when the incremental fit function updates the Center values (and Scale values, if ScaleData is true).

Data Types: double | single

Object Functions

fitFit incremental normalizer model to streaming data
transformNormalize streaming data
resetReset incremental normalizer model

Examples

collapse all

Generate a data set X that contains 1000 observations of a simulated Gaussian noise signal with a standard deviation of 0.05. The signal has an initial mean of 1, which increases linearly after the 500th observation.

rng(0,"twister"); % For reproducibility
n = 1000;
m = 500;
initialMu = 1;
sigma = 0.05;
driftRate = 1/1000;
X = initialMu + sigma*randn(m,1);
t = (1:n-m)';
X = [X; initialMu + t*driftRate + sigma*randn(n-m,1)];

Plot the data set.

plot(X)
xlabel("Observation")
ylabel("X",Rotation=0)

Figure contains an axes object. The axes object with xlabel Observation, ylabel X contains an object of type line.

Create Incremental Normalization Model

Create an exponentially weighted incremental normalization model with an initial Center (mean) value of 1 and a Scale (standard deviation) value of 0.05, based on 10 prior observations. Display the properties of the model object.

Normalizer = incrementalNormalizer("exponentiallyweighted", ...
    Center=1,Scale=0.05,NumObservations=10);
details(Normalizer)
  incremental.preprocessing.ExponentiallyWeightedNormalizer with properties:

               SumOfWeights: 10
           ForgettingFactor: 0.0500
                  ScaleData: 1
                     Center: 1
                      Scale: 0.0500
             PredictorNames: "x1"
                     IsWarm: 1
    NumTrainingObservations: 0
              NumPredictors: 1
               WarmupPeriod: 0
             TrainingPeriod: Inf
            UpdateFrequency: 1
      CategoricalPredictors: []

  Methods, Superclasses

Normalizer is an ExponentiallyWeightedNormalizer model object. All its properties are read-only. The properties of Normalizer affect how the software processes chunks of data as follows:

  • The incremental fit function returns normalized data (IsWarm=true).

  • The ScaleData value is true, meaning that the normalized data is centered (mean = 0) and scaled (standard deviation = 1).

  • fit updates the Center and Scale values of the model each time it processes an observation (UpdateFrequency=1).

  • The value of ForgettingFactor (0.05) is greater than zero, meaning that fit assigns higher weight to newer observations.

  • The TrainingPeriod value is Inf, meaning that the Center and Scale values of the model are never fixed.

Perform Incremental Fitting

To simulate a data stream, process the data in chunks of 50 observations at a time. At each iteration:

  • Process 50 observations.

  • If the mean of the data chunk is within one standard deviation of the signal's initial mean, transform the data chunk using the current model. Otherwise, overwrite the previous incremental model with a new one fitted to the incoming observations, and then transform the data chunk using the updated values of Center and Scale.

  • Store center, the fitted Center value of Normalizer, to see it evolves during incremental learning.

  • Store scale, the fitted Scale value of Normalizer, to see how it evolves during incremental learning.

  • Store XNormalized, the normalized data chunk, to see how it evolves during incremental learning.

numObsPerChunk = 50;
nchunk = floor(n/numObsPerChunk);
center = zeros(nchunk,1);
scale = zeros(nchunk,1); 
XNormalized = [];
% Incremental normalization
for j = 1:nchunk
    ibegin = min(n,numObsPerChunk*(j-1) + 1);
    iend = min(n,numObsPerChunk*j);
    idx = ibegin:iend;
    chunkMu = mean(X(idx));
    if abs(chunkMu - initialMu) < sigma
        normalized = transform(Normalizer,X(idx));
    else
        [Normalizer,normalized] = fit(Normalizer,X(idx));
    end
    center(j) = Normalizer.Center;
    scale(j) = Normalizer.Scale;
    XNormalized = [XNormalized;normalized];
end

Analyze Incremental Model During Training

To see how the Center and Scale values evolve during training, plot them on separate tiles.

figure
tiledlayout(2,1);
nexttile
plot(center,"o-")
xlabel("Iteration")
ylabel("Center")
nexttile
plot(scale,"o-")
xlabel("Iteration")
ylabel("Scale")

Figure contains 2 axes objects. Axes object 1 with xlabel Iteration, ylabel Center contains an object of type line. Axes object 2 with xlabel Iteration, ylabel Scale contains an object of type line.

The Center and Scale values closely track the signal's mean and standard deviation values during the first 11 iterations. After the signal's mean starts to drift, the Center value continues to track the signal's mean, and the Scale value fluctuates slightly around the signal's standard deviation value.

Plot the normalized signal data, and then display its mean and standard deviation.

figure
plot(XNormalized)
xlabel("Observation")
ylabel("XNormalized")

Figure contains an axes object. The axes object with xlabel Observation, ylabel XNormalized contains an object of type line.

display(mean(XNormalized))
   -0.0180
display(std(XNormalized))
    0.9880

The normalized signal has a mean close to zero and a standard deviation close to 1.

Version History

Introduced in R2026a