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: -554.426772623348
## EM - tMoE: Iteration: 2 | log-likelihood: -551.113978113798
## EM - tMoE: Iteration: 3 | log-likelihood: -549.915176193941
## EM - tMoE: Iteration: 4 | log-likelihood: -548.819822591165
## EM - tMoE: Iteration: 5 | log-likelihood: -547.85660575786
## EM - tMoE: Iteration: 6 | log-likelihood: -547.050022629828
## EM - tMoE: Iteration: 7 | log-likelihood: -546.40165514657
## EM - tMoE: Iteration: 8 | log-likelihood: -545.897356677749
## EM - tMoE: Iteration: 9 | log-likelihood: -545.51519159804
## EM - tMoE: Iteration: 10 | log-likelihood: -545.231405424317
## EM - tMoE: Iteration: 11 | log-likelihood: -545.02396719956
## EM - tMoE: Iteration: 12 | log-likelihood: -544.87417404234
## EM - tMoE: Iteration: 13 | log-likelihood: -544.767016645735
## EM - tMoE: Iteration: 14 | log-likelihood: -544.690921557412
## EM - tMoE: Iteration: 15 | log-likelihood: -544.637198943382
## EM - tMoE: Iteration: 16 | log-likelihood: -544.599438279581
## EM - tMoE: Iteration: 17 | log-likelihood: -544.572990254246
## EM - tMoE: Iteration: 18 | log-likelihood: -544.554517477507
## EM - tMoE: Iteration: 19 | log-likelihood: -544.541643774528
## EM - tMoE: Iteration: 20 | log-likelihood: -544.532688065305
## EM - tMoE: Iteration: 21 | log-likelihood: -544.526466880628
## EM - tMoE: Iteration: 22 | log-likelihood: -544.522150274309

Summary

tmoe$summary()
## -------------------------------------
## Fitted t Mixture-of-Experts model
## -------------------------------------
## 
## tMoE model with K = 2 experts:
## 
##  log-likelihood df       AIC       BIC       ICL
##       -544.5222 10 -554.5222 -575.5952 -575.5975
## 
## Clustering table (Number of observations in each expert):
## 
##   1   2 
## 249 251 
## 
## Regression coefficients:
## 
##     Beta(k = 1) Beta(k = 2)
## 1     0.1577658   0.1773964
## X^1   2.7097852  -2.7244783
## 
## Variances:
## 
##  Sigma2(k = 1) Sigma2(k = 2)
##      0.2802434     0.5226801

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.143887934682
## EM - tMoE: Iteration: 2 | log-likelihood: -583.306290629304
## EM - tMoE: Iteration: 3 | log-likelihood: -582.587349579932
## EM - tMoE: Iteration: 4 | log-likelihood: -579.735212791343
## EM - tMoE: Iteration: 5 | log-likelihood: -570.705984164764
## EM - tMoE: Iteration: 6 | log-likelihood: -563.3068372787
## EM - tMoE: Iteration: 7 | log-likelihood: -560.319438818465
## EM - tMoE: Iteration: 8 | log-likelihood: -559.61072565869
## EM - tMoE: Iteration: 9 | log-likelihood: -559.037696277087
## EM - tMoE: Iteration: 10 | log-likelihood: -558.334011832409
## EM - tMoE: Iteration: 11 | log-likelihood: -557.49242976863
## EM - tMoE: Iteration: 12 | log-likelihood: -556.523042338436
## EM - tMoE: Iteration: 13 | log-likelihood: -555.502272477019
## EM - tMoE: Iteration: 14 | log-likelihood: -554.569794499746
## EM - tMoE: Iteration: 15 | log-likelihood: -553.773554105487
## EM - tMoE: Iteration: 16 | log-likelihood: -553.092554562932
## EM - tMoE: Iteration: 17 | log-likelihood: -552.532515800221
## EM - tMoE: Iteration: 18 | log-likelihood: -552.104735235051
## EM - tMoE: Iteration: 19 | log-likelihood: -551.800502669993
## EM - tMoE: Iteration: 20 | log-likelihood: -551.594849958843
## EM - tMoE: Iteration: 21 | log-likelihood: -551.45988606714
## EM - tMoE: Iteration: 22 | log-likelihood: -551.372478894859
## EM - tMoE: Iteration: 23 | log-likelihood: -551.316070602919
## EM - tMoE: Iteration: 24 | log-likelihood: -551.279573213107
## EM - tMoE: Iteration: 25 | log-likelihood: -551.255812973587
## EM - tMoE: Iteration: 26 | log-likelihood: -551.240212977057
## EM - tMoE: Iteration: 27 | log-likelihood: -551.229864456328
## EM - tMoE: Iteration: 28 | log-likelihood: -551.222916348393
## EM - tMoE: Iteration: 29 | log-likelihood: -551.218185997289

Summary

tmoe$summary()
## -------------------------------------
## Fitted t Mixture-of-Experts model
## -------------------------------------
## 
## tMoE model with K = 4 experts:
## 
##  log-likelihood df       AIC       BIC       ICL
##       -551.2182 26 -577.2182 -614.7927 -614.7888
## 
## 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.050288262  994.242586 -1801.890329 292.9924372
## X^1 -0.100763650 -104.099933   110.850023 -12.1823722
## X^2 -0.008765395    2.438234    -1.658844   0.1250231
## 
## Variances:
## 
##  Sigma2(k = 1) Sigma2(k = 2) Sigma2(k = 3) Sigma2(k = 4)
##       1.662701      451.1523       576.763      569.7587

Plots

Mean curve

tmoe$plot(what = "meancurve")

Confidence regions

tmoe$plot(what = "confregions")

Clusters

tmoe$plot(what = "clusters")

Log-likelihood

tmoe$plot(what = "loglikelihood")