Package: em-transfer-learning
Linear Supervised Transfer LearningCopyright (C) 2019 - Benjamin PaassenMachine Learning Research GroupCenter of Excellence Cognitive Interaction Technology (CITEC)Bielefeld UniversityThis program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.You should have received a copy of the GNU General Public License
along with this program; if not, seehttp://www.gnu.org/licenses/.IntroductionThis Python3 library provides several algorithms to learn a linear mapping from
an $m$-dimensional source space to an $n$-dimensional target space, such that
a classification model trained in the source space becomes applicable in the
target space. The source space model is assumed to be a labelled mixture of
Gaussians. Note that this library assumes that the relation between the source
and target space is (approximately) linear and will necessarily fail if the
relationship is highly nonlinear. Further note that this library requires a
few labelled target space data points to work (typically, even ~10 data points
are enough). However, not all classes are required, since the learned linear
transformation generalizes across classes.If you intend to use this library in academic work, please citeour paper.InstallationThis package is available onpypiasem_transfer_learning. You can install
it viapip install --user em_transfer_learningQuickStart GuideFor a quick start we recommend to take a look at the demo in the notebookdemo.ipynb. In this file we demonstrate how to perform transfer learning
on example data. For the actual transfer learning, we recommend to initialize
one of the following models, depending on your source space model:em_transfer_learning.transfer_learning.LGMM_transfer_model: If you have a full labelled
Gaussian mixture model.em_transfer_learning.transfer_learning.SLGMM_transfer_model: If you have a labelled Gaussian
mixture model with shared precision matrices.em_transfer_learning.transfer_learning.Local_LVQ_transfer_model: If you have a learning vector
quantization model with individual metric learning matrices.em_transfer_learning.transfer_learning.LVQ_transfer_model: If you have a learning vector
quantization model with shared metric learning matrix or no metric learning
at all.Note that models 2 and 4 aremuchfaster to train compared to models 1 and 3
(refer to the next section for more information on that).All these models follow thescikit-learnconvention, i.e. you need to call
thefitfunction with target space data first and then thepredictfunction
to map new target space data to the source space according to the learned
mapping.BackgroundThe basic idea of our transfer learning approach is to maximize the likelihood
of target space data according to the source space data distributionafterthe
learned transfer function $h$ has been applied. More precisely, assume we have
a data set $(\vec x_1, y_1), \ldots, (\vec x_m, y_m)$ of target data points
$\vec x_j \in \mathbb{R}^n$ and their labels $y_j \in \{1, \ldots, L\}$.
Then, we wish to maximize the joint probability\max_h \prod_{j=1}^m p\Big(h(\vec x_j), y_j\Big)To make this optimization problem feasible, we introduce two assumptions:
First, that $p(x, y)$ can be modelled by a labelled Gaussian mixture
model (lGMM) and, second, that $h$ can be approximated by a linear function.
In more detail, that means the following.Labelled Gaussian Mixture ModelsAlabelled Gaussian mixture modelassumes that data is generated by a mixture
of $K$ Gaussians, each of which has a prior $P(k)$, a data generating
Gaussian density $p(\vec x|k)$, and a label generating distribution
$P(y|k)$. Using these distributions, we can derive the joint probability
density $p(\vec x, y)$ as follows.p(\vec x, y) = \sum_{k=1}^K p(\vec x, y, k) = \sum_{k=1}^K p(\vec x, y|k) \cdot P(k)Our model assumes that $\vec x$ and $y$ are conditionally independent given
the component index $k$, such that we can re-write:p(\vec x, y) = \sum_{k=1}^K p(\vec x|k) \cdot P(y|k) \cdot P(k)Note that $p(\vec x|k)$ is amultivariate Gaussian probability densitywith parameters for the mean $\vec \mu_k$ and the precision matrix
$\Lambda_k$. Also note that this model is a proper generalization over
standardGaussian mixture modelsand that many of the GMM properties
translate directly to lGMMs. More precisely, we obtain a standard GMM by setting
the label distribution $P(y|k)$ to a uniform distribution and leaving it
unchanged during training. Alternatively, we also obtain a standard GMM by
assigning the same label to all data points.Also note that lGMMs generalize over learning vector quantization models if we
apply a scaling trick to the precision matrices (for more details on this,
refer toour paper).Expectation Maximization transfer learningOur assumption that the transfer function $h$ is approximately linear implies
that $h$ can be re-written as $h(\vec x) \approx H \cdot \vec x$ for some
matrix $H$. Thus, our transfer learning problem becomes:\max_H \prod_{j=1}^m \sum_{k=1}^K p(H \cdot \vec x|k) \cdot P(y|k) \cdot P(k)Due to the product of sums, a direct optimization of this expression is
infeasible. However, we can apply anexpectation maximizationscheme.
In particular, we initialize $H$ with the identity matrix (padded with zeros
wherever necessary) and then iteratively perform the following two steps:Expectation: We compute the posterior $p(k|H \cdot \vec x_j, y_j)$
for the current transfer matrix $H$, all data points $j$ and all
Gaussian components $k$, yielding a matrix $\Gamma \in \mathbb{R}^{K \times m}$
with entries $\gamma_{k,j} = p(k|H \cdot \vec x_j, y_j)$. The full
expression for the posterior is given inour paper.Maximization: We maximize the expected log likelihood under fixed posterior,
i.e.\max_H \sum_{j=1}^m \sum_{k=1}^K \gamma_{k, j} \cdot \log\big[p(H \cdot \vec x_j, y_j| k)\big]This optimization problem can be shown to be convex und thus lends itself
for optimization techniques like l-BFGS. Even better, if the precision
matrix $\Lambda_k$ is shared across all Gaussians $k$, the problem has
a closed-form solution, namelyH = W \cdot \Gamma \cdot X^T \cdot (X \cdot X^T + \lambda \cdot I)^{-1}where $W = (\vec \mu_1, \ldots, \vec \mu_K)$, $X = (\vec x_1, \ldots, \vec x_m)$,
$\lambda$ is a (small) regularization constant, and $I$ is the identity
matrix. Due to this closed form solution, theSLGMM_transfer_modeland
theLVQ_modelare much faster to train compared to theLGMM_transfer_modeland theLocal_LVQ_transfer_model.For more detailed background, please refer toour paper.ContentsThis library contains the following files.demo.ipynb: A demo script illustrating how to use this library.LICENSE: A copy of the GPLv3 license.em_transfer_learning/lgmm.py: A file to train labelled Gaussian mixture models with or without
shared precision matrices.em_transfer_learning/transfer_learning.py: The actual transfer learning models.lgmm_test.py: A set of unit tests forlgmm.py.README.md: This file.transfer_learning_test.py: A set of unit tests fortransfer_learning.py.LicensingThis library is licensed under theGNU General Public License Version 3.DependenciesThis library depends onNumPyfor matrix operations, onscikit-learnfor the base interfaces and onSciPyfor optimization.LiteraturePaassen, B., Schulz, A., Hahne, J., and Hammer, B (2018).Expectation maximization transfer learning and its application for bionic hand prostheses.
Neurocomputing, 298, 122-133. doi:10.1016/j.neucom.2017.11.072.Link