A-quick-tour-of-tMoE

Introduction

TMoE (t Mixture-of-Experts) provides a flexible and robust modelling framework for heterogenous data with possibly heavy-tailed distributions and corrupted by atypical observations. TMoE consists of a mixture of K t expert regressors network (of degree p) gated by a softmax gating network (of degree q) and is represented by:

  • The gating network parameters alpha’s of the softmax net.
  • The experts network parameters: The location parameters (regression coefficients) beta’s, scale parameters sigma’s, and the degree of freedom (robustness) parameters nu’s. TMoE thus generalises mixtures of (normal, t, and) distributions and mixtures of regressions with these distributions. For example, when q = 0, we retrieve mixtures of (t-, or normal) regressions, and when both p = 0 and q = 0, it is a mixture of (t-, or normal) distributions. It also reduces to the standard (normal, t) distribution when we only use a single expert (K = 1).

Model estimation/learning is performed by a dedicated expectation conditional maximization (ECM) algorithm by maximizing the observed data log-likelihood. We provide simulated examples to illustrate the use of the model in model-based clustering of heterogeneous regression data and in fitting non-linear regression functions.

It was written in R Markdown, using the knitr package for production.

See help(package="meteorits") for further details and references provided by citation("meteorits").

Application to a simulated dataset

Generate sample

n <- 500 # Size of the sample
alphak <- matrix(c(0, 8), ncol = 1) # Parameters of the gating network
betak <- matrix(c(0, -2.5, 0, 2.5), ncol = 2) # Regression coefficients of the experts
sigmak <- c(0.5, 0.5) # Standard deviations of the experts
nuk <- c(5, 7) # Degrees of freedom of the experts network t densities
x <- seq.int(from = -1, to = 1, length.out = n) # Inputs (predictors)

# Generate sample of size n
sample <- sampleUnivTMoE(alphak = alphak, betak = betak, sigmak = sigmak, 
                         nuk = nuk, x = x)
y <- sample$y

Set up tMoE model parameters

K <- 2 # Number of regressors/experts
p <- 1 # Order of the polynomial regression (regressors/experts)
q <- 1 # Order of the logistic regression (gating network)

Set up EM parameters

n_tries <- 1
max_iter <- 1500
threshold <- 1e-5
verbose <- TRUE
verbose_IRLS <- FALSE

Estimation

tmoe <- emTMoE(X = x, Y = y, K, p, q, n_tries, max_iter, 
               threshold, verbose, verbose_IRLS)
## EM - tMoE: Iteration: 1 | log-likelihood: -519.677439103998
## EM - tMoE: Iteration: 2 | log-likelihood: -516.114334429722
## EM - tMoE: Iteration: 3 | log-likelihood: -516.005697045179
## EM - tMoE: Iteration: 4 | log-likelihood: -515.939962874608
## EM - tMoE: Iteration: 5 | log-likelihood: -515.885727421891
## EM - tMoE: Iteration: 6 | log-likelihood: -515.841142834344
## EM - tMoE: Iteration: 7 | log-likelihood: -515.804726940633
## EM - tMoE: Iteration: 8 | log-likelihood: -515.775144222188
## EM - tMoE: Iteration: 9 | log-likelihood: -515.751215825909
## EM - tMoE: Iteration: 10 | log-likelihood: -515.731921007796
## EM - tMoE: Iteration: 11 | log-likelihood: -515.716389860516
## EM - tMoE: Iteration: 12 | log-likelihood: -515.703890629095
## EM - tMoE: Iteration: 13 | log-likelihood: -515.693814283551
## EM - tMoE: Iteration: 14 | log-likelihood: -515.685658254326
## EM - tMoE: Iteration: 15 | log-likelihood: -515.679010587451
## EM - tMoE: Iteration: 16 | log-likelihood: -515.673535275266
## EM - tMoE: Iteration: 17 | log-likelihood: -515.668959156278

Summary

tmoe$summary()
## -------------------------------------
## Fitted t Mixture-of-Experts model
## -------------------------------------
## 
## tMoE model with K = 2 experts:
## 
##  log-likelihood df      AIC      BIC       ICL
##        -515.669 10 -525.669 -546.742 -546.7941
## 
## Clustering table (Number of observations in each expert):
## 
##   1   2 
## 249 251 
## 
## Regression coefficients:
## 
##     Beta(k = 1) Beta(k = 2)
## 1     0.2347551   0.2381667
## X^1   2.9508550  -2.7210875
## 
## Variances:
## 
##  Sigma2(k = 1) Sigma2(k = 2)
##       0.328381      0.449833

Plots

Mean curve

tmoe$plot(what = "meancurve")

Confidence regions

tmoe$plot(what = "confregions")

Clusters

tmoe$plot(what = "clusters")

Log-likelihood

tmoe$plot(what = "loglikelihood")

Application to a real dataset

Load data

library(MASS)
data("mcycle")
x <- mcycle$times
y <- mcycle$accel

Set up tMoE model parameters

K <- 4 # Number of regressors/experts
p <- 2 # Order of the polynomial regression (regressors/experts)
q <- 1 # Order of the logistic regression (gating network)

Set up EM parameters

n_tries <- 1
max_iter <- 1500
threshold <- 1e-5
verbose <- TRUE
verbose_IRLS <- FALSE

Estimation

tmoe <- emTMoE(X = x, Y = y, K, p, q, n_tries, max_iter, 
               threshold, verbose, verbose_IRLS)
## EM - tMoE: Iteration: 1 | log-likelihood: -584.468701612805
## EM - tMoE: Iteration: 2 | log-likelihood: -583.004241703923
## EM - tMoE: Iteration: 3 | log-likelihood: -582.237190143091
## EM - tMoE: Iteration: 4 | log-likelihood: -579.613264923929
## EM - tMoE: Iteration: 5 | log-likelihood: -571.102261874635
## EM - tMoE: Iteration: 6 | log-likelihood: -563.377313815634
## EM - tMoE: Iteration: 7 | log-likelihood: -560.100228008728
## EM - tMoE: Iteration: 8 | log-likelihood: -559.295469502271
## EM - tMoE: Iteration: 9 | log-likelihood: -558.669332079947
## EM - tMoE: Iteration: 10 | log-likelihood: -557.883985927263
## EM - tMoE: Iteration: 11 | log-likelihood: -556.922581657812
## EM - tMoE: Iteration: 12 | log-likelihood: -555.858023747862
## EM - tMoE: Iteration: 13 | log-likelihood: -554.877709603886
## EM - tMoE: Iteration: 14 | log-likelihood: -554.040475372863
## EM - tMoE: Iteration: 15 | log-likelihood: -553.295572904683
## EM - tMoE: Iteration: 16 | log-likelihood: -552.641569257208
## EM - tMoE: Iteration: 17 | log-likelihood: -552.10517985029
## EM - tMoE: Iteration: 18 | log-likelihood: -551.699919041098
## EM - tMoE: Iteration: 19 | log-likelihood: -551.414517028097
## EM - tMoE: Iteration: 20 | log-likelihood: -551.222825421481
## EM - tMoE: Iteration: 21 | log-likelihood: -551.097415577266
## EM - tMoE: Iteration: 22 | log-likelihood: -551.016297700792
## EM - tMoE: Iteration: 23 | log-likelihood: -550.963941718457
## EM - tMoE: Iteration: 24 | log-likelihood: -550.930037867418
## EM - tMoE: Iteration: 25 | log-likelihood: -550.907937695115
## EM - tMoE: Iteration: 26 | log-likelihood: -550.893404251337
## EM - tMoE: Iteration: 27 | log-likelihood: -550.88374492561
## EM - tMoE: Iteration: 28 | log-likelihood: -550.877245291976
## EM - tMoE: Iteration: 29 | log-likelihood: -550.872809090118

Summary

tmoe$summary()
## -------------------------------------
## Fitted t Mixture-of-Experts model
## -------------------------------------
## 
## tMoE model with K = 4 experts:
## 
##  log-likelihood df       AIC       BIC       ICL
##       -550.8728 26 -576.8728 -614.4473 -614.4432
## 
## Clustering table (Number of observations in each expert):
## 
##  1  2  3  4 
## 28 37 31 37 
## 
## Regression coefficients:
## 
##      Beta(k = 1) Beta(k = 2)  Beta(k = 3) Beta(k = 4)
## 1   -1.050213173 1039.467239 -1861.769283 303.4817385
## X^1 -0.101021184 -109.128790   115.264042 -12.6175636
## X^2 -0.008737247    2.574298    -1.738354   0.1294753
## 
## Variances:
## 
##  Sigma2(k = 1) Sigma2(k = 2) Sigma2(k = 3) Sigma2(k = 4)
##       1.659401      418.1015      514.9683       510.959

Plots

Mean curve

tmoe$plot(what = "meancurve")

Confidence regions

tmoe$plot(what = "confregions")

Clusters

tmoe$plot(what = "clusters")

Log-likelihood

tmoe$plot(what = "loglikelihood")