Skip to contents

Cost functions for the multinomial distribution

Details

Collective anomalies are represented as chnages to the expected proportions. Time varying expected proportions are currently not handled.

Methods


Method length()

Get the length of time series

Usage

categoricalCost$length()


Method new()

Initialise the cost function

Usage

categoricalCost$new(x, m = rep(1/ncol(x), ncol(x)))

Arguments

x

integer matrix of observations of 0,1

m

numeric vector of expected proportions ## need to check row sums are 1 - possibly just use multinomial??


Method baseCost()

Compute the non-anomalous cost of a segment

Usage

categoricalCost$baseCost(a, b, pen = 0)

Arguments

a

start of period

b

end of period

pen

penalty cost


Method pointCost()

Compute the point anomaly cost of a time step

Usage

categoricalCost$pointCost(b, pen)

Arguments

b

time step

pen

penalty cost


Method collectiveCost()

Compute the anomalous cost of a segment

Usage

categoricalCost$collectiveCost(a, b, pen, len)

Arguments

a

start of period

b

end of period

pen

penalty cost

len

minimum number of observations


Method param()

Compute parameters of a segment if anomalous

Usage

categoricalCost$param(a, b)

Arguments

a

start of period

b

end of period


Method clone()

The objects of this class are cloneable with this method.

Usage

categoricalCost$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

set.seed(0)
m <- c(1:4)/sum(1:4)
X <- t(rmultinom(100, 1, m))

p <- categoricalCost$new(X,m)
p$baseCost(90,95) ## cost of non-anomalous distribution for x[90:95]
#> [1] 14.91881
p$pointCost(90,0) ## point anomaly cost for x[90] with 0 penalty
#> [1] 0
## collective anomaly cost for x[90:95] with penalty of 57 and at least 3 observation
p$collectiveCost(90,95,57,3)
#> [1] 69.13685