MovingMap

MovingMap[f,data,w]

applies f to size w windows in the specified data.

MovingMap[f,data,wspec]

uses windows specified by wspec.

MovingMap[f,data,wspec,padding]

pads data using padding.

Details

  • MovingMap can be used for regularly spaced data and for irregularly spaced data.
  • In many contexts, the ti are times.
  • The data can be a list of values {x1,x2,}, a list of time-value pairs {{t1,x1},{t2,x2},}, a TimeSeries, EventSeries, or TemporalData.
  • A function f of a single argument gets applied to a list of values {xi,xi+1,} for each window. »
  • A pure function f can access values, times, boundary values, and boundary times for each window using the following arguments: »
  • #Values or #1data values within the window
    #Times or #2data times within the window
    #BoundaryValues or #3resampled values at window boundaries
    #BoundaryTimes or #4times at window boundaries
    #Dates or #5data dates within the window
  • By default, f is expected to compute a single value for each window and the time is computed automatically. Using a function f that gives output as rules {τi,}{vi,} allows control over both time and value as well as producing multiple values per window. »
  • The full window specification wspec is a triple {size,align,wpos}, where wpos determines time positions of each window, and size and align specify overall size and alignment that applies to all windows relative to the window positions wpos. »
  • Window placements {τ1,,τm} are specified by wpos. With data time stamps {t1,,tn}, wpos can be one of the following:
  • Automaticuse data time stamps τi=ti
    {τmin,τmax}use τi=tk+i such that τmintk+iτmax
    {Automatic,τmax}equivalent to {t1,τmax}
    {τmin,Automatic}equivalent to {τmin,tn}
    {τmin,τmax,dτ}use τ1=τmin, τ2=τmin+dτ, etc.
    {{τ1,,τm}}use explicit τ1, τ2, etc.
  • By default, the time stamps of the output are {τ1,,τm}.
  • Window size can be given as the following:
  • wpositive number, taken to mean days
    Quantity[w,timeunit]duration w in units of timeunit
    Quantity[n,"Events"]events count n defines the window size
  • The window size may be varying in an absolute sense when referring to relative units such as "Month" or "Events".
  • Window alignment align determines relative position of τi within the window. The possible settings include Right (default), Left, and Center.
  • Window specification {size,align} is equivalent to {size,align,Automatic}.
  • Window specification size or {size} is equivalent to {size,Right,Automatic}.
  • Settings for padding include:
  • Automaticonly keep non-overhanging windows (default)
    Noneno padding, keep all windows
    valuepaddingequivalent to {Automatic,valuepadding}
    {timepadding,valuepadding}padding settings for times and values
  • Settings for valuepadding can be any valid specification recognized by ArrayPad.
  • Settings for timepadding include:
  • Automaticpad uniformly median time-step size
    Δtpad uniformly with step-size Δt
    {Δt1,Δt2,}cyclically pad with steps Δti
    "ReflectedDifferences"reflections of the differences between times
    "PeriodicDifferences"cyclically pad with steps ti+1-ti
  • MovingMap threads pathwise for multipath data.

Examples

open allclose all

Basic Examples  (3)

Perform average over window of width 2:

Perform a three-element moving average:

Smooth an irregularly spaced time series:

Place the window regularly with monthly intervals:

Smooth multiple paths simultaneously:

Use a centered window and reflected padding:

Scope  (30)

Basic Uses  (4)

Map a function f over data with a window of width two units of time:

Map a function f over data with a three-events window:

Compute a moving quantile for some data:

Use centered window of unit size:

Find a moving quartile envelope:

Find a yearly moving average of SP500 time series:

Find a yearly moving average of the time series, placing windows monthly:

Place windows monthly at the first day of each month and use reflected value padding:

Data Types  (7)

Create a generic moving function for a vector:

Compute a moving average for a list of time-value pairs:

Compute a moving GeometricMean for a TimeSeries:

Compute a moving median for a TemporalData:

Compute a moving total for an EventSeries:

Compute a moving variance for multiple paths simultaneously:

Compute a moving correlation coefficient between two components of a bivariate time series:

Moving correlation coefficient over window of size 100:

Functions  (5)

Apply a generic function to values within moving windows:

Use a pure function instead:

Apply a generic function to values and time stamps within moving windows:

Use a pure function with named arguments:

Also provide the function with boundary times and resampled values of data at boundary times:

Define a function to compute both times and values for each window:

Use it to effectively associate window average with scaled time point within the window:

Define a function that drops missing values and their corresponding times:

Temperature readings in Champaign, IL:

Time series contains some missing values:

Delete data points with missing values:

Compute the mean temperature in January:

Find the number of days between consecutive Thanksgiving holidays:

Window Sizes  (4)

Use numeric width of the moving window:

Use time quantities to specify extent of the moving window:

Specify window size using pairs {n,"unit"}:

Find daily median temperature every 4 hours:

Visualize the time series, showing seasonal temperature quartiles:

Specify window size by the number of events it contains:

Find moving average number of events per week:

Window Alignment  (4)

Right-aligned windows use past values:

Right alignment is used by default:

Centered windows use both past and future values:

Left-aligned windows use future values:

Compare window alignments:

Because the time series is regular, values of moving averages for each alignment are equal:

The times are not:

A visual comparison:

Window Placements  (3)

Place windows automatically at every data point:

Place windows at every data point within an interval:

Place windows at every data point after a given instant:

Place windows uniformly:

Place windows uniformly within a given range:

Place windows at the given time stamps:

Find the highest stock value within the last two quarters for each date of interest:

Padding  (3)

With Automatic padding, only those windows that do not overhang the data time domain are used:

Automatic padding is used by default:

With padding set to None, some windows may overhang the data time domain:

Use Automatic time padding and constant value padding:

Applications  (10)

Smoothing and Thinning Data  (1)

Temperature readings in Savoy, IL, around Valentine's Day at about one-minute resolution:

Compute the hourly moving average at resolution of 20 minutes:

Market Volatility  (1)

Identify periods of high volatility in the S&P 500:

Five-year moving standard deviation:

Annual moving interquartile range:

Two-year moving range:

Weighted Moving Average  (3)

Compute a moving average of a regular time series, assigning more weight to recent values:

Compare to placing more weight on past values:

Use a centered window, placing the most weight on central values:

Compute a moving-time average of irregularly sampled continuous-time series:

Weights for the integral of a linear interpolation function over its domain:

Time average of linear interpolation of {{t1,v1},,{tn,vn}} over the interval {t1,tn}:

Particle Trajectories  (2)

Simulate a trajectory with heavy-tailed measurement noise:

The underlying signal and simulated path with noise:

Smooth the trajectory using a moving TrimmedMean:

Increasing the window size gives a smoother trajectory:

Smooth an object's trajectory with measurement noise in 3D space:

GARCH and ARMA Processes  (1)

Compare the volatility of GARCH and ARMA processes:

The stationary mean and variance are equivalent for the processes:

For GARCH processes, the volatility exhibits characteristic spikes:

Time Series Filter  (1)

Minuteresolution temperature readings in Savoy, IL, around Valentine's Day:

Specify a function to find the time and value of the highest temperature in the window:

Specify a function to find the time and value of the lowest temperature in the window:

Specifications for 1-day-long, left-aligned windows placed at the beginning of each day:

Time-Changed Wiener Process  (1)

Build a sample of OrnsteinUhlenbeckProcess from a sample of WienerProcess:

Using , find and from and :

Compute a moving map over one event window, with a function that maps Wiener path time-value pair to OrnsteinUhlenbeck path time-value pair:

Visualize simulated paths and compare to the process mean function:

Properties & Relations  (5)

MovingMap of Mean over regular data is equivalent to MovingAverage:

MovingMap of Median over regular data is equivalent to MovingMedian:

MovingMap is related to ListConvolve:

MovingMap is related to ListCorrelate:

Take successive differences:

Alternatively, use Differences:

Generalize to higher-order differences:

Neat Examples  (2)

Find a moving global Min and Max:

Visualize the changing entropy in the US Constitution. Lower entropy occurs when the same words are used repeatedly:

There is a spike in entropy where several people list their names and states of origin:

The 25th Amendment, concerning presidential succession, is comparatively repetitive:

The top 10 most frequently occurring words in the 25th Amendment:

Wolfram Research (2014), MovingMap, Wolfram Language function, https://reference.wolfram.com/language/ref/MovingMap.html (updated 2017).

Text

Wolfram Research (2014), MovingMap, Wolfram Language function, https://reference.wolfram.com/language/ref/MovingMap.html (updated 2017).

CMS

Wolfram Language. 2014. "MovingMap." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017. https://reference.wolfram.com/language/ref/MovingMap.html.

APA

Wolfram Language. (2014). MovingMap. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MovingMap.html

BibTeX

@misc{reference.wolfram_2024_movingmap, author="Wolfram Research", title="{MovingMap}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/MovingMap.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_movingmap, organization={Wolfram Research}, title={MovingMap}, year={2017}, url={https://reference.wolfram.com/language/ref/MovingMap.html}, note=[Accessed: 21-November-2024 ]}