R Under development (unstable) (2024-01-25 r85826 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. > library(MixAll) Loading required package: rtkore Loading required package: Rcpp Attaching package: 'rtkore' The following object is masked from 'package:Rcpp': LdFlags > > testPredict<-function(nbTrain , nbTest) + { + ## test categorical predictions + train1 <- matrix( c( sample(1:3,size=nbTrain,replace=TRUE, prob = c(0.05,0.05,0.9)) + , sample(1:3,size=nbTrain,replace=TRUE, prob = c(0.9,0.05,0.05)) + , sample(1:3,size=nbTrain,replace=TRUE, prob = c(0.05,0.05,0.9)) + , sample(1:3,size=nbTrain,replace=TRUE, prob = c(0.9,0.05,0.05)) + ) + , ncol =2 + ) + model <- clusterCategorical(train1,2,models = "categorical_p_pjk") + pred <- clusterPredict(train1,model) + # more than 5 classification errors is abnormal + if ( sum(pred@zi - model@zi) != 0) + { print("Predict Categorical failed");return(FALSE)} + + ##------------------------------------------------------------------------------ + ## test Poisson predictions + train2 <- matrix( c( rpois(nbTrain,lambda = 1), rpois(nbTrain,lambda = 10) + , rpois(nbTrain,lambda = 1), rpois(nbTrain,lambda = 10) + ) + , ncol =2 + ) + model <- clusterPoisson(train2,2,models = "poisson_p_lk") + pred <- clusterPredict(train2,model) + # Predictions should be the same + if ( sum(pred@zi -model@zi) != 0) + { print("Predict Poisson failed");return(FALSE)} + + ##------------------------------------------------------------------------------ + ## test Gaussian predictions + train3 <- matrix( c( rnorm(nbTrain, mean = 1, sd=1), rnorm(nbTrain,mean = 10, sd=1) + , rnorm(nbTrain, mean = 1, sd=1), rnorm(nbTrain,mean = 10, sd=1) + ) + , ncol =2 + ) + model <- clusterDiagGaussian(train3, 2, models = "gaussian_p_s") + pred <- clusterPredict(train3, model) + # Predictions should be the same + if ( sum(pred@zi -model@zi) != 0) + { print("Predict Gaussian failed");return(FALSE)} + + ##------------------------------------------------------------------------------ + ## test gamma predictions + train4 <- matrix( c( rgamma(nbTrain, shape = 1, scale=1), rgamma(nbTrain,shape = 10, scale=1) + , rgamma(nbTrain, shape = 1, scale=1), rgamma(nbTrain,shape = 10, scale=1) + ) + , ncol =2 + ) + ## model <- clusterGamma(train4, 2, models = "gamma_p_ak_b") + ## pred <- clusterPredict(train4,model) + ## # more than 5 classification errors is abnormal + ## if ( sum(pred@zi -model@zi) != 0) + ## { print("Predict gamma failed");return(FALSE)} + + ##------------------------------------------------------------------------------ + ## test mixed data predictions + train <- list(train1, train2, train3, train4) + models <- c("categorical_p_pjk", "poisson_p_lk", "gaussian_p_s","gamma_p_ak_b") + + model <- clusterMixedData(train, models, 2) + pred <- clusterPredict(train, model) + # more than 5 classification errors is abnormal + if ( sum(pred@zi -model@zi) != 0) + { print("Predict mixed failed");return(FALSE)} + + ##------------------------------------------------------------------------------ + return(TRUE) + } > > testPredict(1000, 20) [1] TRUE > > proc.time() user system elapsed 5.48 0.12 5.59