Strip comments, save files and whitespace blocks

This commit is contained in:
2022-04-07 09:38:11 +01:00
parent 882f4cfb69
commit 9739770393
2 changed files with 12 additions and 79 deletions

View File

@@ -117,7 +117,6 @@ getOutNodes <- function(codes, codeList) {
}
buildGraph <- function(model, desc) {
# model contains the following
# node table, edge table
@@ -125,7 +124,6 @@ buildGraph <- function(model, desc) {
# inputCode - the top layer of the model
# outputCodes - all subsequent layers to be included in the model
inputNodes <- model$nodes$code[which(startsWith(model$nodes$code, desc$inputCode))]
inputText <- paste0("[", inputNodes, "]", collapse = "")
@@ -153,13 +151,7 @@ buildGraph <- function(model, desc) {
print("Saving model prior to network modelling")
modelDefn <- paste0(inputText, edges)
save(modelDefn, file = "buildGraph.RData")
# print("about to build network")
# print(paste0(inputText, edges))
# save(modelDefn, file = "buildGraph.RData")
net <- model2network(paste0(inputText, edges), debug = FALSE)
@@ -175,15 +167,12 @@ buildGraph <- function(model, desc) {
allDists <- as.list(setNames(c(inDist, outDist), c(inputNodes, outNodes)))
# print(allDists)
cfit <- custom.fit(net, allDists)
cat("about to calculate sample distributions")
# print(outNodes)
sampleDists <- cpdist(cfit, nodes = outNodes, evidence = TRUE, n = 10000, method = "lw")
summDists <- summary(sampleDists)
# stdDev <- sd(sampleDists)
print("sample distribution build successful")
@@ -204,7 +193,6 @@ buildGraph <- function(model, desc) {
getValidNodes <- function(mapping, prevOutputs, prefix) {
# Find row id for input nodes, internal and published
inputNodes <- mapping[2:nrow(mapping), 1]
@@ -271,10 +259,6 @@ getCode <- function(name, nodeDF) {
}
getValidEdges <- function(mapping, nodeDF, prevEdge = NULL, prefix) {
# utils::str(nodeDF)
# save(mapping, nodeDF, prevEdge, prefix, file="validEdges.RData")
edgeCols <- c("inputNode", "outputNode", "impact")
edgeM <- matrix(data = NA, nrow = 0, ncol = length(edgeCols), dimnames = list(NULL, edgeCols))
@@ -297,6 +281,7 @@ getValidEdges <- function(mapping, nodeDF, prevEdge = NULL, prefix) {
# if (count == 0) print(paste("No edges found for output", colnames(mapping)[col]))
}
}
if (is.null(prevEdge)) {
return(data.frame(
input = edgeM[, "inputNode"],
@@ -321,8 +306,6 @@ parseMapping <- function(mapping, prevOutputs, prefix) {
nodeDF <- getValidNodes(mapping, prevOutputs$nodes, prefix)
edgeDF <- getValidEdges(mapping, nodeDF, prevEdge = prevOutputs$edges, prefix)
# save(nodeDF, edgeDF, file="mapping.RData")
return(list(
# New structure
nodes = nodeDF,
@@ -331,8 +314,6 @@ parseMapping <- function(mapping, prevOutputs, prefix) {
}
parseSheet <- function(fName) {
# get sheet names
print(paste("starting sheet load", fName))
if (file.exists(fName)) {
@@ -342,7 +323,7 @@ parseSheet <- function(fName) {
sheets <- sort(delNA(match(names, mappings)))
cat("starting sheet parse")
# print(sheets)
print(sheets)
if (sum(sheets == refs) == length(refs)) {
# read all mapping tables