Skip to contents

The purpose of this vignette is to present the calculations of the costs for various univariate distributions where for each time step there are multiple independent observations.

In the follow variables identified by Greek letters are considered known a priori.

Univariate Gaussian

Data belongs to group kk whose time stamps are the set TkT_{k} can have additive mean anomaly mkm_{k} and multiplicative variance anomaly sks_{k} which are common for tTkt \in T_{k}. For tTkt \in T_{k}. At time step tt the vector of iid observations 𝐲t={yt,1,,tt,nt}\mathbf{y}_{t}=\left\{y_{t,1},\ldots,t_{t,n_{t}}\right\} is made. The probability of of yt,iy_{t,i} is P(yt|μt,mk,σk,sk)=12πσtskexp(12σtsk(ytμtmk)2) P\left(y_t \left| \mu_t,m_k,\sigma_k,s_k\right.\right) = \frac{1}{\sqrt{2\pi\sigma_{t}s_{k}}}\exp\left(-\frac{1}{2\sigma_{t}s_{k}}\left(y_{t} - \mu_t - m_{k}\right)^2\right)

with the likelihood of of the ntn_{t} observations in 𝐲t\mathbf{y}_{t} being L(𝐲t|μt,mk,σk,sk)=(2πsk)nt/2σtnt/2exp(12skσti=1nt(yt,iμtmk)2) L\left(\mathbf{y}_{t} \left| \mu_t,m_k,\sigma_k,s_k\right.\right) = \left(2\pi s_{k}\right)^{-n_{t}/2} \sigma_{t}^{-n_{t}/2} \exp\left(-\frac{1}{2s_{k}\sigma_{t}}\sum\limits_{i=1}^{n_{t}} \left(y_{t,i} - \mu_t - m_{k}\right)^{2}\right) or as a log likelihood l(𝐲t|μt,mk,σk,sk)=nt2log(2πsk)nt2log(σt)12skσti=1nt(yt,iμtmk)2 l\left(\mathbf{y}_{t} \left| \mu_t,m_k,\sigma_k,s_k\right.\right) = -\frac{n_{t}}{2}\log\left(2\pi s_{k}\right) -\frac{n_{t}}{2}\log\left(\sigma_{t}\right) -\frac{1}{2s_{k}\sigma_{t}}\sum\limits_{i=1}^{n_{t}} \left(y_{t,i} - \mu_t - m_{k}\right)^{2}

The log-likelihood of 𝐲tTk\mathbf{y}_{t \in T_{k}} is with nk=tTkntn_{k}=\sum\limits_{t\in T_{k}} n_{t}l(𝐲tTk|μt,mk,σk,sk)=nk2log(2πsk)12tTkntlog(σt)12sktTki=1nt(yt,iμtmk)2σt l\left(\mathbf{y}_{t \in T_{k}} \left| \mu_t,m_k,\sigma_k,s_k\right.\right) = -\frac{n_{k}}{2} \log\left(2\pi s_{k}\right) -\frac{1}{2}\sum\limits_{t \in T_{k}} n_{t}\log\left(\sigma_{t}\right) -\frac{1}{2s_{k}}\sum\limits_{t \in T_{k}} \frac{\sum_{i=1}^{n_{t}}\left(y_{t,i} - \mu_t - m_{k}\right)^2}{\sigma_{t}}

with the cost being twice the negative log likelihood plus a penalty β\beta giving

C(𝐲tTk|μt,mk,σk,sk)=nklog(2πsk)+tTkntlog(σt)+1sktTki=1nt(yt,iμtmk)2σt+β C\left(\mathbf{y}_{t \in T_{k}} \left| \mu_t,m_k,\sigma_k,s_k\right.\right) = n_{k} \log\left(2\pi s_{k}\right) +\sum\limits_{t \in T_{k}} n_{t}\log\left(\sigma_{t}\right) +\frac{1}{s_{k}}\sum\limits_{t \in T_{k}} \frac{\sum_{i=1}^{n_{t}}\left(y_{t,i} - \mu_t - m_{k}\right)^2}{\sigma_{t}} +\beta

Anomaly in mean and varinace

Estimates m̂\hat{m} of mm and σ̂\hat{\sigma} of σ\sigma can be selected to minimise the cost by taking m̂k=(tTki=1nt(ytμt)σt)(tTkntσt)1 \hat{m}_{k} = \left( \sum\limits_{t \in T_k} \frac{\sum\limits_{i=1}^{n_t} \left(y_t-\mu_t\right)}{\sigma_t} \right)\left( \sum\limits_{t \in T_k} \frac{n_{t}}{\sigma_t}\right)^{-1} and ŝk=1nktTki=1nt(yt,iμtm̂k)2σt \hat{s}_{k} = \frac{1}{n_{k}} \sum\limits_{t \in T_{k}} \frac{\sum_{i=1}^{n_{t}}\left(y_{t,i} - \mu_t - \hat{m}_{k}\right)^2}{\sigma_{t}}

Anomaly in Mean

There is no change in variance so sk=1s_{k}=1. Estimate of m̂k\hat{m}_{k} is unchanged from that for an anomaly in mean and variance.

Anomaly in Variance

These is no mean anomaly so mk=0m_{k}=0. Estimate of ŝk\hat{s}_{k} therfore changes to

ŝk=1nktTki=1nt(yt,iμt)2σt \hat{s}_{k} = \frac{1}{n_{k}} \sum\limits_{t \in T_{k}} \frac{\sum_{i=1}^{n_{t}}\left(y_{t,i} - \mu_t\right)^2}{\sigma_{t}}

No Anomaly (Baseline)

Here mk=0m_{k}=0 and sk=1s_{k}=1 and there is no penalty so β=0\beta = 0

Point anomaly

Assuming at for all tt there are at least 2 unique values there is no need to represent a point in time differently [Check].