Talk:Averages/Simple moving average: Difference between revisions

Line 46:
 
--[[User:Rdm|Rdm]] 18:04, 7 June 2010 (UTC)
 
==Some confusion over interpretation==
The text states "create a ... that takes a period and returns a routine that ..." which seems to me to require the generation of the source code of a function that will perform the simple moving average. As distinct from devising a function that calculates a moving average. In a system with a pre-processor as a part of the language (as with pl/i) the preprocessor procedure would be given a period P (such as 3) and would generate the pl/i source for a function sma3(v), and on another invocation such as 5 would generate the source for sma5(v) and so on. Pl/i also allows alternate entry points to functions/procedures, so these could be supplied to enable the initialisation of a given SMA''n'' routine, so that each different size could be employed separately and restarted at will. I am supposing that each routine would be invoked with successive values to average, as in <code>for i:=1:20 do sma3(sqrt(i));</code> or similar. If alternate entries are unavailable, then each SMA''n'' could be used on only one sequence during the life of a prog., unless some global variable can be adjusted to cause a re-initialisation.
 
Alternatively, and especially for compiler-based systems, a compound routine is intended, with multiple parameters that enable the specification of a period P and the initialisation of such a summation's internal storage, followed by the presentation of a datum for a particular period P (presumably, two parameters: the chosen P and the value to be averaged) with potentially many different averages (each with a distinct P) going on together as further data are provided...
 
Alternatively, the plan would be to devise a routine SMA that on its first invocation is with P; the routine allocates internal memory to save values between the second and successive calls that will follow so as to provide the moving average of order P. Such a routine could not be used on two independent streams of data, and the initial P cannot be changed.
 
Alternatively, provide the auxiliary storage as a second parameter, with different such parameters for each summation (different values of P, and multiple summations for the same P). But this means that the routine itself contains no state information internally.
 
So, I'm confused... [[User:Dinosaur|Dinosaur]] ([[User talk:Dinosaur|talk]]) 07:52, 27 October 2015 (UTC)
1,220

edits