time-series-0.1.0.0: Time series analysis.

Portabilitynon-portable
Stabilityexperimental
Safe HaskellNone

TimeSeries.Routing

Contents

Description

Data routing for time series analysis.

Synopsis

Types

data Config Source

Configuration values for detecting correlations from uncooperative time series data.

This data type shall relate to bootstrapping in future, but at the moment, nothing related.

Constructors

Config 

Fields

sketchSize :: Int

Number of random elements in sketch.

sketchGroups :: Word8

Number of subsequences for grouping sketch.

corrCutoff :: Double

Cutoff value between of correlation, between 0 to 1.

swSize :: Word64

Size of sliding window.

bwSize :: Word64

Size of basic window.

randSeed :: Integer

Seed for random vectors.

impls :: Implementation

Implementation.

verbose :: Bool

To show trace output or not.

Instances

type BasicWindows = IntMap (Seq Window)Source

Representing basic windows as IntMap of Seq of Windows.

Key of outer IntMap is ID for concurrent input stream, number of keys matches to number of concurrent input stream. Inner Seq is indexed basic window within sliding window, number of elements matches to nb, where `nb = sw bw`, sw/ is sliding window size and bw is basic window size.

data Summary Source

Summary of sliding window.

We don't need to maintain whole basic windows when sketch implementation is the only concern. To show correlation values with direct function, preserving the whole basic window contents. From "3.5 The Issues in Implementation section":

... We need to maintain

  • ∑i=0,nb-1(sum(Xbwⁱ))
  • ∑i=0,nb-1(sum((Xbwⁱ)²))

for a sliding window ...

Constructors

Summary 

Fields

smrSum :: Double

Sum of elements in sliding window. In other words, ∑i=0,nb-1(sum(Xbwⁱ)).

smrSumSq :: Double

Sum of squared elements in sliding window. In other words, ∑i=0,nb-1(sum((Xbwⁱ)²).

smrSketch :: Window

Sketch vector, size of this window matches to sketch size.

smrPreSketches :: [Window]

Pre-sketches. "Pre" means that those sketch values before applying dot product with control vector.

smrBasicWindows :: Seq BWSummary

Summaries for basic windows, length of Seq is nb, where nb = sliding_window_size / basic_window_size.

Instances

data BWSummary Source

Summary of basic window.

From "3.5 The Issues in Implementation section":

... We need to maintain

  • Xbwⁱ⋅R
  • sum(Xbwⁱ)
  • sum((Xbwⁱ)²)

for each basic window.

Constructors

BWSummary 

Fields

bwSketch :: Window

Sketch of basic window, currently not in use.

bwsSum :: Double

Sum of elements in basic window.

bwsSumSq :: Double

Sum of squared elements in basic window.

data SysState Source

State stored in analysis system.

Later this shall relate to memory data in hardware implementation, but at the moment its 100% Haskell data type and values.

Instances

data CorrResult Source

Result of correlation analysis.

Inspired from output found in "statStream". See:

Constructors

CorrResult 

Fields

crIndexA :: Int

Index of time series input A.

crIndexB :: Int

Index of time series input B.

crStartTime :: Word64

Start time of base window.

crEndTime :: Word64

crTimeStart + (size of base window)

crValue :: Double

A value between -1 to 1.

data Implementation Source

Implementations.

As for a prototype, used to analyse and compre resulting values for different implementations.

Constructors

Direct

Direct correlation computation.

Sketch

Sketch based computation.

newtype Loop a Source

Loop for analysing correlation of input data and updating analysis results and windowed data.

Constructors

Loop 

Fields

unLoop :: StateT SysState (Writer [Either String CorrResult]) a
 

Instances

Monad Loop 
Functor Loop 
MonadState SysState Loop 
MonadWriter [Either String CorrResult] Loop 

Looping actions

Looping with State and Writer.

loopSource

Arguments

:: Handle

Where to show results.

-> Config

Configuration values used for computation.

-> [[Double]]

Input values.

-> IO () 

The main loop of time series analysis.

Specifying number of concurrent time series data in this function. In hardware implementation, this may relates to fixed value, which possibly been configured at the time of code generation.

runLoop :: Loop a -> SysState -> ((a, SysState), [Either String CorrResult])Source

Unwrap Loop, run internal State and Writer.

step :: Config -> [Double] -> Loop ()Source

Single step to take with new input data.

Handle state management and if found any, report analysis result.

filterImplSource

Arguments

:: Implementation

Which result to choose.

-> Double

Cutoff value.

-> (CorrResult, CorrResult)

(Direct correlation result, sketch correlation result).

-> [CorrResult] 

Filter results with implementation and cutoff value.

corrPermuteSource

Arguments

:: Word64

System current time. ... What is the time format used in hardware implementation?

-> Word64

Basic window size.

-> Word64

Sliding window size.

-> BasicWindows

Basic windows.

-> IntMap Summary

Summary for each input stream.

-> [(CorrResult, CorrResult)]

Direct result and sketch result.

Compute correlations.

slidingWindow :: Word64 -> BasicWindows -> IntMap WindowSource

Struct sliding windows from basic windows.

This function is not needed in hardware implementation, should used for direct calculation only.

updateStates :: [Double] -> Loop ()Source

Adding new elements to windows, removing old elements.

consBWSource

Arguments

:: Seq Window

Singleton Seq of singleton Window.

-> Seq Window

Basic windows in system status.

-> Seq Window 

Append first argument to second argument.

updateSummariesAndShift :: Loop ()Source

Update sum of elements in sliding window, and sum of squared elements in sliding window, and shift contents of basic windows.

rotateSeq :: a -> Seq a -> Seq aSource

Cons given element to given Seq and remove last element in Seq.

Initial values

initialSysState :: Config -> Int -> SysStateSource

Initial state.

Other than Config, number of concurrent time series input data is passed.

initialSummariesSource

Arguments

:: Config

Main configuration.

-> Int

Number of concurrent input streams.

-> IntMap Summary 

initialBWSummarySource

Arguments

:: Size

Sketch size.

-> BWSummary 

Initial basic window summary data.

randomVectorsSource

Arguments

:: Integer

Random seed.

-> Size

Basic window size.

-> Size

Sliding window size.

-> Int

Sketch size.

-> IntMap RandomVector 

Initial random vectors.

Pretty printer

Actually, not much pretty.

simpleCorrResult :: CorrResult -> StringSource

Simplified string representation of CorrResult.

>>> simpleCorrResult (CorrResult 1 2 10 20 0.5)
"1, 2, 10, 20, 0.5"