Commit 679b62805671e900eb8f790c2866f091b576180d

Authored by Efrain Gonzalez
1 parent 6b8f81e7b3
Exists in master

completed code for path finding(TESTING)

Showing 1 changed file with 44 additions and 12 deletions   Show diff stats
1 1 #Efrain Gonzalez
2   -#8/28/2017
  2 +#8/25/2017
3 3 #Code for Markov Blanket
4 4  
5 5  
... ... @@ -289,7 +289,7 @@ k = d
289 289 prevar <- VariableEndName
290 290 Pathlisting <- vector("list",length = d)
291 291 Pathlisting[[d]] <- prevar
292   -for(k in d:1){
  292 +for(k in d:2){
293 293 if(k == d){
294 294 for(ship in 1:length(AllVarList[[d]])){
295 295 if(sum(grepl(paste0("^",VariableEndName,"$"),AllVarList[[d]][[ship]])) > 0){
... ... @@ -345,20 +345,52 @@ for(k in d:1){
345 345  
346 346 } else if(modship == 1){
347 347 #When modship == 1 then we are referring to a Parent
348   - LCofVar <- grep(paste0("^",prevar,"$"),NewDotP2_2[,1])
349   - CoVar <- NewDotP2_2[LCofVar,1]
350   - lenC <- length(CoVar)
351   - for(o in 1:lenC){
352   - if(grepl(CoVar[o],AllVarList[[k]][[intship]]) == TRUE){
353   -
354   -
  348 + lengprevar <- length(prevar)
  349 + t <- 1
  350 + ##All children of these parents
  351 + TCoVar <- vector("character",length = 0)
  352 + ##variables that could have led to these parents
  353 + leadVar <- vector("character",length = 0)
  354 + for(t in 1: lengprevar){
  355 + LCofVar <- grep(paste0("^",prevar[t],"$"),NewDotP2_2[,1])
  356 + CoVar <- NewDotP2_2[LCofVar,2]
  357 + TCoVar <- append(TCoVar,CoVar)
  358 + }
  359 + TCoVar <- TCoVar[!duplicated(TCoVar)]
  360 + s <- 1
  361 + ##Searching for the children that are also in the previous degree
  362 + for(s in 1:length(TCoVar)){
  363 + if(sum(grepl(TCoVar[s],AllVarList[[(k - 1)]][[intship]])) >= 1){
  364 + leadVar <- append(leadVar,TCoVar[s])
355 365 }
356   -
357 366 }
358   -
  367 + leadVar <- leadVar[!duplicated(leadVar)]
  368 + prevar <- leadVar
359 369  
360 370 } else if(modship == 2){
361   - #When modship == 0 then we are referring to a Child
  371 + #When modship == 2 then we are referring to a Child
  372 + lenprevar <- length(prevar)
  373 + x <- 1
  374 + ##All parents of these children
  375 + TPoVar <- vector("character",length = 0)
  376 + ##variables that could have led to these children based on the
  377 + drctVar <- vector("character",length = 0)
  378 + for(x in 1:lenprevar){
  379 + LPoVar <- grep(paste0("^",prevar[x],"$"),NewDotP2_2[,2])
  380 + PoVar <- NewDotP2_2[LPoVar,1]
  381 + TPoVar <- append(TPoVar,PoVar)
  382 + }
  383 + TPoVar <- TPoVar[!duplicated(TPoVar)]
  384 + y <- 1
  385 + ##Searching for the parents that are also in the previous degree
  386 + for(y in 1:length(TPoVar)){
  387 + if(sum(grepl(TPoVar[y],AllVarList[[(k - 1)]][[intship]])) >= 1){
  388 + drctVar <- append(drctVar,TPoVar[y])
  389 + }
  390 + }
  391 + drctVar <- drctVar[!duplicated(drctVar)]
  392 + prevar <- drctVar
  393 +
362 394  
363 395 }
364 396