Function to write out the best-matching hexagons and/or cluster bases in terms of data

Description

sWriteData is supposed to write out the best-matching hexagons and/or cluster bases in terms of data.

Usage

sWriteData(sMap, data, sBase = NULL, filename = NULL, keep.data = FALSE)

Arguments

sMap
an object of class "sMap" or a codebook matrix
data
a data frame or matrix of input data
sBase
an object of class "sBase"
filename
a character string naming a filename
keep.data
logical to indicate whether or not to also write out the input data. By default, it sets to false for not keeping it. It is highly expensive to keep the large data sets

Value

a data frame with following components:

  • ID: ID for data. It inherits the rownames of data (if exists). Otherwise, it is sequential integer values starting with 1 and ending with dlen, the total number of rows of the input data
  • Hexagon_index: the index for best-matching hexagons
  • Cluster_base: optional, it is only appended when sBase is given. It stores the cluster memberships/bases
  • data: optional, it is only appended when keep.data is true

Note

If "filename" is not NULL, a tab-delimited text file will be also written out. If "sBase" is not NULL and comes from the "sMap" partition, then cluster bases are also appended. if "keep.data" is true, the data will be part of output.

Examples

# 1) generate an iid normal random matrix of 100x10 data <- matrix( rnorm(100*10,mean=0,sd=1), nrow=100, ncol=10) # 2) get trained using by default setup sMap <- sPipeline(data=data)
Start at 2018-01-18 16:56:13 First, define topology of a map grid (2018-01-18 16:56:13)... Second, initialise the codebook matrix (61 X 10) using 'linear' initialisation, given a topology and input data (2018-01-18 16:56:13)... Third, get training at the rough stage (2018-01-18 16:56:13)... 1 out of 7 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 2 out of 7 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 3 out of 7 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 4 out of 7 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 5 out of 7 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 6 out of 7 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 7 out of 7 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) Fourth, get training at the finetune stage (2018-01-18 16:56:13)... 1 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 2 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 3 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 4 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 5 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 6 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 7 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 8 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 9 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 10 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 11 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 12 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 13 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 14 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 15 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 16 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 17 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 18 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 19 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 20 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 21 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 22 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 23 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 24 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) 25 out of 25 (2018-01-18 16:56:13) updated (2018-01-18 16:56:13) Next, identify the best-matching hexagon/rectangle for the input data (2018-01-18 16:56:13)... Finally, append the response data (hits and mqe) into the sMap object (2018-01-18 16:56:13)... Below are the summaries of the training results: dimension of input data: 100x10 xy-dimension of map grid: xdim=9, ydim=9, r=5 grid lattice: hexa grid shape: suprahex dimension of grid coord: 61x2 initialisation method: linear dimension of codebook matrix: 61x10 mean quantization error: 5.04879912872829 Below are the details of trainology: training algorithm: batch alpha type: invert training neighborhood kernel: gaussian trainlength (x input data length): 7 at rough stage; 25 at finetune stage radius (at rough stage): from 3 to 1 radius (at finetune stage): from 1 to 1 End at 2018-01-18 16:56:13 Runtime in total is: 0 secs
# 3) write data's BMH hitting the trained map output <- sWriteData(sMap=sMap, data=data, filename="sData_output.txt") # 4) partition the grid map into cluster bases sBase <- sDmatCluster(sMap=sMap, which_neigh=1, distMeasure="median", clusterLinkage="average") # 5) write data's BMH and cluster bases output <- sWriteData(sMap=sMap, data=data, sBase=sBase, filename="sData_base_output.txt")

Source code

sWriteData.r

Source man

sWriteData.Rd sWriteData.pdf

See also

sBMH