Moving Average (moving average, MA)

Source: Internet
Author: User

The moving average method is a common method used to predict the demand of the company's products and the company's production capacity in the next period or several periods with a set of recent actual data values. The moving average method is applicable to spot prediction. The moving average method can effectively eliminate the stochastic fluctuation in the forecast when the demand of the product is neither fast nor fast, and there is no seasonal factor. The moving average method can be divided into:

Simple moving average weighted moving average simple moving average: the weights of each element of the simple moving average are equal. The simple moving average is calculated as follows:

weighted Moving Average method:
The weighted moving average gives the value of each variable in a fixed spanning period with unequal weights. The principle is that the data information of the product demand in the historical period is different to predict the demand in the future period. In addition to periodic changes in the period of N, the influence of variable values away from the target period is relatively low, so lower weights should be given. The weighted moving average method is calculated as follows:


#coding: Utf-8 import TensorFlow as TF "" "Tf.train.ExponentialMovingAverage (decay, steps) Use the sliding average method to update the parameters. This function initialization needs to provide a decay rate (decay) to control the update speed of the model. The function also maintains a shadow variable (that is, the parameter value after updating the parameter), and the initial value of the shadow variable is the initial value of the variable, and the value of the shadow variable is updated as follows: shadow_variable = decay * shadow_variable + (1-decay) * Variable decay is the attenuation rate.

The decay is generally set to a number close to 1 (0.99,0.999).
Tf.train.ExponentialMovingAverage also provides a way to calculate the automatic Update decay: decay= min (Decay, (1+steps)/(10+steps)) steps is the number of iterations that can be set by itself. "" "V1 = tf. Variable (0, Dtype=tf.float32) # defines a variable with an initial value of 0 step = tf. Variable (0, Trainable=false) # Step for the iteration wheel number variable, control attenuation rate EMA = tf.train.ExponentialMovingAverage (0.99, Step) # Initial set attenuation The rate is 0.99 maintain_averages_op = ema.apply ([v1]) # Update the variables in the list with TF. Session () as Sess:init_op = Tf.initialize_all_variables () # init_op = Tf.global_variables_initializer () # initializes all Variable (init_op) print ( ([V1, Ema.average (v1)]) # decay=min (0.99, 1/10) =0.1, v1=0.1*0+0.9*0=0              .0 (Tf.assign (v1, 5))        # Update V1 value (maintain_averages_op) # decay=min (0.99, 1/10) =0.1, v1=0.1*0+0.9*5=4.5 p Rint ( ([V1, Ema.average (v1)])) (Tf.assign (step, 10000)) # Update Iteration Rotation number Step (TF.A          Ssign (v1, 10) # Update the value of V1 (maintain_averages_op) print ( ([V1, Ema.average (v1)]))                 # Decay=min (0.99, (1+10000)/(10+10000)) =0.99, v1=0.99*4.5+0.01*10=4.555 (tf.assign (step, 1234)) # Update Iteration Rotation number Step (tf.assign (v1, 15)) # Update V1 value (maintain_averages_o p) Print ( ([V1, Ema.average (v1)]) # Decay=min (0.99, (1+1234)/(10+1234)) =0.99, v1=0.99*4.555+0.01*15=4.
Operation Result:
You can see that the results of the operation are consistent with the calculations of our annotations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.