movecheck: Function to explore whether moving the (X,Y) location of any...

Description Usage Arguments Value Examples

Description

This function takes an existing set of X and Y estimates, a matrix of patterns, and the frequencies of the patterns and examines whether moving the (X,Y) coordinates of any one pattern may improve the criterion value that POSAC attempts to optimise. As such this function can be used as one check of whether the results from the POSAC function itself are optimal. Note that this function works by an exhaustive search for all patterns across the grid of all possible positionings. As such, it is quite slow and probably only worth applying once a fairly good initial solution has been found.

Usage

1
movecheck(X, Y, patmat, freqs)

Arguments

X

The initial X values assigned to each pattern.

Y

The initial Y values assigned to each pattern.

patmat

A matrix of patterns of values across. Each row of the matrix should represents a distinct pattern with no duplicates. The columns are the variables defining the patterns.

freqs

A vector of frequencies of each pattern. This should have the same length as nrow(patmat).

Value

The function returns a list with the following elements:

CurrentCorrect

The percentage of pairs correctly mapped by the POSAC function to begin with.

BestMove

Details of the best possible move including an updated per cent correct. This need not be above the current value.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## Not run: 
#Look at whether initial POSAC solution for CRASdata can be improved
posac2=POSAC(CRASdata[,1:5],CRASdata[,6])
Sys.time()
moves=movecheck(posac2$X,posac2$Y,posac2$patmat,posac2$freq)
Sys.time()
moves
#now update the posac analysis to reflect improved results
newX=rank(replace(posac2$X,moves$BestMove$Case,moves$BestMove$NewX))
newY=rank(replace(posac2$Y,moves$BestMove$Case,moves$BestMove$NewY))
posac3=POSACupdate(posac2,newX,newY)
posac3
#recheck (slow)
Sys.time()
moves2=movecheck(posac3$X,posac3$Y,posac3$patmat,posac3$freq)
Sys.time()
moves2
#try an iterative approach to update everything until no improvement possible (NOTE: very slow to run)
stop=FALSE
XCURR=posac2$X
YCURR=posac2$Y
print(Sys.time())
while(stop==FALSE){
moves2=movecheck(XCURR,YCURR,posac2$patmat,posac2$freq)
print(Sys.time())
print(moves2$BestMove$pccorrect)
if(moves2$CurrentCorrect==moves2$BestMove$pccorrect){stop=TRUE}
XCURR=rank(replace(XCURR,moves2$BestMove$Case,moves2$BestMove$NewX))
YCURR=rank(replace(YCURR,moves2$BestMove$Case,moves2$BestMove$NewY))
}
#update final POSAC results again
posac3=POSACupdate(posac2,XCURR,YCURR)
 
## End(Not run)

CambridgeAssessmentResearch/POSAC documentation built on May 28, 2019, 12:16 p.m.