Documentation ¶
Index ¶
- Constants
- func Avg(b TimeWindowView) float64
- func Rat(b TimeWindowView) float64
- type BatchWindow
- type Bucket
- type Buffer
- type Data
- type HMM
- type HMMConfig
- type HistoryWindow
- func (h HistoryWindow) Buffer(index int, extract func(b TimeWindowView) float64) ([]float64, error)
- func (h HistoryWindow) Extract(index int, extract func(b TimeWindowView) float64) ([]float64, []float64, error)
- func (h HistoryWindow) Get(transform TimeBucketTransform) []interface{}
- func (h HistoryWindow) Polynomial(index int, extract func(b TimeWindowView) float64, degree int, trace bool) ([]float64, []float64, []float64, error)
- func (h HistoryWindow) Push(t time.Time, v ...float64) (TimeBucket, bool)
- func (h HistoryWindow) Raw() WindowStatus
- func (h HistoryWindow) String() string
- func (h HistoryWindow) Values(index int, extract func(b TimeWindowView) float64) ([]float64, error)
- type IntervalWindow
- func (iw *IntervalWindow) Close() error
- func (iw *IntervalWindow) Flush()
- func (iw *IntervalWindow) Push(t time.Time, v ...float64)
- func (iw *IntervalWindow) WithEcho() *IntervalWindow
- func (iw *IntervalWindow) WithInterval(interval int) *IntervalWindow
- func (iw *IntervalWindow) WithLimit(limit int) *IntervalWindow
- type MultiBuffer
- type Prediction
- type PredictionList
- type Predictions
- type Ring
- type Sequence
- type StackOfStats
- type State
- type Stats
- func (s Stats) Avg() float64
- func (s Stats) Count() int
- func (s Stats) Diff() float64
- func (s Stats) EMA() float64
- func (s *Stats) Push(v float64)
- func (s Stats) Range() (float64, float64)
- func (s Stats) Ratio() float64
- func (s Stats) SampleStDev() float64
- func (s Stats) SampleVariance() float64
- func (s Stats) Size() int
- func (s Stats) StDev() float64
- func (s Stats) Sum() float64
- func (s Stats) Variance() float64
- type StatsCollector
- type StatsMessage
- type Status
- type TimeBucket
- type TimeBucketTransform
- type TimeWindow
- type TimeWindowView
- type Transform
- type Window
- type WindowStatus
Constants ¶
const Delimiter = "|"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BatchWindow ¶
type BatchWindow struct { Window *IntervalWindow `json:"Window"` // contains filtered or unexported fields }
BatchWindow is a window struct that gathers the passed `x` elements from an IntervalWindow.
func NewBatchWindow ¶
func NewBatchWindow(id string, dim int, duration time.Duration, size int) (*BatchWindow, <-chan []StatsMessage)
NewBatchWindow creates a new batch window.
func (*BatchWindow) Push ¶
func (bw *BatchWindow) Push(t time.Time, v ...float64)
Push adds an element to the given time Index. It will return true, if there was a new bucket completed at the last operation
func (*BatchWindow) WithEcho ¶
func (bw *BatchWindow) WithEcho() *BatchWindow
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket groups together stats collectors with the same Index
func (*Bucket) Push ¶
Push adds an element to the bucket for the given Index. it returns true if the bucket has the right Index, false otherwise. This allows to build higher level abstractions i.e. Window etc ...
func (Bucket) Values ¶
func (b Bucket) Values() StatsCollector
Values returns the bucket StatsCollector for the bucket.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer defines a simple float buffer that acts like a constant size queue
func (*Buffer) GetAsFloats ¶
GetAsFloats returns the buffer elements in the order they were added.
func (*Buffer) GetAsStrings ¶
GetAsStrings returns the buffer elements in the order they were added.
type HMM ¶
type HMM struct { Config []HMMConfig `json:"config"` State map[Sequence]map[Sequence]State `json:"state"` Status Status `json:"status"` // contains filtered or unexported fields }
HMM counts occurrences in a sequence of strings. It implements effectively several hidden markov model of the n-grams lengths provided in the Config.
func HMMFromState ¶
HMMFromState creates a new model from a previous one.
type HMMConfig ¶
type HMMConfig struct { IgnoreValues []string `json:"ignore"` LookBack int `json:"lookback"` LookAhead int `json:"lookahead"` }
HMMConfig defines the configuration for the hidden markov model analysis.
func NewHMMConfig ¶
type HistoryWindow ¶
type HistoryWindow struct { Window TimeWindow `json:"Window"` // contains filtered or unexported fields }
HistoryWindow keeps the last x buckets based on the Window interval given
func NewHistoryWindow ¶
func NewHistoryWindow(duration time.Duration, size int) HistoryWindow
NewHistoryWindow creates a new history Window.
func (HistoryWindow) Buffer ¶
func (h HistoryWindow) Buffer(index int, extract func(b TimeWindowView) float64) ([]float64, error)
Buffer evaluates the elements of the current buffer
func (HistoryWindow) Extract ¶
func (h HistoryWindow) Extract(index int, extract func(b TimeWindowView) float64) ([]float64, []float64, error)
Extract extracts the bucket values as a series
func (HistoryWindow) Get ¶
func (h HistoryWindow) Get(transform TimeBucketTransform) []interface{}
Get returns the transformed bucket value at the corresponding Index. TODO : change the signature to act like json.Decode etc... so that we control the appending of properties on our own
func (HistoryWindow) Polynomial ¶
func (h HistoryWindow) Polynomial(index int, extract func(b TimeWindowView) float64, degree int, trace bool) ([]float64, []float64, []float64, error)
Polynomial evaluates the polynomial regression for the given polynomial degree and based on the value extracted from the TimeBucket scaled at the corresponding time duration.
func (HistoryWindow) Push ¶
func (h HistoryWindow) Push(t time.Time, v ...float64) (TimeBucket, bool)
Push adds an element to the given time Index. It will return true, if there was a new bucket completed at the last operation
func (HistoryWindow) Raw ¶
func (h HistoryWindow) Raw() WindowStatus
func (HistoryWindow) String ¶
func (h HistoryWindow) String() string
func (HistoryWindow) Values ¶
func (h HistoryWindow) Values(index int, extract func(b TimeWindowView) float64) ([]float64, error)
Values returns the values of the time window in a slice
type IntervalWindow ¶
type IntervalWindow struct { ID string First time.Time `json:"first"` Last time.Time `json:"last"` Duration time.Duration `json:"duration"` Dim int `json:"dimensions"` // contains filtered or unexported fields }
IntervalWindow defines a struct that returns the stats for the given interval. It gathers events for the given interval and flushes them at the predefined duration. If no events are gathered the window will return a StatsMessage with the flag OK set to false. The WithEcho method can control the window behaviour to flush a valid StatsMessage even without an event, in this case the value of the last StatsMessage will be echoed with count of `0` WithLimit sets a limit for the window in terms of number of event WithInterval sets the interval for the window based on the time dimension The window can either operate as 'live' , with a limit or with an interval (TODO : enforce)
func NewIntervalWindow ¶
func NewIntervalWindow(id string, dim int, duration time.Duration) (*IntervalWindow, <-chan StatsMessage)
NewIntervalWindow creates a new IntervalWindow with the given Duration.
func (*IntervalWindow) Flush ¶
func (iw *IntervalWindow) Flush()
Flush flushes the current bucket contents
func (*IntervalWindow) Push ¶
func (iw *IntervalWindow) Push(t time.Time, v ...float64)
Push adds an element to the interval Window.
func (*IntervalWindow) WithEcho ¶
func (iw *IntervalWindow) WithEcho() *IntervalWindow
func (*IntervalWindow) WithInterval ¶
func (iw *IntervalWindow) WithInterval(interval int) *IntervalWindow
WithInterval sets a duration limit on the time dimension for a window to flush
func (*IntervalWindow) WithLimit ¶
func (iw *IntervalWindow) WithLimit(limit int) *IntervalWindow
WithLimit sets a limit on the number of events for a window to flush
type MultiBuffer ¶
type MultiBuffer struct {
// contains filtered or unexported fields
}
MultiBuffer defines a simple float slice buffer that acts like a constant size queue
func NewMultiBuffer ¶
func NewMultiBuffer(size int) *MultiBuffer
NewMultiBuffer creates a new buffer.
func (*MultiBuffer) Get ¶
func (b *MultiBuffer) Get() [][]float64
Get returns the buffer elements in the order they were added.
func (*MultiBuffer) GetReverse ¶
func (b *MultiBuffer) GetReverse() [][]float64
GetReverse returns the buffer elements in the reverse order they were added.
func (*MultiBuffer) Last ¶
func (b *MultiBuffer) Last() []float64
Last returns the last element in the buffer.
func (*MultiBuffer) Len ¶
func (b *MultiBuffer) Len() int
Len returns the current length of the buffer.
type Prediction ¶
type Prediction struct { // ID is a unique numeric id related to the prediction ID int64 // Value for the prediction . Essentially the concatenated string of the predicted sequence Value Sequence // Probability for the bucket prediction Probability float64 // EMP is the exponential moving probability e.g. on-the-fly calculated probability with integrated exponential decay EMP float64 // contains filtered or unexported fields }
Prediction defines a prediction result with the computed Probability
func NewPrediction ¶
func NewPrediction(s Sequence, st State) *Prediction
NewPrediction TODO : maybe better to choose a uuid, for now the unix second should be enough
func (*Prediction) String ¶
func (p *Prediction) String() string
type PredictionList ¶
type PredictionList []*Prediction
PredictionList is a sortable list of predictions
func (PredictionList) Len ¶
func (p PredictionList) Len() int
func (PredictionList) Less ¶
func (p PredictionList) Less(i, j int) bool
func (PredictionList) Swap ¶
func (p PredictionList) Swap(i, j int)
type Predictions ¶
type Predictions struct { Key Sequence // Values are the prediction details for each prediction Values PredictionList // Sample is the number of previous incidents of the source sequence that generated the bucket probability matrix Sample int // Groups is the number of groups / combinations of source sequences encountered of the given length. // TODO :assess the statistical significance of this Groups int // Count is the Count of invocations for this model Count int // Label is a string acting as metadata for the prediction Label string }
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring is a ring buffer keeping the last x elements TODO : use container/ring
type Sequence ¶
type Sequence string
Sequence defines a sequence of strings.
func NewSequence ¶
NewSequence creates a new sequence from a string
type StackOfStats ¶
type StackOfStats []Stats
func (StackOfStats) ToData ¶
func (sos StackOfStats) ToData() []Data
type Stats ¶
type Stats struct {
// contains filtered or unexported fields
}
Stats is a set of statistical properties of a set of numbers.
func (Stats) SampleStDev ¶
SampleStDev is the sample standard deviation of the set.
func (Stats) SampleVariance ¶
SampleVariance is the sample variance of the set.
type StatsCollector ¶
type StatsCollector struct {
// contains filtered or unexported fields
}
StatsCollector is a collection of Stats variables. This enabled multi-dimensional tracking.
func NewStatsCollector ¶
func NewStatsCollector(dim int) *StatsCollector
NewStatsCollector creates a new Stats collector.
func (*StatsCollector) Push ¶
func (sc *StatsCollector) Push(v ...float64)
Push pushes each value to the corresponding dimension.
func (*StatsCollector) Size ¶
func (sc *StatsCollector) Size() int
Size returns the size of the bucket.
func (StatsCollector) Stats ¶
func (sc StatsCollector) Stats() []*Stats
func (StatsCollector) String ¶
func (sc StatsCollector) String() string
type StatsMessage ¶
type StatsMessage struct { OK bool `json:"ok"` First time.Time `json:"first"` Init time.Time `json:"init"` Last time.Time `json:"last"` ID string `json:"id"` Duration time.Duration `json:"Duration"` Dim int `json:"Dimensions"` Stats []Stats `json:"-"` Data []Data `json:"data"` }
StatsMessage defines a stats message instance. It gathers stats and metadata for the aggregation of the provided values.
type Status ¶
type Status struct { Count int `json:"count"` Samples map[Sequence]map[Sequence]int `json:"sample"` }
Status reflects the bucket Status of the HMM it is the inverse map of the state
type TimeBucket ¶
TimeBucket is a wrapper for a bucket of a TimeWindow, that carries also the time Index.
type TimeBucketTransform ¶
type TimeBucketTransform func(bucket TimeBucket) interface{}
TimeBucketTransform is a operation acting on an TimeWindow slice.
func StatsWindow ¶
func StatsWindow(dim int) TimeBucketTransform
StatsWindow is a predefined TimeBucketTransform function that will gather the stats for the given dimensions.
func WindowDensity ¶
func WindowDensity() TimeBucketTransform
type TimeWindow ¶
type TimeWindow struct { Index int64 `json:"Index"` Duration int64 `json:"Duration"` // contains filtered or unexported fields }
TimeWindow is a Window indexed by the bucket time.
func NewTimeWindow ¶
func NewTimeWindow(duration time.Duration) TimeWindow
NewTimeWindow creates a new TimeWindow with the given Duration.
func (*TimeWindow) Bucket ¶
func (tw *TimeWindow) Bucket() TimeBucket
Bucket returns the current active bucket stats from the window.
func (*TimeWindow) Next ¶
func (tw *TimeWindow) Next(iterations int64) time.Time
Next returns the next timestamp for the coming Window.
func (*TimeWindow) Push ¶
func (tw *TimeWindow) Push(t time.Time, v ...float64) (TimeBucket, bool)
Push adds an element to the time Window. It will return true, if the last addition caused a bucket to close.
func (TimeWindow) String ¶
func (tw TimeWindow) String() string
type TimeWindowView ¶
type TimeWindowView struct { Time time.Time `json:"time"` Count int `json:"Count"` Value float64 `json:"value"` EMADiff float64 `json:"ema_diff"` Diff float64 `json:"diff"` Ratio float64 `json:"ratio"` StdDev float64 `json:"std"` Density int `json:"density"` }
TimeWindowView is a time specific but static snapshot on top of a StatsCollector. It allows to retrieve buckets of Stats from a streaming data set. the bucket indexing is based on the time.
func NewView ¶
func NewView(bucket TimeBucket, index int) TimeWindowView
NewView creates a new time view from a time bucket.
type Transform ¶
type Transform func(bucket interface{}) interface{}
Transform is a operation acting on an object and returning another one. Because users know what objects they work with, this abstraction makes sense for the bucket scope. Otherwise it's clear that this method is too generic to be used in another context.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window is a helper struct allowing grouping together Buckets of StatsCollectors for the given Index.
func NewWindow ¶
NewWindow creates a new Window of the given Window size e.g. the Index range for each bucket.
func (*Window) Push ¶
Push adds an element to a Window at the given Index. returns if the Window closed, e.g. if last element initiated a new bucket. (Note that based on this logic we ll only know when a Window closed only on the initiation of a new one) (Note that the Index must be increasing for this logic to work) NOTE : This is not a hashmap implementation !