Example 13: Window Data Tool

This example shows how to use the WindowData() function to divide univariate/multivariate data into subsequences.

_______________________________________________________________________________

Ex. 1

Import a sequence of uniformly distributed random numbers.

X = ExampleData("uniform");

Extract a series of subsequences by dividing the sequence into windows of length 1024 with no overlap.

WinData, Log = WindowData(X, WinLen = 1024);
4-element Vector{Any}:
 [0.30488083; 0.3193731; … ; 0.96996519; 0.56488317;;]
 [0.2176899; 0.85776329; … ; 0.82407189; 0.87188557;;]
 [0.30107453; 0.23600521; … ; 0.01796884; 0.70151145;;]
 [0.015752307; 0.68389312; … ; 0.93608362; 0.89273695;;]
Dict{String, Any} with 6 entries:
  "DataType"      => "single univariate vector (1 sequence)"
  "TotalWindows"  => 4
  "WindowOverlap" => 0
  "Mode"          => "exclude"
  "WindowLength"  => 1024
  "DataLength"    => 5000

Repeat the previous step but change the number of overlapping window samples to 256.

WinData, Log = WindowData(X, WinLen = 1024, Overlap = 256);
6-element Vector{Any}:
 [0.30488083; 0.3193731; … ; 0.96996519; 0.56488317;;]
 [0.23505684; 0.27546108; … ; 0.19065843; 0.44929962;;]
 [0.69268163; 0.71660386; … ; 0.9850556; 0.53472262;;]
 [0.87397951; 0.7582504; … ; 0.91119243; 0.21468518;;]
 [0.015752307; 0.68389312; … ; 0.93608362; 0.89273695;;]
 [0.11680255; 0.76933052; … ; 0.5091784; 0.80413267;;]
Dict{String, Any} with 6 entries:
  "DataType"      => "single univariate vector (1 sequence)"
  "TotalWindows"  => 6
  "WindowOverlap" => 256
  "Mode"          => "exclude"
  "WindowLength"  => 1024
  "DataLength"    => 5000

_______________________________________________________________________________

Ex. 2

Window a range of numbers (1:1234) into 5 windows.

WinData, Log = WindowData(1:1234);
5-element Vector{Any}:
 [1; 2; … ; 245; 246;;]
 [247; 248; … ; 491; 492;;]
 [493; 494; … ; 737; 738;;]
 [739; 740; … ; 983; 984;;]
 [985; 986; … ; 1229; 1230;;]
Dict{String, Any} with 6 entries:
  "DataType"      => "single univariate vector (1 sequence)"
  "TotalWindows"  => 5
  "WindowOverlap" => 0
  "Mode"          => "exclude"
  "WindowLength"  => 246
  "DataLength"    => 1234

Repeat the previous step, but this time retain any remaining samples that do not fill the last window.

WinData, Log = WindowData(1:1234, Mode="include");
6-element Vector{Any}:
 [1; 2; … ; 245; 246;;]
 [247; 248; … ; 491; 492;;]
 [493; 494; … ; 737; 738;;]
 [739; 740; … ; 983; 984;;]
 [985; 986; … ; 1229; 1230;;]
 [1231; 1232; 1233; 1234;;]
Dict{String, Any} with 6 entries:
  "DataType"      => "single univariate vector (1 sequence)"
  "TotalWindows"  => 5
  "WindowOverlap" => 0
  "Mode"          => "exclude"
  "WindowLength"  => 246
  "DataLength"    => 1234

Note that the last vector in WinData contains only 4 values.

4×1 Matrix{Int64}:
 1231
 1232
 1233
 1234

_______________________________________________________________________________

Ex. 3

Generate a multivariate dataset of 5 uniformly-distributed random number sequences (N=3333) and divide the dataset into subsets of 777 samples.

using Random
X = rand(MersenneTwister(0), 3333, 5)
WinData, Log = WindowData(X, WinLen = 777)
4-element Vector{Any}:
 [0.8236475079774124 0.3167135211361438 … 0.030676289511771815 0.5151261154510727; 0.9103565379264364 0.8745566924139507 … 0.037218800526782836 0.6593641734555802; … ; 0.7811116853756865 0.07254990318837007 … 0.5311522478040649 0.20016734188173713; 0.36558550033238424 0.3615030467534581 … 0.3388216421494432 0.09345021938930298]
 [0.6392060319799393 0.4769078401021005 … 0.03056916093918094 0.8148753431664593; 0.10117462252583387 0.7094973746688977 … 0.8417567709149247 0.8606069518198929; … ; 0.24835642716873307 0.9628845906397601 … 0.6895610694344338 0.571321569689375; 0.9977556689034139 0.0714798031505417 … 0.05748328493531818 0.9212882854001856]
 [0.21434411474067172 0.3486640479231402 … 0.20731809619227604 0.5344048192502102; 0.6900476056717384 0.46536991556135465 … 0.25800028114194706 0.09469853772958725; … ; 0.8971522988627398 0.41650011271354614 … 0.9150435373540216 0.4288696954764304; 0.44365826980862466 0.5420872128698995 … 0.7383540072064789 0.21423573479757252]
 [0.20209454184168374 0.8187257080563428 … 0.21732125310159334 0.38915700545993137; 0.6215565652122805 0.7018564844114248 … 0.4227657642202751 0.42462790058750377; … ; 0.9989204297817524 0.6951341832387776 … 0.8581526880246708 0.907986877805709; 0.19347672024016238 0.2133188501363834 … 0.12105991595762178 0.1440333715864257]
Dict{String, Any} with 6 entries:
  "DataType"      => "multivariate matrix (5 vectors)"
  "TotalWindows"  => 4
  "WindowOverlap" => 0
  "Mode"          => "exclude"
  "WindowLength"  => 777
  "DataLength"    => 3333

Repeat the previous step including 55 samples of overlap and retain any remaining samples that do not fill a window.

WinData, Log = WindowData(X, WinLen = 777, Overlap = 55, Mode = "include")
5-element Vector{Any}:
 [0.8236475079774124 0.3167135211361438 … 0.030676289511771815 0.5151261154510727; 0.9103565379264364 0.8745566924139507 … 0.037218800526782836 0.6593641734555802; … ; 0.7811116853756865 0.07254990318837007 … 0.5311522478040649 0.20016734188173713; 0.36558550033238424 0.3615030467534581 … 0.3388216421494432 0.09345021938930298]
 [0.4268090051873512 0.6296341653161006 … 0.26183951042661713 0.8588480955288058; 0.19683964923205655 0.5640981542542767 … 0.229520925481834 0.34502114218984614; … ; 0.845828658397995 0.3322642377283018 … 0.2582097309700917 0.17804611290659644; 0.4047854349485651 0.9426563027536123 … 0.34187055381905984 0.18084814047159292]
 [0.7254150710554719 0.8794330895048859 … 0.16861540094825034 0.11719698074155782; 0.9274755797309919 0.7690101648879515 … 0.6340294404293674 0.31696379431841315; … ; 0.6803043037039826 0.791083867230056 … 0.571418041726484 0.13882509731298098; 0.08746615164581018 0.5319143419387751 … 0.8776681064733247 0.8306151173374101]
 [0.09072602349143932 0.7271925706956666 … 0.3599007468117128 0.26959074779686554; 0.08253701800244162 0.6580671324720018 … 0.9591447619292577 0.8548444070969661; … ; 0.6984217110411444 0.15831033319749088 … 0.26362961784715666 0.5306749401932338; 0.9732853504220447 0.9249005761056093 … 0.2230679319611475 0.6532956983543834]
 [0.9748344532097626 0.4341016379629772 … 0.3239116081492075 0.14634590879516218; 0.6738357601455445 0.04448042771454497 … 0.31849036383092955 0.5427449788998076; … ; 0.31888456079799044 0.22265061369762784 … 0.10498156010916482 0.6906831340517614; 0.5109473378391427 0.6124580362466203 … 0.8086206527041544 0.03622180657390639]
Dict{String, Any} with 6 entries:
  "DataType"      => "multivariate matrix (5 vectors)"
  "TotalWindows"  => 5
  "WindowOverlap" => 55
  "Mode"          => "include"
  "WindowLength"  => 777
  "DataLength"    => 3333