-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpair_operations1f.R
More file actions
52 lines (49 loc) · 1.45 KB
/
Copy pathpair_operations1f.R
File metadata and controls
52 lines (49 loc) · 1.45 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#Functions that operate on a list of pair objects
#The input list of pairs describes a single (ggobi) view
#Sanity Functions
is.view.exhaustive <- function(lst,dat)
{
all.ids <- sapply(lst,FUN=function(x) x$get.data.ids())
all(1:nrow(get(dat)) %in% do.call('c',all.ids))
}
is.view.mutually.exclusive <- function(lst)
{
ids <- sapply(lst,FUN=function(x) x$get.data.ids())
for(i in 1:(length(ids)-1))
{
for(j in (i+1):length(ids))
{
if(any(ids[[i]] %in% ids[[j]])) return(FALSE)
}
}
TRUE
}
is.view.sane <- function(lst,dat)
{
if(is.view.exhaustive(lst,dat) &
is.view.mutually.exclusive(lst) &
all(sapply(lst,FUN=function(x) x$sanity())))
return(TRUE)
else if(is.view.exhaustive())
warning("View is not Exhaustive")
else if(is.view.mutually.exclusive())
warning("View is not Mutually Exhaustive")
else
warning("Some pair has gone bad")
return(FALSE)
}
better.view <- function(lst,start,bases,n,max.tries=10)
{
p <- vector('list',bases)
i <- 1
index <- function(mat) sum(sapply(lst,FUN=function(x) x$index(mat)))
cat("Initial Value",index(start),'\n')
p[[1]] <- start
while (i <= bases)
{
p[[i+1]]<- search_geodesic(current=p[[i]],index=index,n=n[i],max.tries=max.tries)
if((length(p[[i+1]]) == 1)) return(p)
i <- i + 1
}
return(p)
}