X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=vignettes%2Freport.Rmd;h=2f4a218340180b5e675023f46f92528fa37c710c;hb=e36b104629f3afa95b5947f28911e276c46aa79f;hp=41497177de20a8c05c9e2bafbbe7bb51cd3dd9c6;hpb=3d5b50604d7e63fa0a0d6c37d34f6a4595bcfd34;p=morpheus.git diff --git a/vignettes/report.Rmd b/vignettes/report.Rmd index 4149717..2f4a218 100644 --- a/vignettes/report.Rmd +++ b/vignettes/report.Rmd @@ -1,5 +1,5 @@ --- -title: morpheus........... +title: Use morpheus package output: pdf_document: @@ -13,150 +13,61 @@ knitr::opts_chunk$set(echo = TRUE, include = TRUE, out.width = "100%", fig.align = "center") ``` -0) Tell that we try to learn classification parameters in a non-EM way, using algebric manipulations. -1) Model. +## Introduction + + +*morpheus* is a contributed R package which attempts to find the parameters of a mixture of logistic classifiers. +When the data under study come from several groups that have different characteristics, using mixture models is a very popular way to handle heterogeneity. +Thus, many algorithms were developed to deal with various mixtures models. Most of them use likelihood methods or Bayesian methods that are likelihood dependent. +*flexmix* is an R package which implements these kinds of algorithms. + +However, one problem of such methods is that they can converge to local maxima, so several starting points must be explored. +Recently, spectral methods were developed to bypass EM algorithms and they were proved able to recover the directions of the regression parameter +in models with known link function and random covariates (see [XX]). +Our package extends such moment methods using least squares to get estimators of the whole parameters (with theoretical garantees, see [XX]). +Currently it can handle only binary output $-$ which is a common case. + +## Model + +TODO: adapt + +Let us denote $[n]$ the set $\lbrace 1,2,\ldots,n\rbrace$ and $e_i\in\mathbb{R}^d,$ the i-th canonical basis vector of $\mathbb{R}^d.$ Denote also $I_d\in\mathbb{R}^{d\times d}$ the identity matrix in $\mathbb{R}^{d}$. The tensor product of $p$ euclidean spaces $\mathbb{R}^{d_i},\,\,i\in [p]$ is noted $\bigotimes_{i=1}^p\mathbb{R}^{d_i}.$ $T$ is called a real p-th order tensor if $T\in \bigotimes_{i=1}^p\mathbb{R}^{d_i}.$ For $p=1,$ $T$ is a vector in $\mathbb{R}^d$ and for $p=2$, $T$ is a $d\times d$ real matrix. The $(i_1,i_2,\ldots,i_p)$-th coordinate of $T$ with respect the canonical basis is denoted $T[i_1,i_2,\ldots,i_p]$, $ i_1,i_2,\ldots,i_p\in [d].$\\ + +\noindent +Let $X\in \R^{d}$ be the vector of covariates and $Y\in \{0,1\}$ be the binary output. \\ + +\noindent +A binary regression model assumes that for some link function $g$, the probability that $Y=1$ conditionally to $X=x$ is given by $g(\langle \beta , x \rangle +b)$, where $\beta\in \R^{d}$ is the vector of regression coefficients and $b\in\R$ is the intercept. Popular examples of link functions are the logit link function where for any real $z$, $g(z)=e^z/(1+e^z)$ and the probit link function where $g(z)=\Phi(z),$ with $\Phi$ the cumulative distribution function of the standard normal ${\cal N}(0,1)$. \\ +If now we want to modelise heterogeneous populations, let $K$ be the number of populations and $\omega=(\omega_1,\cdots,\omega_K)$ their weights such that $\omega_{j}\geq 0$, $j=1,\ldots,K$ and $\sum_{j=1}^{K}\omega{j}=1$. Define, for $j=1,\ldots,K$, the regression coefficients in the $j$-th population by $\beta_{j}\in\R^{d}$ and the intercept in the $j$-th population by $b_{j}\in\R$. Let $\omega =(\omega_{1},\ldots,\omega_{K})$, $b=(b_1,\cdots,b_K)$, $\beta=[\beta_{1} \vert \cdots,\vert \beta_K]$ the $d\times K$ matrix of regression coefficients and denote $\theta=(\omega,\beta,b)$. +The model of population mixture of binary regressions is given by: +\begin{equation} +\label{mixturemodel1} +\PP_{\theta}(Y=1\vert X=x)=\sum^{K}_{k=1}\omega_k g(<\beta_k,x>+b_k). +\end{equation} + +\noindent +We assume that the random variable $X$ has a Gaussian distribution. We now focus on the situation where $X\sim \mathcal{N}(0,I_d)$, $I_d$ being the identity $d\times d$ matrix. All results may be easily extended to the situation where $X\sim \mathcal{N}(m,\Sigma)$, $m\in \R^{d}$, $\Sigma$ a positive and symetric $d\times d$ matrix. \\ + +\noindent + 2) Algorithm (as in article) -3) Experiments: show package usage -# Expériences - -```{r, results="show", include=TRUE, echo=TRUE} -library(Rmixmod) #to get clustering probability matrix -library(ClusVis) -library(FactoMineR) #for PCA - -plotPCA <- function(prob) -{ - par(mfrow=c(2,2), mar=c(4,4,2,2), mgp=c(2,1,0)) - partition <- apply(prob, 1, which.max) - n <- nrow(prob) - K <- ncol(prob) - palette <- rainbow(K, s=.5) - cols <- palette[partition] - tmp <- PCA(rbind(prob, diag(K)), ind.sup=(n+1):(n+K), scale.unit=F, graph=F) - scores <- tmp$ind$coord[,1:3] #samples coords, by rows - ctrs <- tmp$ind.sup$coord #projections of indicator vectors (by cols) - for (i in 1:2) - { - for (j in (i+1):3) - { - absc <- scores[,i] - ords <- scores[,j] - xrange <- range(absc) - yrange <- range(ords) - plot(absc, ords, col=c(cols,rep(colors()[215],K),rep(1,K)), - pch=c(rep("o",n),rep(as.character(1:K),2)), - xlim=xrange, ylim=yrange, - xlab=paste0("Dim ", i, " (", round(tmp$eig[i,2],2), "%)"), - ylab=paste0("Dim ", j, " (", round(tmp$eig[j,2],2), "%)")) - ctrsavg <- t(apply(as.matrix(palette), 1, - function(cl) c(mean(absc[cols==cl]), mean(ords[cols==cl])))) - text(ctrsavg[,1], ctrsavg[,2], as.character(1:K), col=colors()[215]) - text(ctrs[,i], ctrs[,j], as.character(1:K), col=1) - title(paste0("PCA ", i, "-", j, " / K=",K)) - } - } - # TODO: - plot(0, xaxt="n", yaxt="n", xlab="", ylab="", col="white", bty="n") -} - -plotClvz <- function(xem, alt=FALSE) -{ - par(mfrow=c(2,2), mar=c(4,4,2,2), mgp=c(2,1,0)) - if (alt) { - resvisu <- clusvis(log(xem@bestResult@proba), xem@bestResult@parameters@proportions) - } else { - resvisu <- clusvisMixmod(xem) - } - plotDensityClusVisu(resvisu, positionlegend=NULL) - plotDensityClusVisu(resvisu, add.obs=TRUE, positionlegend=NULL) - # TODO: - plot(0, xaxt="n", yaxt="n", xlab="", ylab="", col="white", bty="n") - plot(0, xaxt="n", yaxt="n", xlab="", ylab="", col="white", bty="n") -} - -grlplot <- function(x, K, alt=FALSE) #x: data, K: nb classes -{ - xem <- mixmodCluster(x, K, strategy=mixmodStrategy(nbTryInInit=500,nbTry=25)) - plotPCA(xem@results[[1]]@proba) - plotClvz(xem, alt) -} -``` +TODO: find it... -## Iris data +The developed R-package is called \verb"morpheus" \cite{Loum_Auder} and divided into two main parts: +\begin{enumerate} + \item the computation of the directions matrix $\mu$, based on the empirical + cross-moments as described in the previous sections; + \item the optimization of all parameters (including $\mu$), using the initially estimated + directions as a starting point. +\end{enumerate} +The former is a straightforward translation of the mathematical formulas (file R/computeMu.R), +while the latter calls R constrOptim() method on the objective function expression and its +derivative (file R/optimParams.R). For usage examples, please refer to the package help. -```{r, results="show", include=TRUE, echo=TRUE} -data(iris) -x <- iris[,-5] #remove class info -for (i in 3:5) -{ - print(paste("Resultats en", i, "classes")) - grlplot(x, i) -} -``` +3) Experiments: show package usage + +\subsection{Experiments} +In this section, we evaluate our algorithm in a first step using mean squared error (MSE). In a second step, we compare experimentally our moments method (morpheus package \cite{Loum_Auder}) and the likelihood method (with felxmix package \cite{bg-papers:Gruen+Leisch:2007a}). -### finance dataset (from Rmixmod package) -# -#This dataset has two categorical attributes (the year and financial status), and four continuous ones. -# -#Warnings, some probabilities of classification are exactly equal to zero then we cannot use ClusVis -# -#```{r, results="show", include=TRUE, echo=TRUE} -#data(finance) -#x <- finance[,-2] -#for (i in 3:5) -#{ -# print(paste("Resultats en", i, "classes")) -# grlplot(x, i, TRUE) -#} -#``` -# -### "Cathy dataset" (12 clusters) -# -#Warnings, some probabilities of classification are exactly equal to zero then we cannot use ClusVis -# -#```{r, results="hide", include=TRUE, echo=TRUE} -#cathy12 <- as.matrix(read.table("data/probapostCatdbBlocAtrazine-K12.txt")) -#resvisu <- clusvis(log(cathy12), prop = colMeans(cathy12)) -#par(mfrow=c(2,2), mar=c(4,4,2,2), mgp=c(2,1,0)) -#plotDensityClusVisu(resvisu, positionlegend = NULL) -#plotDensityClusVisu(resvisu, add.obs = TRUE, positionlegend = NULL) -#plotPCA(cathy12) -#``` -# -### Pima indian diabete -# -#[Source.](https://gist.github.com/ktisha/c21e73a1bd1700294ef790c56c8aec1f) -# -#```{r, results="show", include=TRUE, echo=TRUE} -#load("data/pimaData.rda") -#for (i in 3:5) -#{ -# print(paste("Resultats en", i, "classes")) -# grlplot(x, i) -#} -#``` -# -### Breast cancer -# -#[Source.](http://archive.ics.uci.edu/ml/datasets/breast+cancer+wisconsin+\%28diagnostic\%29) -# -#```{r, results="show", include=TRUE, echo=TRUE} -#load("data/wdbc.rda") -#for (i in 3:5) -#{ -# print(paste("Resultats en", i, "classes")) -# grlplot(x, i) -#} -#``` -# -### House-votes -# -#```{r, results="show", include=TRUE, echo=TRUE} -#load("data/house-votes.rda") -#for (i in 3:5) -#{ -# print(paste("Resultats en", i, "classes")) -# grlplot(x, i) -#} -#``` +TODO.........