Commit 4be91a04 authored by Jean-Benoist Leger's avatar Jean-Benoist Leger

tests

parent 12eceb62
require('blockmodels')
##
## SBM
##
## generation of one SBM network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
P<-matrix(runif(Q*Q),Q,Q)
M<-1*(matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)<Z%*%P%*%t(Z)) ## adjacency matrix
## estimation
my_model <- BM_bernoulli("SBM",M , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## SBM symmetric
##
## generation of one SBM_sym network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
P<-matrix(runif(Q*Q),Q,Q)
P[lower.tri(P)]<-t(P)[lower.tri(P)]
M<-1*(matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)<Z%*%P%*%t(Z)) ## adjacency matrix
M[lower.tri(M)]<-t(M)[lower.tri(M)]
## estimation
my_model <- BM_bernoulli("SBM_sym",M , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## LBM
##
## generation of one LBM network
npc <- c(20,10) # nodes per class
Q <- c(1,2) # classes
Z1<-diag(Q[1])%x%matrix(1,npc[1],1)
Z2<-diag(Q[2])%x%matrix(1,npc[2],1)
P<-matrix(runif(Q[1]*Q[2]),Q[1],Q[2])
M<-1*(matrix(runif(npc[1]*Q[1]*npc[2]*Q[2]),npc[1]*Q[1],npc[2]*Q[2])<Z1%*%P%*%t(Z2)) ## adjacency matrix
## estimation
my_model <- BM_bernoulli("LBM",M , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
require('blockmodels')
##
## SBM
##
## generation of one SBM network
npc <- 10 # nodes per class
Q <- 2 # classes
sigmo <- function(x){1/(1+exp(-x))}
Z<-diag(Q)%x%matrix(1,npc,1)
Mg<-8*matrix(runif(Q*Q),Q,Q)-4
Y1 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)-.5
Y2 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)-.5
M_in_expectation<-sigmo(Z%*%Mg%*%t(Z) + 5*Y1-3*Y2)
M<-1*(matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)<M_in_expectation)
## estimation
my_model <- BM_bernoulli_covariates("SBM",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## SBM symmetric
##
## generation of one SBM_sym network
npc <- 10 # nodes per class
Q <- 2 # classes
sigmo <- function(x){1/(1+exp(-x))}
Z<-diag(Q)%x%matrix(1,npc,1)
Mg<-8*matrix(runif(Q*Q),Q,Q)-4
Mg[lower.tri(Mg)]<-t(Mg)[lower.tri(Mg)]
Y1 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)-.5
Y2 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)-.5
Y1[lower.tri(Y1)]<-t(Y1)[lower.tri(Y1)]
Y2[lower.tri(Y2)]<-t(Y2)[lower.tri(Y2)]
M_in_expectation<-sigmo(Z%*%Mg%*%t(Z) + 5*Y1-3*Y2)
M<-1*(matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)<M_in_expectation)
M[lower.tri(M)]<-t(M)[lower.tri(M)]
## estimation
my_model <- BM_bernoulli_covariates("SBM_sym",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## LBM
##
## generation of one LBM network
npc <- c(20,10) # nodes per class
Q <- c(1,2) # classes
sigmo <- function(x){1/(1+exp(-x))}
Z1<-diag(Q[1])%x%matrix(1,npc[1],1)
Z2<-diag(Q[2])%x%matrix(1,npc[2],1)
Mg<-8*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])-4
Y1 <- matrix(runif(npc[1]*Q[1]*npc[2]*Q[2]),npc[1]*Q[1],npc[2]*Q[2])-.5
Y2 <- matrix(runif(npc[1]*Q[1]*npc[2]*Q[2]),npc[1]*Q[1],npc[2]*Q[2])-.5
M_in_expectation<-sigmo(Z1%*%Mg%*%t(Z2) + 5*Y1-3*Y2)
M<-1*(matrix(runif(npc[1]*Q[1]*npc[2]*Q[2]),npc[1]*Q[1],npc[2]*Q[2])<M_in_expectation)
## estimation
my_model <- BM_bernoulli_covariates("LBM",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
require('blockmodels')
##
## SBM
##
## generation of one SBM network
npc <- 10 # nodes per class
Q <- 2 # classes
sigmo <- function(x){1/(1+exp(-x))}
Z<-diag(Q)%x%matrix(1,npc,1)
Mg<-8*matrix(runif(Q*Q),Q,Q)-4
Y1 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)-.5
Y2 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)-.5
M_in_expectation<-sigmo(Z%*%Mg%*%t(Z) + 5*Y1-3*Y2)
M<-1*(matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)<M_in_expectation)
## estimation
my_model <- BM_bernoulli_covariates_fast("SBM",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## SBM symmetric
##
## generation of one SBM_sym network
npc <- 10 # nodes per class
Q <- 2 # classes
sigmo <- function(x){1/(1+exp(-x))}
Z<-diag(Q)%x%matrix(1,npc,1)
Mg<-8*matrix(runif(Q*Q),Q,Q)-4
Mg[lower.tri(Mg)]<-t(Mg)[lower.tri(Mg)]
Y1 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)-.5
Y2 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)-.5
Y1[lower.tri(Y1)]<-t(Y1)[lower.tri(Y1)]
Y2[lower.tri(Y2)]<-t(Y2)[lower.tri(Y2)]
M_in_expectation<-sigmo(Z%*%Mg%*%t(Z) + 5*Y1-3*Y2)
M<-1*(matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)<M_in_expectation)
M[lower.tri(M)]<-t(M)[lower.tri(M)]
## estimation
my_model <- BM_bernoulli_covariates_fast("SBM_sym",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## LBM
##
## generation of one LBM network
npc <- c(20,10) # nodes per class
Q <- c(1,2) # classes
sigmo <- function(x){1/(1+exp(-x))}
Z1<-diag(Q[1])%x%matrix(1,npc[1],1)
Z2<-diag(Q[2])%x%matrix(1,npc[2],1)
Mg<-8*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])-4
Y1 <- matrix(runif(npc[1]*Q[1]*npc[2]*Q[2]),npc[1]*Q[1],npc[2]*Q[2])-.5
Y2 <- matrix(runif(npc[1]*Q[1]*npc[2]*Q[2]),npc[1]*Q[1],npc[2]*Q[2])-.5
M_in_expectation<-sigmo(Z1%*%Mg%*%t(Z2) + 5*Y1-3*Y2)
M<-1*(matrix(runif(npc[1]*Q[1]*npc[2]*Q[2]),npc[1]*Q[1],npc[2]*Q[2])<M_in_expectation)
## estimation
my_model <- BM_bernoulli_covariates_fast("LBM",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
require('blockmodels')
##
## SBM
##
## generation of one SBM network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
Mu<-20*matrix(runif(Q*Q),Q,Q)
M<-matrix(rnorm(npc*Q*npc*Q,sd=10),npc*Q,npc*Q)+Z%*%Mu%*%t(Z) ## adjacency matrix
## estimation
my_model <- BM_gaussian("SBM",M , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## SBM symmetric
##
## generation of one SBM_sym network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
Mu<-20*matrix(runif(Q*Q),Q,Q)
Mu[lower.tri(Mu)]<-t(Mu)[lower.tri(Mu)]
M<-matrix(rnorm(npc*Q*npc*Q,sd=10),npc*Q,npc*Q)+Z%*%Mu%*%t(Z) ## adjacency matrix
M[lower.tri(M)]<-t(M)[lower.tri(M)]
## estimation
my_model <- BM_gaussian("SBM_sym",M , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## LBM
##
## generation of one LBM network
npc <- c(20,10) # nodes per class
Q <- c(1,2) # classes
Z1<-diag(Q[1])%x%matrix(1,npc[1],1)
Z2<-diag(Q[2])%x%matrix(1,npc[2],1)
Mu<-20*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])
M<-matrix(rnorm(npc[1]*Q[1]*npc[2]*Q[2],sd=10),npc[1]*Q[1],npc[2]*Q[2])+Z1%*%Mu%*%t(Z2) ## adjacency matrix
## estimation
my_model <- BM_gaussian("LBM",M , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
require('blockmodels')
##
## SBM
##
## generation of one SBM network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
Mu<-20*matrix(runif(Q*Q),Q,Q)
Y1 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)
Y2 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)
M<-matrix(rnorm(npc*Q*npc*Q,sd=5),npc*Q,npc*Q)+Z%*%Mu%*%t(Z)+4.2*Y1-1.6*Y2 ## adjacency matrix
## estimation
my_model <- BM_gaussian_covariates("SBM",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## SBM symmetric
##
## generation of one SBM_sym network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
Mu<-20*matrix(runif(Q*Q),Q,Q)
Mu[lower.tri(Mu)]<-t(Mu)[lower.tri(Mu)]
Y1 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)
Y2 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)
Y1[lower.tri(Y1)]<-t(Y1)[lower.tri(Y1)]
Y2[lower.tri(Y2)]<-t(Y2)[lower.tri(Y2)]
M<-matrix(rnorm(npc*Q*npc*Q,sd=5),npc*Q,npc*Q)+Z%*%Mu%*%t(Z)+4.2*Y1-1.6*Y2 ## adjacency matrix
M[lower.tri(M)]<-t(M)[lower.tri(M)]
## estimation
my_model <- BM_gaussian_covariates("SBM_sym",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## LBM
##
## generation of one LBM network
npc <- c(20,10) # nodes per class
Q <- c(1,2) # classes
Z1<-diag(Q[1])%x%matrix(1,npc[1],1)
Z2<-diag(Q[2])%x%matrix(1,npc[2],1)
Mu<-20*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])
Y1 <- matrix(runif(npc[1]*Q[1]*npc[2]*Q[2]),npc[1]*Q[1],npc[2]*Q[2])
Y2 <- matrix(runif(npc[1]*Q[1]*npc[2]*Q[2]),npc[1]*Q[1],npc[2]*Q[2])
M<-matrix(rnorm(npc[1]*Q[1]*npc[2]*Q[2],sd=5),npc[1]*Q[1],npc[2]*Q[2])+Z1%*%Mu%*%t(Z2)+4.2*Y1-1.6*Y2 ## adjacency matrix
## estimation
my_model <- BM_gaussian_covariates("LBM",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
require('blockmodels')
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
Mu1<-4*matrix(runif(Q*Q),Q,Q)
Mu2<-4*matrix(runif(Q*Q),Q,Q)
Noise1<-matrix(rnorm(npc*Q*npc*Q,sd=1),npc*Q,npc*Q)
Noise2<-matrix(rnorm(npc*Q*npc*Q,sd=1),npc*Q,npc*Q)
M1<- Z%*%Mu1%*%t(Z) + Noise1
M2<- Z%*%Mu2%*%t(Z) + 10*Noise1 + Noise2
## estimation
my_model <- BM_gaussian_multivariate("SBM",list(M1,M2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## SBM symmetric
##
## generation of one SBM_sym network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
Mu1<-4*matrix(runif(Q*Q),Q,Q)
Mu2<-4*matrix(runif(Q*Q),Q,Q)
Noise1<-matrix(rnorm(npc*Q*npc*Q,sd=1),npc*Q,npc*Q)
Noise2<-matrix(rnorm(npc*Q*npc*Q,sd=1),npc*Q,npc*Q)
M1<- Z%*%Mu1%*%t(Z) + Noise1
M2<- Z%*%Mu2%*%t(Z) + 10*Noise1 + Noise2
M1[lower.tri(M1)]<-t(M1)[lower.tri(M1)]
M2[lower.tri(M2)]<-t(M2)[lower.tri(M2)]
## estimation
my_model <- BM_gaussian_multivariate("SBM_sym",list(M1,M2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## LBM
##
## generation of one LBM network
npc <- c(20,10) # nodes per class
Q <- c(1,2) # classes
Z1<-diag(Q[1])%x%matrix(1,npc[1],1)
Z2<-diag(Q[2])%x%matrix(1,npc[2],1)
Mu1<-4*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])
Mu2<-4*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])
Noise1<-matrix(rnorm(npc[1]*Q[1]*npc[2]*Q[2],sd=1),npc[1]*Q[1],npc[2]*Q[2])
Noise2<-matrix(rnorm(npc[1]*Q[1]*npc[2]*Q[2],sd=1),npc[1]*Q[1],npc[2]*Q[2])
M1<-Z1%*%Mu1%*%t(Z2) + Noise1 ## adjacency
M2<-Z1%*%Mu2%*%t(Z2) + 10*Noise1 + Noise2 ## adjacency
## estimation
my_model <- BM_gaussian_multivariate("LBM",list(M1,M2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
require('blockmodels')
##
## SBM
##
## generation of one SBM network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
Mu1<-8*matrix(runif(Q*Q),Q,Q)
Mu2<-8*matrix(runif(Q*Q),Q,Q)
M1<-matrix(rnorm(npc*Q*npc*Q,sd=5),npc*Q,npc*Q)+Z%*%Mu1%*%t(Z) ## adjacency
M2<-matrix(rnorm(npc*Q*npc*Q,sd=10),npc*Q,npc*Q)+Z%*%Mu2%*%t(Z) ## adjacency
## estimation
my_model <- BM_gaussian_multivariate_independent("SBM",list(M1,M2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## SBM symmetric
##
## generation of one SBM_sym network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
Mu1<-8*matrix(runif(Q*Q),Q,Q)
Mu2<-8*matrix(runif(Q*Q),Q,Q)
Mu1[lower.tri(Mu1)]<-t(Mu1)[lower.tri(Mu1)]
Mu2[lower.tri(Mu2)]<-t(Mu2)[lower.tri(Mu2)]
M1<-matrix(rnorm(npc*Q*npc*Q,sd=5),npc*Q,npc*Q)+Z%*%Mu1%*%t(Z) ## adjacency
M2<-matrix(rnorm(npc*Q*npc*Q,sd=10),npc*Q,npc*Q)+Z%*%Mu2%*%t(Z) ## adjacency
M1[lower.tri(M1)]<-t(M1)[lower.tri(M1)]
M2[lower.tri(M2)]<-t(M2)[lower.tri(M2)]
## estimation
my_model <- BM_gaussian_multivariate_independent("SBM_sym",list(M1,M2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## LBM
##
## generation of one LBM network
npc <- c(20,10) # nodes per class
Q <- c(1,2) # classes
Z1<-diag(Q[1])%x%matrix(1,npc[1],1)
Z2<-diag(Q[2])%x%matrix(1,npc[2],1)
Mu1<-8*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])
Mu2<-8*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])
M1<-matrix(rnorm(npc[1]*Q[1]*npc[2]*Q[2],sd=5),npc[1]*Q[1],npc[2]*Q[2])+Z1%*%Mu1%*%t(Z2) ## adjacency
M2<-matrix(rnorm(npc[1]*Q[1]*npc[2]*Q[2],sd=10),npc[1]*Q[1],npc[2]*Q[2])+Z1%*%Mu2%*%t(Z2) ## adjacency
## estimation
my_model <- BM_gaussian_multivariate_independent("LBM",list(M1,M2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
require('blockmodels')
##
## SBM
##
## generation of one SBM network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
Mu1<-4*matrix(runif(Q*Q),Q,Q)
Mu2<-4*matrix(runif(Q*Q),Q,Q)
M1<-matrix(rnorm(npc*Q*npc*Q,sd=5),npc*Q,npc*Q)+Z%*%Mu1%*%t(Z) ## adjacency
M2<-matrix(rnorm(npc*Q*npc*Q,sd=5),npc*Q,npc*Q)+Z%*%Mu2%*%t(Z) ## adjacency
## estimation
my_model <- BM_gaussian_multivariate_independent_homoscedastic("SBM",list(M1,M2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## SBM symmetric
##
## generation of one SBM_sym network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
Mu1<-4*matrix(runif(Q*Q),Q,Q)
Mu2<-4*matrix(runif(Q*Q),Q,Q)
Mu1[lower.tri(Mu1)]<-t(Mu1)[lower.tri(Mu1)]
Mu2[lower.tri(Mu2)]<-t(Mu2)[lower.tri(Mu2)]
M1<-matrix(rnorm(npc*Q*npc*Q,sd=5),npc*Q,npc*Q)+Z%*%Mu1%*%t(Z) ## adjacency
M2<-matrix(rnorm(npc*Q*npc*Q,sd=5),npc*Q,npc*Q)+Z%*%Mu2%*%t(Z) ## adjacency
M1[lower.tri(M1)]<-t(M1)[lower.tri(M1)]
M2[lower.tri(M2)]<-t(M2)[lower.tri(M2)]
## estimation
my_model <- BM_gaussian_multivariate_independent_homoscedastic("SBM_sym",list(M1,M2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## LBM
##
## generation of one LBM network
npc <- c(20,10) # nodes per class
Q <- c(1,2) # classes
Z1<-diag(Q[1])%x%matrix(1,npc[1],1)
Z2<-diag(Q[2])%x%matrix(1,npc[2],1)
Mu1<-4*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])
Mu2<-4*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])
M1<-matrix(rnorm(npc[1]*Q[1]*npc[2]*Q[2],sd=5),npc[1]*Q[1],npc[2]*Q[2])+Z1%*%Mu1%*%t(Z2) ## adjacency
M2<-matrix(rnorm(npc[1]*Q[1]*npc[2]*Q[2],sd=5),npc[1]*Q[1],npc[2]*Q[2])+Z1%*%Mu2%*%t(Z2) ## adjacency
## estimation
my_model <- BM_gaussian_multivariate_independent_homoscedastic("LBM",list(M1,M2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
require('blockmodels')
#
# SBM
#
## generation of one SBM network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
L<-70*matrix(runif(Q*Q),Q,Q)
M_in_expectation<-Z%*%L%*%t(Z)
M<-matrix(
rpois(
length(as.vector(M_in_expectation)),
as.vector(M_in_expectation))
,npc*Q,npc*Q)
## estimation
my_model <- BM_poisson("SBM",M , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## SBM symmetric
##
## generation of one SBM_sym network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
L<-70*matrix(runif(Q*Q),Q,Q)
L[lower.tri(L)]<-t(L)[lower.tri(L)]
M_in_expectation<-Z%*%L%*%t(Z)
M<-matrix(
rpois(
length(as.vector(M_in_expectation)),
as.vector(M_in_expectation))
,npc*Q,npc*Q)
M[lower.tri(M)]<-t(M)[lower.tri(M)]
## estimation
my_model <- BM_poisson("SBM_sym",M , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## LBM
##
## generation of one LBM network
npc <- c(20,10) # nodes per class
Q <- c(1,2) # classes
Z1<-diag(Q[1])%x%matrix(1,npc[1],1)
Z2<-diag(Q[2])%x%matrix(1,npc[2],1)
L<-70*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])
M_in_expectation<-Z1%*%L%*%t(Z2)
M<-matrix(
rpois(
length(as.vector(M_in_expectation)),
as.vector(M_in_expectation))
,npc[1]*Q[1],npc[2]*Q[2])
## estimation
my_model <- BM_poisson("LBM",M , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
require('blockmodels')
##
## SBM
##
## generation of one SBM network
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
L<-70*matrix(runif(Q*Q),Q,Q)
M_in_expectation_without_covariates<-Z%*%L%*%t(Z)
Y1 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)
Y2 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)
M_in_expectation<-M_in_expectation_without_covariates*exp(4.2*Y1-1.2*Y2)
M<-matrix(
rpois(
length(as.vector(M_in_expectation)),
as.vector(M_in_expectation))
,npc*Q,npc*Q)
## estimation
my_model <- BM_poisson_covariates("SBM",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## SBM symmetric
##
## generation of one SBM_sym network, we re-use one produced for SBM
npc <- 10 # nodes per class
Q <- 2 # classes
Z<-diag(Q)%x%matrix(1,npc,1)
L<-70*matrix(runif(Q*Q),Q,Q)
L[lower.tri(L)]<-t(L)[lower.tri(L)]
M_in_expectation_without_covariates<-Z%*%L%*%t(Z)
Y1 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)
Y2 <- matrix(runif(npc*Q*npc*Q),npc*Q,npc*Q)
Y1[lower.tri(Y1)]<-t(Y1)[lower.tri(Y1)]
Y2[lower.tri(Y2)]<-t(Y2)[lower.tri(Y2)]
M_in_expectation<-M_in_expectation_without_covariates*exp(4.2*Y1-1.2*Y2)
M<-matrix(
rpois(
length(as.vector(M_in_expectation)),
as.vector(M_in_expectation))
,npc*Q,npc*Q)
M[lower.tri(M)]<-t(M)[lower.tri(M)]
## estimation
my_model <- BM_poisson_covariates("SBM_sym",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
##
## LBM
##
## generation of one LBM network
npc <- c(20,10) # nodes per class
Q <- c(1,2) # classes
Z1<-diag(Q[1])%x%matrix(1,npc[1],1)
Z2<-diag(Q[2])%x%matrix(1,npc[2],1)
L<-70*matrix(runif(Q[1]*Q[2]),Q[1],Q[2])
M_in_expectation_without_covariates<-Z1%*%L%*%t(Z2)
Y1 <- matrix(runif(npc[1]*Q[1]*npc[2]*Q[2]),npc[1]*Q[1],npc[2]*Q[2])
Y2 <- matrix(runif(npc[1]*Q[1]*npc[2]*Q[2]),npc[1]*Q[1],npc[2]*Q[2])
M_in_expectation<-M_in_expectation_without_covariates*exp(4.2*Y1-1.2*Y2)
M<-matrix(
rpois(
length(as.vector(M_in_expectation)),
as.vector(M_in_expectation))
,npc[1]*Q[1],npc[2]*Q[2])
## estimation
my_model <- BM_poisson_covariates("LBM",M,list(Y1,Y2) , plotting='', explore_min=2, explore_max=2, ncores=2, verbosity=0)
my_model$estimate()
which.max(my_model$ICL)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment