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 #1 data values within the window #Times or #2 data times within the window #BoundaryValues or #3 resampled values at window boundaries #BoundaryTimes or #4 times at window boundaries #Dates or #5 data 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:
-
Automatic use data time stamps τi=ti {τmin,τmax} use τi=tk+i such that τmin≤tk+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:
-
w positive 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:
-
Automatic only keep non-overhanging windows (default) None no padding, keep all windows valuepadding equivalent 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:
-
Automatic pad uniformly median time-step size Δt pad 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 allBasic Examples (3)
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:
Functions (5)
Apply a generic function to values within moving windows:
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:
Window Alignment (4)
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 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:
Applications (10)
Smoothing and Thinning Data (1)
Market Volatility (1)
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)
Time Series Filter (1)
Minute‐resolution 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:
Compute a moving map over one event window, with a function that maps Wiener path time-value pair to Ornstein–Uhlenbeck 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:
Alternatively, use 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:
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