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: -531.090390269623
## EM - tMoE: Iteration: 2 | log-likelihood: -522.470715480188
## EM - tMoE: Iteration: 3 | log-likelihood: -520.069109253319
## EM - tMoE: Iteration: 4 | log-likelihood: -518.442452827289
## EM - tMoE: Iteration: 5 | log-likelihood: -517.344656350543
## EM - tMoE: Iteration: 6 | log-likelihood: -516.638803942479
## EM - tMoE: Iteration: 7 | log-likelihood: -516.198775242585
## EM - tMoE: Iteration: 8 | log-likelihood: -515.929311355538
## EM - tMoE: Iteration: 9 | log-likelihood: -515.765968668161
## EM - tMoE: Iteration: 10 | log-likelihood: -515.667528520619
## EM - tMoE: Iteration: 11 | log-likelihood: -515.60839982427
## EM - tMoE: Iteration: 12 | log-likelihood: -515.572951042033
## EM - tMoE: Iteration: 13 | log-likelihood: -515.551721051248
## EM - tMoE: Iteration: 14 | log-likelihood: -515.539013191586
## EM - tMoE: Iteration: 15 | log-likelihood: -515.531407718103
## EM - tMoE: Iteration: 16 | log-likelihood: -515.526855311839

Summary

tmoe$summary()
## -------------------------------------
## Fitted t Mixture-of-Experts model
## -------------------------------------
## 
## tMoE model with K = 2 experts:
## 
##  log-likelihood df       AIC       BIC       ICL
##       -515.5269 10 -525.5269 -546.5999 -546.6062
## 
## Clustering table (Number of observations in each expert):
## 
##   1   2 
## 249 251 
## 
## Regression coefficients:
## 
##     Beta(k = 1)  Beta(k = 2)
## 1      0.057049 -0.002948983
## X^1    2.463168 -2.439658849
## 
## Variances:
## 
##  Sigma2(k = 1) Sigma2(k = 2)
##      0.3035883     0.3970848

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.493182080302
## EM - tMoE: Iteration: 2 | log-likelihood: -583.587874678764
## EM - tMoE: Iteration: 3 | log-likelihood: -582.959458799523
## EM - tMoE: Iteration: 4 | log-likelihood: -580.316633626359
## EM - tMoE: Iteration: 5 | log-likelihood: -571.261853578868
## EM - tMoE: Iteration: 6 | log-likelihood: -563.622409805815
## EM - tMoE: Iteration: 7 | log-likelihood: -560.590449380487
## EM - tMoE: Iteration: 8 | log-likelihood: -559.896659942736
## EM - tMoE: Iteration: 9 | log-likelihood: -559.331880656279
## EM - tMoE: Iteration: 10 | log-likelihood: -558.587057530464
## EM - tMoE: Iteration: 11 | log-likelihood: -557.649490620427
## EM - tMoE: Iteration: 12 | log-likelihood: -556.619468446007
## EM - tMoE: Iteration: 13 | log-likelihood: -555.68080035715
## EM - tMoE: Iteration: 14 | log-likelihood: -554.850720124086
## EM - tMoE: Iteration: 15 | log-likelihood: -554.07791712794
## EM - tMoE: Iteration: 16 | log-likelihood: -553.367846511377
## EM - tMoE: Iteration: 17 | log-likelihood: -552.753650182325
## EM - tMoE: Iteration: 18 | log-likelihood: -552.263861855205
## EM - tMoE: Iteration: 19 | log-likelihood: -551.903746335167
## EM - tMoE: Iteration: 20 | log-likelihood: -551.655047422553
## EM - tMoE: Iteration: 21 | log-likelihood: -551.489917151674
## EM - tMoE: Iteration: 22 | log-likelihood: -551.382470076923
## EM - tMoE: Iteration: 23 | log-likelihood: -551.313081321498
## EM - tMoE: Iteration: 24 | log-likelihood: -551.268264694494
## EM - tMoE: Iteration: 25 | log-likelihood: -551.239183594524
## EM - tMoE: Iteration: 26 | log-likelihood: -551.220171709601
## EM - tMoE: Iteration: 27 | log-likelihood: -551.207624302672
## EM - tMoE: Iteration: 28 | log-likelihood: -551.199249871376
## EM - tMoE: Iteration: 29 | log-likelihood: -551.193587441805
## EM - tMoE: Iteration: 30 | log-likelihood: -551.189701103296

Summary

tmoe$summary()
## -------------------------------------
## Fitted t Mixture-of-Experts model
## -------------------------------------
## 
## tMoE model with K = 4 experts:
## 
##  log-likelihood df       AIC       BIC     ICL
##       -551.1897 26 -577.1897 -614.7642 -614.76
## 
## 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.050010094 1010.072807 -1865.727997 292.6842002
## X^1 -0.101558786 -105.862642   115.553964 -12.1696158
## X^2 -0.008679092    2.485984    -1.743543   0.1248929
## 
## Variances:
## 
##  Sigma2(k = 1) Sigma2(k = 2) Sigma2(k = 3) Sigma2(k = 4)
##       1.652867      439.1176      511.1219      571.4369

Plots

Mean curve

tmoe$plot(what = "meancurve")

Confidence regions

tmoe$plot(what = "confregions")

Clusters

tmoe$plot(what = "clusters")

Log-likelihood

tmoe$plot(what = "loglikelihood")