sufficientStatistics_Weighted.LinearGaussianGaussian {bbricks} R Documentation

## Weighted sufficient statistics of a "LinearGaussianGaussian" object

### Description

For following model structure:

x \sim Gaussian(A z + b, Sigma)

z \sim Gaussian(m,S)

Where Sigma is known. A is a dimx x dimz matrix, x is a dimx x 1 random vector, z is a dimz x 1 random vector, b is a dimm x 1 vector. Gaussian() is the Gaussian distribution. See `?dGaussian` for the definition of Gaussian distribution.
For weight vector w and one dimensional observations: x is a vector of length N, or a N x 1 matrix, each row is an observation, must satisfy nrow(x)=length(w); A is a N x dimz matrix; b is a length N vector. The sufficient statistics are:

• SA = A^T (A w) / Sigma

• SAx = A^T ((x-b) w) / Sigma

For weight vector w and dimx dimensional observations: x must be a N x m matrix, each row is an observation, must satisfy nrow(x)=length(w); A can be either a list or a matrix. When A is a list, A = {A_1,A_2,...A_N} is a list of dimx x dimz matrices. If A is a single dimx x dimz matrix, it will be replicated N times into a length N list; b can be either a matrix or a vector. When b is a matrix, b={b_1^T,...,b_N^T} is a N x dimx matrix, each row is a transposed vector. When b is a length dimx vector, it will be transposed into a row vector and replicated N times into a N x dimx matrix. The sufficient statistics are:

• SA = sum_{i=1:N} w_i A_i^T Sigma^{-1} A_i

• SAx = sum_{i=1:N} w_i A_i^T Sigma^{-1} (x_i-b_i)

### Usage

```## S3 method for class 'LinearGaussianGaussian'
sufficientStatistics_Weighted(obj, x, w, A, b = NULL, foreach = FALSE, ...)
```

### Arguments

 `obj` A "LinearGaussianGaussian" object. `x` matrix, Gaussian samples, when x is a matrix, each row is a sample of dimension ncol(x). when x is a vector, x is length(x) samples of dimension 1. `w` numeric, sample weights. `A` matrix or list. when x is a N x 1 matrix, A must be a matrix of N x dimz, dimz is the dimension of z; When x is a N x dimx matrix, where dimx > 1, A can be either a list or a matrix. When A is a list, A = {A_1,A_2,...A_N} is a list of dimx x dimz matrices. If A is a single dimx x dimz matrix, it will be replicated N times into a length N list `b` matrix, when x is a N x 1 matrix, b must also be a N x 1 matrix or length N vector; When x is a N x dimx matrix, where dimx > 1, b can be either a matrix or a vector. When b is a matrix, b={b_1^T,...,b_N^T} is a N x dimx matrix, each row is a transposed vector. When b is a length dimx vector, it will be transposed into a row vector and replicated N times into a N x dimx matrix. When b = NULL, it will be treated as a vector of zeros. Default NULL. `foreach` logical, specifying whether to return the sufficient statistics for each observation. Default FALSE. `...` Additional arguments to be passed to other inherited types.

### Value

If foreach=TRUE, will return a list of sufficient statistics for each row of x, otherwise will return the sufficient statistics of x as a whole.

### References

Murphy, Kevin P. Machine learning: a probabilistic perspective. MIT press, 2012.

`LinearGaussianGaussian`, `sufficientStatistics.LinearGaussianGaussian`

### Examples

```obj <- LinearGaussianGaussian(gamma=list(Sigma=matrix(c(2,1,1,2),2,2),m=c(0.2,0.5,0.6),S=diag(3)))
x <- rGaussian(100,mu = runif(2),Sigma = diag(2))
w <- runif(100)
A <- matrix(runif(6),2,3)
b <- runif(2)
sufficientStatistics_Weighted(obj,x=x,w=w,A=A,b=b)
sufficientStatistics_Weighted(obj,x=x,w=w,A=A,b=b,foreach = TRUE)
```

[Package bbricks version 0.1.4 Index]