Implement changes as requested by JNCC

This commit is contained in:
2022-03-30 17:51:19 +01:00
parent eec5f07cfc
commit 5fc290e832
5 changed files with 369 additions and 44 deletions

View File

@@ -85,7 +85,7 @@ getInitial <- function(string, letter) {
}
split <- function(cell) {
params <- unlist(strsplit(cell, ","))
values <- rep(0, length(states))
@@ -126,6 +126,7 @@ 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 = "")
@@ -151,8 +152,15 @@ buildGraph <- function(model, desc) {
outDist[[idx]] <- list(coef = coefVal, sd = model$nodes$confidence[nodeRef])
}
print("about to build network")
print(paste0(inputText, edges))
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))
net <- model2network(paste0(inputText, edges), debug = FALSE)
@@ -167,6 +175,8 @@ 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")
@@ -264,6 +274,8 @@ 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))
@@ -309,6 +321,8 @@ 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,
@@ -329,7 +343,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
@@ -338,12 +352,6 @@ parseSheet <- function(fName) {
p_op <- parseMapping(readXL(fName,mappings[3], startRow = 1), p_ba, prefix = "op")
p_es <- parseMapping(readXL(fName,mappings[4], startRow = 1), p_op, prefix = "es")
legend <- readXL(fName,mappings[5], startRow = 1)
#print("building graphs")
#p_baNet <- buildGraph(p_ba, desc = list(inputCode = "p", outputCodes = "ba"))
#p_opNet <- buildGraph(p_op, desc = list(inputCode = "p", outputCodes = c("ba", "op")))
#p_esNet <- buildGraph(p_es, desc = list(inputCode = "p", outputCodes = c("ba", "op", "es")))
print("sheet load completed")
return(