# Authors: Fuyu Frank Xu and Kate Beard, School of Computing and Information Science, University of Maine, Orono, Maine
# Function name: STES.sim2().
# This function is used after running STES.sim1 and outputs global and local similarity matrices separately.
#
# Modified date: May, 2019
STES.sim2 <- function(data,ctw=1){
# ----------------------------------------------- Test for errors if input data is not matrix format ------------------------------
#
if(!is.matrix(data)){
print("!--------------------- ERROR #001 -----------------!")
print("! Input data file 'data' is not a matrix! !")
print("!----------------------------------------------------!")
return()
} # end of matrix input check
# ----------------------------------------------- Eventization --------------------------------------------------------------------
nr = nrow(data) #number of rows
nc = ncol(data) #number of columns
nw = nc%/%ctw #number of complete local temporal windows
nm = nc%%ctw #modulus
cat('Original STES matrix', "\n")
print(data)
cat("\n")
globalsim = STES.sim1(data=data)
cat('Global event sequence similarity matrix', "\n")
print(globalsim)
cat("\n")
for (i in 1:nw){
subdata = data[,((i-1)*ctw+1):(i*ctw)]
localsim = STES.sim1(data=subdata)
cat('Local similarity matrix at window ', i, "\n")
print(localsim)
}
if (nm != 0){
subdata = data[,(nw*ctw+1):(nw*ctw+nm)]
localsim = STES.sim1(data=subdata)
cat('Local similarity matrix at last incomplete window ', nw+1, "\n")
print(localsim)
}
} # end function STES.sim2