R Under development (unstable) (2024-04-29 r86495 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # TODO: Add comment > # > # Author: iovleff > #----------------------------------------------------------------------- > library(MixAll) Loading required package: rtkore Loading required package: Rcpp Attaching package: 'rtkore' The following object is masked from 'package:Rcpp': LdFlags > data(iris) > > gauss_model <- clusterDiagGaussian( iris[1:4], nbCluster = 3, models= c("gaussian_pk_sjk") + , strategy = clusterFastStrategy()) > > data<-gauss_model@component@data > nbCluster <- gauss_model@nbCluster > prop <- gauss_model@pk > mean <- gauss_model@component@mean > sigma <- gauss_model@component@sigma > > nbSample <- nrow(data) > nbVariable <- ncol(data) > > f <-vector(length=nbSample) > lnComp <- vector(length=nbCluster) > > for (i in 1:nbSample) + { + for (k in 1:nbCluster) + { lnComp[k] = log(prop[k]) + sum(dnorm(data[i,], mean[k,], sigma[k,],log=TRUE)); } + lmax <- max(lnComp) + + lnComp = lnComp -lmax; + + f[i] = log(sum(exp(lnComp))) + lmax; + } > > if( abs(sum(f) - gauss_model@lnLikelihood) < 1.e-15 ) + { print ("clusterDiagGaussianLikelihood failed") + } else + { print ("clusterDiagGaussianLikelihood successful") } [1] "clusterDiagGaussianLikelihood successful" > > proc.time() user system elapsed 0.64 0.18 0.78