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
Get the length of time series
Method new()
Initialise the cost function
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
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